drop foreign key
ALTER TABLE table_name
DROP CONSTRAINT fk_name;
drop foreign key
ALTER TABLE table_name
DROP CONSTRAINT fk_name;
sql foreign key
CREATE TABLE orders (
id int NOT NULL,
user_id int,
product_id int,
PRIMARY KEY (id),
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (product_id) REFERENCES products(id)
);
sql foreign key
create table Jobs(
job_id number not null,
job_title varchar(30),
min_salary number,
max_salary number
);
create table job_history(
employee_id number not null,
start_date date,
end_date date,
job_id number not null,
department_id number
);
alter table jobs add constraint pk_jobs primary key(job_id);
alter table job_history add constraint fk_job foreign key(job_id) references jobs(job_id);
foreign key constraint
CREATE TABLE Students ( /* Create table with foreign key - Way 1 */
ID INT NOT NULL
Name VARCHAR(255)
LibraryID INT
PRIMARY KEY (ID)
FOREIGN KEY (Library_ID) REFERENCES Library(LibraryID)
);
CREATE TABLE Students ( /* Create table with foreign key - Way 2 */
ID INT NOT NULL PRIMARY KEY
Name VARCHAR(255)
LibraryID INT FOREIGN KEY (Library_ID) REFERENCES Library(LibraryID)
);
ALTER TABLE Students /* Add a new foreign key */
ADD FOREIGN KEY (LibraryID)
REFERENCES Library (LibraryID);
what is foreign key
Foreign Key:
It is a column that comes from a different table and
using Foreign key tables are related each other
It is the primary key of another table
It can be duplicate or null for another table
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