1.主键约束代码
create table usersa(
user_qq VARCHAR(20) not null PRIMARY KEY,
user_name VARCHAR(50) not NULL,
user_sex char(2) NOT NULL,
user_birthday date NOT NULL,
user_mobile char(11) not null
)
2.外键约束代码:
<strong>create table scores(
user_qq varchar(20) not null
-- 表明该数据是引用users(user_qq)表
references users(user_qq),
gno int not null,
score int not null
)</strong>
制作表的界面(外键约束引用了其他表的数据),并将数据导入本表中
3.检查约束代码:
<strong>create table games
(
gno int not null check(gno>0),
gname varchar(50) not null,
gtype varchar(20) not null
)</strong>
制作的界面(检查约束规定了哪条记录要满足的条件,例如此处约束了gno必须要大于0)
4.默认约束代码
CREATE TABLE moren
(
user_qq VARCHAR(20) NOT NULL,
user_name VARCHAR(50) NOT NULL,
user_sex CHAR(2) NOT NULL DEFAULT 'na',
user_birthday date NOT NULL,
user_phone CHAR(11) NOT NULL
)
制作的界面(默认记录的某一数据为某值,这里默认性别为男)
5.自增列代码(某一列上自增数据):
CREATE TABLE gamels
(
gno INT NOT NULL auto_increment,
GNAME VARCHAR(50) NOT NULL,
gType VARCHAR(20) NOT NULL
)