简体   繁体   English

尝试添加fk时无效的ALTER TABLE选项

[英]invalid ALTER TABLE option when trying to add fk

ALTER TABLE OtherCharges
(
    ADD FOREIGN KEY (BookingID) REFERENCES Bookings(BookingID)
);

Above is the code I have and the error I am getting is "invalid ALTER TABLE option" any help would be appreciated. 上面是我的代码,我得到的错误是“无效的ALTER TABLE选项”,将不胜感激。

You might want to have a look at the SQL Reference . 您可能需要看一下SQL Reference To add a foreign key you'd use 添加您要使用的外键

ALTER TABLE OTHERCHARGES
  ADD CONSTRAINT OTHERCHARGES_FK1
    FOREIGN KEY (BOOKING_ID) REFERENCES BOOKINGS(BOOKING_ID)
      ON DELETE NO ACTION;

Always a good idea to name your constraints something reasonable but simple. 给您的约束起个合理而简单的名字总是一个好主意。 Also, for FK's always specify an ON DELETE action, even if it's NO ACTION - that way it's explicitly stated and easy to understand. 同样,对于FK始终指定ON DELETE操作,即使它不是NO ACTION,也就是这样明确声明并易于理解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 SQL 服务器中添加带有 ONLINE = ON 的约束时,“ALTER TABLE 语句中选项 ONLINE 的使用无效” - "Invalid usage of the option ONLINE in the ALTER TABLE statement" in SQL Server when add constraint with ONLINE = ON SQL无效的ALTER TABLE选项 - SQL Invalid ALTER TABLE option ORA-01735: 无效的 ALTER TABLE 选项 - ORA-01735: invalid ALTER TABLE option 添加列时无效的ALTER TABLE OPTION - INVALID ALTER TABLE OPTION on adding column Oracle SQL - 无效的更改表选项 - Oracle SQL- Invalid Alter Table Option ORA-01735:ALTER TABLE选项无效(尝试在COLUMN上删除DEFAULT时) - ORA-01735: invalid ALTER TABLE option (While trying to drop DEFAULT on a COLUMN) ORA-01735:无效的ALTER TABLE选项(在尝试更改列的默认值时) - ORA-01735: invalid ALTER TABLE option (While trying to change DEFAULT on a COLUMN) 更改表添加具有默认值和FK的列,该值在FK参考数据中不存在 - Alter Table Add Column with Default value And FK, that Value no existing in FK Reference Data 尝试插入表格时,“ORA-00922:缺少或无效选项” - “ORA-00922: missing or invalid option” when trying to insert into table 改变表<table_name>拒绝限制无限制返回无效的更改表选项? - Alter table <table_name> reject limit unlimited returns invalid Alter table option?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM