创建架构,复合主键,主表,从表的创建方法。
create schema XIXI--创建架构
create table XIXI.U(
id int not null ,
s_id int not null,
u_id int
constraint PK_ID primary key(id,s_id,u_id)--创建复合主键
)
create table XIXI.O(--主表
id int constraint PK_OK primary key,
)
create table XIXI.K(--从表
id int constraint FK_id foreign key(id) references XIXI.O(id)
)
--先删从表再删主表
drop table XIXI.K
drop table XIXI.O
create type Happy_HAHA from nvarchar(20) not null
create type OK from int
create table I(
id int not null,
name nvarchar(20) constraint UQ_name unique,
sex char(2) check(sex in('M','F')),
age int check(age between 17 and 20),
tel nvarchar(20) check(tel like'130[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]')
,[address] nvarchar(20) default 'NO',
JL Happy_HAHA,
xixi OK
)
create synonym LiuDaGe for AdventureWorks.HumanResources.Employee
select * from LiuDaGe
alter table I add constraint PK_id primary key(id)