如何在netbeans sql中使用外键约束来进行参考完整性?

时间:2017-04-07 06:07:31

标签: mysql netbeans

我正在尝试在netbeans中编写sql代码。 我有两张桌子:

Create table building(
        building_name varchar(10) not null primary key,
        building_location varchar(20),
        building_room_number integer);

Insert into building values('Building A', 'Location A',34);
Insert into building values('Building B','Location B',45);
Insert into building values('Building C', 'Location C',40);

Create table room(
        room_number integer primary key,
        building_name varchar(10));

Insert into room values(1, 'Building A');
Insert into room values(2, 'Building B');
Insert into room values(3,  'Building C');

然后我想创建外键来进行参照完整性。

ALTER TABLE room
ADD CONSTRAINT FK_room
FOREIGN KEY (building_name) REFERENCES building(building_name)
ON DELETE RESTRICT ON UPDATE CASCADE;

Netbeans一直给我这个错误

  [Exception, Error code 905, SQLState 42000] ORA-00905: missing keyword

我不确定我的语法有什么问题。我应该如何在netbeans sql中编写外键约束?

感谢您的帮助><

1 个答案:

答案 0 :(得分:0)

您的语法在MySQL中是正确的。

您发布的错误日志看起来像Oracle日志。您确定在Netbeans选项卡中执行了ALTER语句吗?