我正在使用SQL Server 2008R2管理Studio [英] I am using SQL Server 2008R2 Management Studio

查看:76
本文介绍了我正在使用SQL Server 2008R2管理Studio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SQL Server 2008R2 Management Studio

I am using SQL Server 2008R2 Management Studio

推荐答案

对于SQL Server,FOREIGN KEY和PRIMARY kEY约束位于列表的末尾,而不是在线声明该列: http://www.w3schools.com/sql/sql_foreignkey.asp [ ^ ]
With SQL server, FOREIGN KEY and PRIMARY kEY constraints go at the end of the list, not on the line declaring the column: http://www.w3schools.com/sql/sql_foreignkey.asp[^]


外键,可以将其放在作为外键引用的列上,也可以放在必须同时定义引用父表的列的末尾.

如果外键是使用多列构建的,则必须最后分别定义外键.

外键也可以单独创建.请考虑以下示例:
When you create a foreign key, it can be placed on the column, which is the foreign key reference or at the end when you must define also the column that references the parent table.

If the foreign key is built using multiple columns, then you must define the foreign key separately in the end.

The foreign key can also be created separately. Consider the following examples:
-- parent table
create table a (
   id int not null primary key
);

-- inline foreign key
create table b (
   id int not null primary key,
   fk int not null foreign key references a (id)
);

-- using constraint definition in the create table
create table c (
   id int not null primary key,
   fk int not null,
   constraint fk_c_a foreign key (fk) references a (id)
);

-- foreign key defined separately
create table d (
   id int not null primary key,
   fk int not null
);
alter table d add constraint fk_d_a foreign key (fk) references a (id);



另请参阅:创建表 [



See also: CREATE TABLE[^]


这篇关于我正在使用SQL Server 2008R2管理Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆