1. Table structure (table name, columns)
Column description: column name, data type, whether it is empty
1. Create table
mysql> create table student
-> (sno char(4) not null,
-> sname char(10),
-> ssex char(2));
**Check which tables are under the current database show tables;
**View table structure: desc student;
2. Modify the table alter table table name
(1) Modify the name of the table
mysql> alter table student
-> rename to s;
(2) Add column
add 1 column
mysql> alter table s
-> add sage int;
Add multiple columns at once
mysql> alter table s
-> add (a char(3),b int);
(3) modify column
mysql> alter table s
-> modify sname char(20) not null;
(4) delete column
mysql> alter table s
-> drop column b;
3. Drop the table
mysql> drop table s;
2. Table data (add, delete, modify, check)
1. Insert data
Insert into table name
Values (value 1, value 2)
**Precautions:
(1) The provided values are either in one-to-one correspondence with the fields of the table, or in one-to-one correspondence with the list.
(2) Add '' to character and date data
(3) Fields that are not null must add data
mysql> insert into student
-> values('0001','Li Li','Female',18,'CS');
mysql> insert into student(sno,sname)
-> values('0002','Li Li');
2. Update data
grammar:
update table name
set data name = new data
where the data name to look for = data;
3. Delete data
Delete from table name
Where sno = ‘0003’
mysql> delete from student
-> where sno = '0003';