SQL server 创建表,索引,主键,外键

if object_id('student', 'U') is not null
	drop table student
go

create table student(
	sno		varchar(20) not null ,
	sage	decimal not null,
	sname	varchar(20)
)
go

create nonclustered index stu_index on student(sno)
go

if(object_id('person', 'U') is not null)
	drop table person
go

create table person(
	sname varchar(20) not null
)
go

alter table person add primary key(sname)
go

create nonclustered index person_index on person(sname)
go

alter table student add primary key(sno, sage)
go

alter table student add foreign key(sname) references person(sname)
go


posted @ 2014-06-30 10:52  marco_tan  阅读(396)  评论(0编辑  收藏  举报