mysql建表语句
create table [if not exists] db_name.table_name
(
colunum1 date not null comment '列字段说明'
,colunum2 int(11) not null comment '列字段说明'
,colunum3 int(11) not null comment '列字段说明'
,colunum4 int(11) not null default 0 comment '列字段说明'
,unique index un_key (colunum1)
)
comment='表说明'
default character set utf8
default collate utf8_general_ci
其中:
1、comment:可以加入表和字段的说明信息
2、unique index un_key (colunum1):指定表的唯一索引
3、default character set utf8:指定表的默认字符集
4、default collate utf8_general_ci:指定表的默认排序方式
5、engine:存储引擎。
1)如果被指定的存储引擎无法利用,则MySQL使用MyISAM代替。例如,一个表定义包括ENGINE=BDB选项,但是MySQL服务器不支持BDB表,则表被创建为MyISAM表。
2)在MySQL 5.1中,只有MyISAM,InnoDB, BDB和MEMORY存储引擎支持在含有NULL值的列中编索引。在其它情况下,您必须定义已编索引的列为NOT NULL,否则会出现错误。
3)对于MyISAM表,每个NULL列要多占用一位,进位到距离最近的字节。对于InnoDB表,NULL列的存储量与NOT NULL列的存储量没有区别。
create table [if not exists] db_name.table_name
(
colunum1 date not null comment '列字段说明'
,colunum2 int(11) not null comment '列字段说明'
,colunum3 int(11) not null comment '列字段说明'
,colunum4 int(11) not null default 0 comment '列字段说明'
,unique index un_key (colunum1)
)
comment='表说明'
default character set utf8
default collate utf8_general_ci
engine = memory
;
其中:
1、comment:可以加入表和字段的说明信息
2、unique index un_key (colunum1):指定表的唯一索引
3、default character set utf8:指定表的默认字符集
4、default collate utf8_general_ci:指定表的默认排序方式
5、engine:存储引擎。
存储引擎 |
说明 |
ARCHIVE |
档案存储引擎。 |
BDB |
带页面锁定的事务安全表。也称为BerkeleyDB。 |
CSV |
值之间用逗号隔开的表。 |
FEDERATED |
可以访问远程表的存储引擎。 |
InnoDB |
带行锁定和外键的事务安全表。 |
MEMORY |
本表类型的数据只保存在存储器里。(在早期MySQL版本中被称为HEAP。) |
MERGE |
MyISAM表的集合,作为一个表使用。也称为MRG_MyISAM。 |
MyISAM |
二进制轻便式存储引擎,此引擎是MySQL所用的默认存储引擎。 |
NDBCLUSTER |
成簇表,容错表,以存储器为基础的表。也称为NDB。 |
2)在MySQL 5.1中,只有MyISAM,InnoDB, BDB和MEMORY存储引擎支持在含有NULL值的列中编索引。在其它情况下,您必须定义已编索引的列为NOT NULL,否则会出现错误。
3)对于MyISAM表,每个NULL列要多占用一位,进位到距离最近的字节。对于InnoDB表,NULL列的存储量与NOT NULL列的存储量没有区别。