sql server外鍵建立的寫法
作者:佚名
sql server外鍵約束建立的寫法是學(xué)習(xí)SQL數(shù)據(jù)庫過程中都需要掌握的,下面就將為您介紹該SQL語句的寫法,供您參考。
在我們使用sql server的過程中,經(jīng)常需要用到sql server外鍵約束,下面就將為您介紹sql server外鍵約束是如何建立的,希望對(duì)您學(xué)習(xí)sql server外鍵能有些幫助。
- CREATE TABLE [dbo].[Varrily]
- (
- [ID] [bigint] NOT NULL ,
- [Name] [char] (10) NULL ,
- [Address] [char] (480) NULL ,
- [Introduction] [ntext] NULL
- )
- CREATE TABLE [dbo].[MyTable]
- (
- [ID] [bigint] IDENTITY (1, 1) NOT NULL ,
- [AuthorID] [bigint] NOT NULL ,
- [Title] [char] (40) NULL ,
- [Date_of_Created] [datetime] NULL
- )
- 被引用的鍵必須***,可以設(shè)置為主鍵或者添加***約束。
- alter table dbo.Varrily add constraint pk_id primary key (ID)
- alter table dbo.Varrily add constraint un_id unique (ID)
- alter table dbo.MyTable add constraint fk_AuthorID foreign key (AuthorID) references dbo.Varrily([ID])
【編輯推薦】
責(zé)任編輯:段燃
來源:
互聯(lián)網(wǎng)