03, MySQL- Table Operator

1, create a data table

The basic syntax: create table table name (field name field type [Field Properties], the field name field type [Field Properties], ...) [Table Option]

Example: Create a data table

 

Error described above: Table must be placed under the corresponding database: There are two ways may be linked into the table to the specified database.

. "" (1) before the data table name with the database name, connection to: database data table.

 

(2) before creating the data table to enter into a specific database to: use database name;

 

Table Options: Similar to database options

Engine: storage engine, specific way of storing data provided by mysql, there is a default innodb (5.5 previous default myisam)

Charset: character sets, only (level higher than the database) table is valid for the current own

Collate: proofreading set

Example: Create a data table using the Table Options

 

2, copy the existing table structure

Copy (copy only structural: the data table is not copied) from the existing table replication

The basic syntax: create table new table like table name; // Just use the database table name, you can access other database table name in any database.

3, the display data table

Whenever a data table is created, it will create some files in the corresponding database (and related storage engine)

 

Note: This configuration file from the innodb storage engine, innodb storage engine all files are stored in an external file ibdata

 

4, displaying all the tables

The basic syntax: show tables;

Example: All the tables

 

5, match the display table

The basic syntax: show tables like 'pattern match';

Example: using the matching table display

 

6, showing the table structure

Essential meaning: shown in the table included in the field information (name, type, attributes, etc.)

Describe 表名

Desc table

show columns from 表名

Example: display table structure

 

7, table creation statement

View the data sheet statement is created: to see the results of this statement has not previously entered by the user a statement.

The basic syntax: show create table table name;

Example: display used to create Statement List

 

8, the statement terminator

There are several Mysql statement terminator

; Effect \ G is represented by the same, is the field in the row sideways, with the following corresponding data

\ G field vertically on the left side, the right side of the data sideways

 

9, setting the table properties

表属性指的就是表选项:engine,charset和collate

基本语法:alter table 表名 表选项 [=] 值;

范例:设置表属性

 

注意:如果数据库已经确定了,里面有很多数据了,不要轻易修改表选项(字符集影响不大)

10、修改表结构

修改表名:rename table 旧表名 to 新表名

范例:修改表的结构

  

修改表选项:alter table 表名 表选项 [=] 新值

新增字段:alter table 表名 add [column] 新字段名 列类型 [列属性] [位置first/after 字段名]

范例:新增字段

 

说明:

字段位置:字段想要存放的位置

First:在某某之前(最前面),第一个字段

After 字段名:放在某个具体的字段之后(默认的)

范例:字段位置的使用

  

修改字段名:alter table 表名 change 旧字段名 新字段名 字段类型 [列属性] [新位置]

范例:修改字段名称

 

修改字段类型(属性):alter table 表名 modify 字段名 新类型 [新属性] [新位置]

范例:使用modify修改字段类型

  

删除字段:alter table 表名 drop 字段名

范例:删除字段

 

11、删除表结构

基础语法:drop table 表名[,表名2…],可以同时删除多个数据表

范例:删除表结构(单个删除)

 

范例:删除表结构(批量删除表)

 

Guess you like

Origin www.cnblogs.com/CSAH/p/11111383.html