SQL Server Table Generation creation SQL, foreign key definition, SQL

Source: Internet
Author: User
 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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.