MySQL basic operation command, including database, data table, data operation.

First, the operation of the library

1.1 check the

show schemas/databases;

1.2 select library

use demo;

1.3 create

create database/schema demo;

1.4 delete

drop database/schema demo;

Two, the operation of the table

2.1 check the

show tables;

2.2 create

create table if not exists job(
    -> id int not null auto_increment,
    -> job_name varchar(50) not null,
    -> job_desc varchar(200) not null,
    -> primary key (id));

2.3 delete

drop table job;

2.4 Clear table data

delete from job;

2.5 Table field operations

2.5.1 View table fields

desc job;
或者
show create table job;

2.5.2 Add table field to add

alter table job add job_desc varchar(200);

2.5.3 Modify table field :change, modify table field type and name: MODIFY

alter table job change job_desc job_text varchar(200);
alter table job modify job_name varchar(50);

DROP TABLE DROP TABLE DROP TABLE DROP TABLE DROP TABLE

alter table job drop job_desc; You cannot use DROP to DROP a field if only one field is left in the table

2.5.5 Move table field position: it can only be used when add and modify

alter table job add job_desc first;
alter table job modify job_desc varchar(200) after id;

3. Data manipulation

3.1 to add:

Insert into test.job (job_name,job_desc) values (" engineer "," XXX "); insert into test.job (job_name,job_desc) values (" engineer "," XXX "); Insert into test.job values (2," test "," test bug"); INSERT INTO TEST. JOB VALUES (5," DST "," DST "); Insert into test.job (job_name,job_desc) values (" 1 "," 1 ");

3.2 delete:

Delete from job where job_name = "job_name ";

3.3 change:

Update job set job_desc = "test "; Update job set job_desc = "XXXXX" where job_name = "engineer ";

3.4 check:

select job_desc from job where job_name = "test";