about python The list can be understood as C Language inside the array of comparative memory and contrast , They're similar , about python The definition of the list can be directly added with the method of the contained object in square brackets , Let's have a look !

One Storage engine introduction

The storage engine is the table type ,mysql According to different table types, there are different processing mechanisms

Two Table introduction

A table is equivalent to a file , A record in a table is equivalent to a line in a file , The difference is , A record in the table has a corresponding title , Fields called tables

 Insert picture description here

id,name,qq,age Called fields , The rest , A line is called a record

3、 ... and Create table

# grammar :create table Table name (

Field name 1 type [( Width ) constraint condition ],

Field name 2 type [( Width ) constraint condition ],

Field name 3 type [( Width ) constraint condition ]

);# Be careful :1. In the same table , Field names cannot be the same 2. Width and constraints are optional 3. Field name and type are required

Pay attention to pay attention to : Don't add a comma to the last field in the table

Four View table structure

MariaDB [db1]> describe t1;# View table structure , It can be abbreviated as desc Table name ±------±----------------------±-----±----±--------±------+| Field | Type | Null | Key | Default | Extra |±------±----------------------±-----±----±--------±------+| id | int(11) | YES | | NULL | || name | varchar(50) | YES | | NULL | || sex | enum(‘male’,‘female’) | YES | | NULL | || age | int(3) | YES | | NULL | |±------±----------------------±-----±----±--------±------+MariaDB [db1]> show create table t1\G;# Look at the detailed structure of the table , coca \G

5、 ... and data type

6、 ... and Table integrity constraints

7、 ... and Modify table ALTER TABLE

grammar :1. Modify the name of the table

ALTER TABLE Table name

RENAME The new name of the table ;2. Add fields

ALTER TABLE Table name

ADD Field name data type [ Integrity constraints …],

ADD Field name data type [ Integrity constraints …];

ALTER TABLE Table name

ADD Field name data type [ Integrity constraints …] FIRST;

ALTER TABLE Table name

ADD Field name data type [ Integrity constraints …] AFTER Field name ;3. Delete field

ALTER TABLE Table name

DROP Field name ;4. Modify fields

ALTER TABLE Table name

MODIFY Field name data type [ Integrity constraints …];

ALTER TABLE Table name

CHANGE Old field name new field name Old data types [ Integrity constraints …];

ALTER TABLE Table name

CHANGE Old field name new field name New data types [ Integrity constraints …];

Example :1. Modify the storage engine

mysql> alter table service -> engine=innodb;2. Add fields

mysql> alter table student10-> add name varchar(20)not null,-> add age int(3)notnull default 22;

mysql> alter table student10-> add stu_num varchar(10)notnull after name; // add to name After the fields

mysql> alter table student10 -> add sex enum(‘male’,‘female’) default’male’first; // Add to the front 3. Delete field

mysql> alter table student10-> drop sex;

mysql> alter table service-> drop mac;4. Modify field type modify

mysql> alter table student10-> modify age int(3);

mysql> alter table student10-> modify id int(11)notnull primary key auto_increment; // Change to primary key 5. Add constraints ( Add... To the existing primary key auto_increment)

mysql> alter table student10 modify id int(11)not null primary key auto_increment;

ERROR 1068 (42000): Multiple primary key defined

mysql> alter table student10 modify id int(11)not null auto_increment;

Query OK, 0 rows affected (0.01 sec)

Records: 0 Duplicates: 0 Warnings: 06. Add a compound primary key to an existing table

mysql> alter table service2-> add primary key(host_ip,port);7. Add primary key

mysql> alter table student1-> modify name varchar(10)not null primary key;8. Add primary keys and grow automatically

mysql> alter table student1-> modify id intnot null primary key auto_increment;9. Delete primary key

a. Delete autoincrement constraint

mysql> alter table student10 modify id int(11)not null;

b. Delete primary key

mysql> alter table student10 -> drop primary key;

8、 ... and Copy table

Replicated table structure + Record (key Will not copy : Primary key 、 Foreign keys and indexes )

mysql> create table new_service select *from service;

Copy only table structure

mysql> select *fromservice where 1=2; // The condition is false , No records can be found

Empty set (0.00 sec)

mysql> create table new1_service select *fromservice where 1=2;

Query OK, 0 rows affected (0.00 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> create table t4 like employees;

Nine Delete table

DROP TABLE Table name ;