MySQL basic sql statement

MySQL basic operation statement

Action Folder (Library)

Add
create database library name charset utf8;
charset utf8 is the character encoding of the specified library
Delete
drop database library name
Delete a database
Modify
alter database library name charset gbk
Note: You cannot modify the library name, only the character encoding
query
1, show databases;
2. show create database database name
1. All databases are
queried 2. Details of a specified database are queried

 

Action file (table)

View the current database: select database()
to switch the database: use the database name
to increase the
create table table name (field 1 type...);
for example: create table t1 (id int, name char);
delete
the drop table table name;
for example:
drop table t1;
modify
and add field
alter table table name add field type;
for example:
alter table t1 add sex char;
delete field
alter table table name dorp field name;
for example:
alter table t1 dorp name;
modify field
change field type
alter table table name modify field type;
for example:
alter table t1 modify name char(16);-----change the field type length to 16
change the field name
alter table table name change field 1 field 2 type;
for example:
alter table t1 change name Name char (16);---- Field name modification
query
1, show tables;
2. show create table table name;
1. View all tables:
2. View detailed information of a specified table

 

Action file content (record)

Add
insert into table name (field1...)values(value1,value2);
for example:
insert into t1(id,name)values(1,'lili'),(2,'hanmeimei');
delete
from table Name where condition
for example:
delete from t1 where id =2;
modify
update table name set field='modified value' where condition;
for example:
update t1 set name='hello' where id =2;
query
select field/* from table name;
select id,name from t1;
select * from t1;

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325501145&siteId=291194637