mysql - CRUD database, table, table data

data

1. Insert

INSERT INTO userinfo(id,username,birthday) VALUES (5,'孙七','1982-12-26'),(6,'Jack','1982-11-26');
INSERT INTO userinfo SET id = 7, username = '朱八', birthday = '1992-11-11';

 

2. Modify

UPDATE userinfo SET username = 'tom' WHERE id = 6;

 

3. Delete

DELETE FROM userinfo WHERE id = 7;

Empty Table:

TRUNCATE userinfo;

 

database:

4. Create

create database if not exists database name

 

The database generally does not modify the name and contents

 

6. Modify database character set

ALTER DATABASE database name CHARACTER SET gbk (or utf-8)

 

7. Delete

drop database database name

 

 

table:

desc table

View table structure

 

8. Create:

create table 表名(

    Column name Data type 1 [1] constraints,

    Column name Data type 2 2 [2] constraints,

    Column Name Data Type 3 3 3 [constraints]

);

 

create table table name select statement

Create a new table with query results

 

create table 表名 like 表2

Create a table with the structure of Table 2

 

9. Review:

Add column names

alter table add column new table column name the new data type

Modify the column name

alter table table name change column old column name for the new column names new data types;

Modify column data types

alter table modify column table column name the new data type

Remove Columns

alter table table name drop column column name

Modify the table name

Old alter table table name rename to new table name

 

10. Delete:

drop table if exists 表名

if exists, and only the table used to determine the library exists, and data can not use this column

 

 

Guess you like

Origin www.cnblogs.com/clamp7724/p/11790245.html