当前位置:网站首页>Mysql database: introduction to database 𞓜 addition, deletion, modification and query

Mysql database: introduction to database 𞓜 addition, deletion, modification and query

2022-06-12 00:21:00 Mountains and rivers cool in autumn

 database (database) It's for organizing , Warehouse for storing and managing data 
 Copy code 

database

Traditional database ( Also known as : Relational database or SQL database ) MySQL,Oracle,SQL Server New database ( Also known as : Non relational database or NoSQL database ) MongoDB

The data organization structure of traditional database

  • database (database)
    • In development , Usually each project corresponds to a separate database
  • Data sheet (table)
    • Different data , Stored in different tables
    • For example, the user data is in users surface , Book data in books In the table
  • data row (row)
    • The rows in the table , Represents each specific piece of data
  • Field (field)
    • What information is stored in each table , Determined by the field
    • Such as users Table design id,username,password These three fields
    • Fields are similar to Excel The column of ,
    • Each field has a corresponding data type

Create database

  Don't use Chinese , Space with '_' Instead of 
 
 Copy code 

Create data table

  • DataType data type
    • int Integers
    • varchar(length) character string
    • tinyint(int) Boolean value
  • Special identification of the field :
    • PK(Primary Key) Primary key , Unique identification
    • NN(Not Null) Value cannot be empty
    • UQ(Unique) It's worth it
    • AI(Auto Increment) The value increases automatically ( Usually to id Set up auto grow )
    • Default/Expression The default value is ( When not assigned , Automatically set to default )

hypothesis id Is an automatically increasing and unique value , If the row data is deleted , The new data will not be used again id value

SQL: Structured query language

SQL Is a database programming language 
SQL Code written in language , namely SQL sentence 
 Can only be used in relational databases (MySQL,Oracle,SQL Server)
 Copy code 

grammar

SQL Keywords in statements are case insensitive , therefore SELECT,FROM Equivalent to select,from
 Copy code 
  • Select Statement is used to query data from a table , The results of the execution are stored in a result table ( Called result set ). The syntax is as follows
-- notes 
-- from from designated 【 In the table 】, Query out 【 all 】 The data of ,* Represents all columns 
SELECT * FROM  The name of the table 

-- from FROM designated 【 In the table 】, Query the specified   Column name ( Field )  The data of 
SELECT  Column name  FROM  The name of the table 

-- Between multiple columns ',' separate 
SELECT username,password FROM users
 Copy code 
  • Insert into Statement is used to insert a new data row into a data table
    --  Be careful : Columns and values should correspond to each other , Between multiple columns and multiple values , Use English commas to separate 
            INSERT INTO table_name ( Column 1, Column 2,...) VALUES ( value 1, value 2,...)
 Copy code 
  • Update Statement is used to modify the data in the table
    --  use UPDATE  Specify which table data to update 
    --  use SET Specify the new value corresponding to the column 
    --  use WHERE  Specify the conditions for updating 
    -- UPDATE  The name of the table  SET  Column name  =  The new value  WHERE  Column name  =  Certain value 
        UPDATE users SET password = 'zs8888' WHERE id = 7
    --  Update several columns in a row 
        UPDATE users SET password = '123456',username = 'zs' WHERE ID = 2
 Copy code 
  • Delete Statement to delete rows in a table

       Be careful : Use delete If you forget to add where The condition will delete the data of the whole table 
     Copy code 
--  From the specified table , according to where The conditions offered , Delete the corresponding data row 
DELETE FROM TABLE_NAME WHERE COL_NAME = VALUE
 Copy code 
  • where Clause is used to qualify the selection criteria

     stay select,update,delete In the sentence , Can be used where Clause to limit the selection criteria 
     Copy code 
  • Operator

    • = be equal to
    • <> It's not equal to ( In some versions ,<> It can be written. '!=')
    • > Greater than
    • < Less than
    • >= Greater than or equal to
    • <= Less than or equal to
    • BETWEEN In a certain range
    • LIKE Search for a pattern
  • and/or Statements in where Combining two or more conditions in a clause

    SELECT * FROM users WHERE uername<>'zs' AND id<3
    SELECT * FROM users WHERE uername<>'zs' OR id<3
 Copy code 
原网站

版权声明
本文为[Mountains and rivers cool in autumn]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202203011510114375.html