如何在身份列中设置外键 [英] How to set forign key to the identity column

查看:87
本文介绍了如何在身份列中设置外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个具有数据的表..一个表具有列primarykey + identity key ....如何将此列设置为外键而将另一表设置为外键??????????

I had 2 tables with data..one table with column primarykey+identity key....how can i set this column as forign key to another table as forign key??????????

推荐答案

此处是专辑"和曲目"表的示例代码.相册ID是主要的身份列.

Here is the sample code where ''album'' and ''track'' tables. Album ID is the primary identity column.

CREATE TABLE album(
  id int IDENTITY NOT NULL PRIMARY KEY,
  title VARCHAR(100),
  artist VARCHAR(100)
);

CREATE TABLE track(
  album int,
  dsk INTEGER,
  posn INTEGER,
  song VARCHAR(255),
  FOREIGN KEY (album) REFERENCES album(id)
);


这篇关于如何在身份列中设置外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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