Some common database statements

A. Log database (registered in the console)
1. plaintext registration
mysql -u username -p password
2. ciphertext log
mysql -u -p Enter a username and password

Second DDL operations database
1. Create a database
a database created directly (remember):.
The Create Database database name;
b and create a database to determine whether there is (to know):.
The Create Database not IF EXISTS database name;
c create a database and specify. character set (understand):
the Create database database name character set the character set;
2. Review the database
. a view which currently mysql database (remember):
Show databases;
b view the definition of a database of information (to know):.
Show the Create database database name;
3. modify database
a database encoding a modified (learn):.
ALTER database database default character set character set name;
4. remove the database
. directly delete a database (Learn):
drop database database name;
5. database
. a view the database being used (to know):
the SELECT database ();
b using a database (remember):.
use the database name;
three DDL operations data sheet.
1. create a table
create table table name (
Field Name Data Type (length) [bound],
Field Name Data Type (length) [bound],
Field Name Data Type (length) [bound]
);
2. Display
a view below the current database which tables:.
Show the tables;
b View table in Detail:.
desc table name;
. c see the table creation SQL statement (understand)
Show the create the table table name;
3. quickly create a table structure and the same original table (understand)
the create a new table the table like the old table name;
4. delete table (understanding)
. A delete table
drop table name;
. B determines if there is, then delete the table
drop table if exists name;
5. modify table configuration (Learn)
A added. column
alter table table add column name data type (length) [bound];
. B change the column
alter table table modify column name data type (length) [bound];
. C modify column name
alter table table change the old column name new column name data type (length) [bound];
. D delete column
alter table drop table column name;
. E modified table
rename table the old table to the new table name
. f changes to the table character set (encoding)
the ALTER the Table table name character set character set;
Fourth DML add data (very important)
1. Full name of the column to add
insert into table (column 1 , column 2, column 3) values (value 1, value 2 and value 3);
2. All column value added
insert into table values (value 1, value 2 and value 3);
3. Add the specified column (common)
INSERT into table (column 1, column 3) values (value 1, value 3);
4. batch add
insert into table (column 1, column 2, column 3) values (value 1, value 2 and value 3), ( value 1, value 2 and value 3), (value 1, value 2 and value 3);
5. worm copies
insert into table 1 select * from table 2
Five DML modified data (important)
Update table set column = value, column = value [where conditions];
VI DML delete data (very important)
the delete from table [where conditions];
TRUNCATE the table table name; (understand)
Seven DQL query (very important)
1. All inquiries column
select * from table name;
2. Check the specified column
select column names, column names from table name;
3. alias query
select AS column name from an alias name;
select column names from the alias table;
4. deduplication query (Learn)
select columns from table DISTINCT;
5. Calculation query
+ column select values from table;
select columns from table name + column;

Published 13 original articles · won praise 3 · Views 2653

Guess you like

Origin blog.csdn.net/qq_45014905/article/details/104315031