我正在尝试在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中编写外键约束?
感谢您的帮助><
答案 0 :(得分:0)
您的语法在MySQL中是正确的。
您发布的错误日志看起来像Oracle日志。您确定在Netbeans选项卡中执行了ALTER
语句吗?