Foreign key with basic reference
SQL
Easy
9 views
Problem Description
Create Departments(dept_id, dept_name) and Employees(emp_id, name, dept_id). Add FK so employee dept_id must exist in Departments.
Output Format
DDL statement(s)
Sample Test Case
Input:
Employees, Departments
Output:
Tables created with FK
Official Solution
CREATE TABLE Departments (dept_id INT PRIMARY KEY, dept_name VARCHAR(100) NOT NULL); CREATE TABLE Employees (emp_id INT PRIMARY KEY, name VARCHAR(100) NOT NULL, dept_id INT NOT NULL, FOREIGN KEY (dept_id) REFERENCES Departments(dept_id));
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!