use [test] Go/****** object: Table [DBO]. [t_student] script Date: 10/12/2010 19:28:09 ******* // ******** sqlserver 2008 *********/
Set ansi_nulls ongoset quoted_identifier ongocreate table [DBO]. [t_student] ([ID] [int] Identity (1,1) not null, [teacherid] [int] Null, [name] [nvarchar] (50) null, [PWD] [nvarchar] (50) null, constraint [pk_t_student] primary key clustered ([ID] ASC) with (pad_index = OFF, statistics_norecompute = OFF, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary]) on [primary] goexec sys. sp_addextendedproperty @ name = n' MS _ description', @ value = n' id', @ level0type = n' schema ', @ level0name = n' dbo ', @ level1type = n'table', @ level1name = n't_ student ', @ level2type = n'column', @ level2name = n'id' goexec sys. sp_addextendedproperty @ name = n' MS _ description', @ value = n' instructor id', @ level0type = n' schema ', @ level0name = n' dbo ', @ level1type = n' table ', @ level1name = n' T _ student', @ level2type = n' column ', @ level2name = n' teacherid' goexec sys. sp_addextendedproperty @ name = n' MS _ description', @ value = n' name', @ level0type = n' schema ', @ level0name = n' dbo ', @ level1type = n'table', @ level1name = n't_ student ', @ level2type = n'column', @ level2name = n'name' goexec sys. sp_addextendedproperty @ name = n' MS _ description', @ value = n' password', @ level0type = n' schema ', @ level0name = n' dbo ', @ level1type = n' table ', @ level1name = n' T _ student', @ level2type = n' column ', @ level2name = n' pwd' goexec sys. sp_addextendedproperty @ name = n' MS _ description', @ value = n' T _ student ', @ level0type = n' schema', @ level0name = n' dbo ', @ level1type = n' table ', @ level1name = n' T _ student' Go/******** exec2005 syntax execute sp_addextendedproperty 'Ms _ description ', 'name', 'user', 'dbo', 'table', 't_ student ', 'column ', 'name' go ************/-- manually add a foreign key constraintCode Alter table [DBO]. [t_student] with check add constraint [fk_t_studen_reference_t_teache] foreign key ([teacherid]) References [DBO]. [t_teacher] ([ID]) on update cascadeon Delete cascadegoalter table [DBO]. [t_student] Check constraint [fk_t_studen_reference_t_teache] Go