alter table add foreign key mysql
ALTER TABLE orders
ADD
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
alter table add foreign key mysql
ALTER TABLE orders
ADD
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
drop foreign key
ALTER TABLE table_name
DROP CONSTRAINT fk_name;
mysql add foreign key
-- On Create
CREATE TABLE tableName (
ID INT,
SomeEntityID INT,
PRIMARY KEY (ID),
FOREIGN KEY (SomeEntityID)
REFERENCES SomeEntityTable(ID)
ON DELETE CASCADE
);
-- On Alter, if the column already exists but has no FK
ALTER TABLE
tableName
ADD
FOREIGN KEY (SomeEntityID) REFERENCES SomeEntityTable(ID) ON DELETE CASCADE;
-- Add FK with a specific name
-- On Alter, if the column already exists but has no FK
ALTER TABLE
tableName
ADD CONSTRAINT fk_name
FOREIGN KEY (SomeEntityID) REFERENCES SomeEntityTable(ID) ON DELETE CASCADE;
alter foreign key
ALTER TABLE Employee
ADD FOREIGN KEY (DeptNo) REFERENCES Department(DeptNo);
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us