mysql 建表語句

2021-10-01 02:14:14 字數 907 閱讀 8009

下面是自己工作中總結的建表語句: 

自增id 和 主鍵id

業務字段

系統字段

索引

create table `tb_demo` (

`inc_id` int(11) not null auto_increment comment '自增主鍵',

`id` varchar(50) not null comment '主鍵id',

`name` varchar(100) default null comment '姓名',

`creator` varchar(50) default null comment '建立者',  

`updater` varchar(50) default null comment '更新者',

`create_time` timestamp not null default current_timestamp comment '建立時間',

`update_time` timestamp not null default current_timestamp on update current_timestamp comment '更新時間',

`remark` varchar(255) default null comment '備註',

`deleted` int(1) default '0' comment '狀態:0未刪除 ;1 已刪除',  

key `id_index` (`id`) using btree,  

primary key (`increment_id`) using btree

) engine=innodb auto_increment=1 default charset=utf8 row_format=dynamic comment='表名';

mysql建表語句

在sql語句中注意 約束的概念 1.實體完整性約束 主鍵 唯一且非空 primary key 違約處理 no action 拒絕執行 2.參照完整性約束 外來鍵約束 foregin key references tablename filedname on delete update casecad...

mysql建表語句

mysql裝好以後,進入命令列,開始建表需要先建立乙個database.開始使用 create database mybase use mybase create table user id int 10 auto increment not null primary key,username va...

mysql建表語句

工作的時候總會寫一些建表語句提交給db,有的時候就會忘記主鍵自增寫法,以及一些型別的標註,下面是乙個比較全的建表語句,包括各種型別。create table minisite lock site id int not null auto increment primary key,admin id ...