码迷,mamicode.com
首页 > 数据库 > 详细

通过SQL创建一个有主键自动递增有默认值不为空有注释的表

时间:2017-09-06 14:33:42      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:主键   tab   var   comm   blog   bsp   varchar   nod   默认   

-- create database db_std_mgr_sys;
use db_std_mgr_sys;
create table student(
std_id bigint not null auto_increment,
std_name varchar(10) not null default ‘‘,
std_code varchar(20) not null default ‘‘ comment 学号,值唯一,
std_sex varchar(8) not null default ‘‘,
std_phone varchar(20) not null default ‘‘,
school_id bigint not null default -1 comment 所在学校id,
grade_id BIGINT not null default -1 comment 所在年级id,
cls_id bigint not null default -1 comment 所在班级id,
primary key(std_id)
)engine=INNODB,CHARSET=utf8,comment=学生表;

 表二:

use db_std_mgr_sys;
create table `user`(
uid bigint not null auto_increment,
username varchar(20) not null,
`password` varchar(40) not null,
phone varchar(20) not null,
email varchar(30) not null,
primary key (uid),
unique key (username),
unique key (phone),
unique key (email)
)engine=INNODB charset=utf8
/*这里要注意key后面一定要有()而不能直接是primary key uid,这里的key就是索引的意思,
而前面的primary、unique都是修饰,主键也是索引的一种;若只有key没有修饰则表示该索引是普通索引;
若是unique key uq_username (username),则是给这个索引命名为uq_username,否则索引名和索引的列名是一样的为username*/

 

通过SQL创建一个有主键自动递增有默认值不为空有注释的表

标签:主键   tab   var   comm   blog   bsp   varchar   nod   默认   

原文地址:http://www.cnblogs.com/silentdoer/p/7404030.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!