如何在访问中创建外键? [英] How do I create a foreign key in access?

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

问题描述

我有以下代码:

CREATE TABLE Faculty (
FacSSN text(9) primary key,
FacFirstName Text(30) null,
FacLastName Text(50) null,
FacCity text(50) null,
FacState text(2) null,
FacDept text (6) null,
FacRank text(6) null,
FacSalary currency null,
FacSupervisor text(9) null,
FacHireDate datetime null,
facZipCode text(9) null,
offerNo text(6) ,

FOREIGN KEY offerNo REFERENCES ClassOffering (OfferNo)

);

我还有一个名为ClassOffering的表,该表已经在其中创建了"OfferNo".我需要在上面的表中创建一个链接"到ClassOffering的外键.我正在使用Access.

I have another table called ClassOffering created with "OfferNo" already in it. I need to create a foreign key in the table above that 'links' to ClassOffering. I am using Access.

推荐答案

布兰登,当定义为text(6)

forign keys的数据类型需要匹配,并且上一个问题的ClassOffering表具有offerNo INTEGER.将text(6)更改为INTEGER进行匹配,外键将起作用

The data types for forign keys need to match and the ClassOffering table from your previous question has offerNo INTEGER. Change the text(6) to INTEGER to match, and the foreign key will work

您需要在offerNo栏上加上括号,如下所示:

You need to put parenthesis around the column offerNo, like this:

FOREIGN KEY (offerNo) REFERENCES ClassOffering (OfferNo)

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

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