Quick Start SQL statements the basic operation

Mysql database + Mysql Workbench GUI client.

Tips: Execute the statement: select version (); you can view the Mysql database version of this machine

Tips: the beginning of the line flag "-" to comment on the line, you need to remove the comment statement To run mark

- to see what databases
- Show Databases;
- use the database MyBlog
- MyBlog use;
- to show all the tables in this database
- show tables;


- data into the table
- INSERT INTO Users (username, password, RealName of) values ( 'zhangsan', '456', 'John Doe');
- INSERT INTO Users (username, password, RealName of) values ( 'Lisi', '123', 'John Doe');


- Delete line
- Delete from Users WHERE username = 'zhangsan';
- but the actual development in general does not actually delete rows, but from the state field is set to 0 is defined as the line marked invalid (soft delete)
- Update Users SET State = '0' WHERE username = 'Lisi';
- and using queries shape following query valid data
- SELECT * from Users WHERE State = '. 1';
- and can restore soft-deleted data
- update users set state = ' 1 'where username =' lisi ' ;


- Update
- SET SQL_SAFE_UPDATES = 0; // update error if the line safe update mode is executed
- update users set realname = 'John Doe' where username = 'lisi';


- all of the lookup table data (in order to improve the performance of the actual development avoid using *)
- SELECT * from Users;
- some of the columns of data look-up table
- SELECT ID, username from Users;
- Query Condition
- select * from users where = username 'zhangsan';
- exclude query (the query sentence password users table 456 is not data)
- SELECT * WHERE from users password <> '456';
- many conditions intersection
- select * from users where username = 'zhangsan' and password= '123';
- many conditions and set
- SELECT * from Users WHERE username = 'zhangsan' or password= '123';
- Fuzzy query
- SELECT * from Users WHERE username like '% San%';
- ordering (top to bottom default positive sequence alignment, with parameters desc compared with the reverse order)
- SELECT * WHERE password from Users like '%. 1%' by order ID desc;


Published 49 original articles · won praise 29 · views 1901

Guess you like

Origin blog.csdn.net/Brannua/article/details/104652438