---- primary key 是主键
---- unique 是代表唯一
---- default 是代表默认值
---- check 代表范围
create table tb_test
(
id varchar2(15) primary key,
name varchar2(10) not null unique,
sex char(2) not null default 'male',
age number not null check(Age>=10 and Age<=99),
Address varchar2(50),
start_date date default sysdate,
constraint tb_test_fk foreign key(id) references stuInfo(id)
)
这里可以设置外键:
constraint tb_test_fk foreign key(id) references stuInfo(id)
这里可以设置主键:
constraint tb_test_pk primary key (id),
如果要设置联合主键则可以:
constraint tb_test_pk primary ke (id,name)
如果表已经建好 要添加主外键的话可以使用以下命令
alter table 表名 add primary key (字段名)
alter table 表名 add index 索引名