The document outlines the SQL commands to create and manage an Employees table with various constraints, including primary keys, foreign keys, unique constraints, and check constraints. It also details the creation of related tables such as Departments, Projects, Cities, and Bonuses, along with rules to ensure data integrity and specific conditions for employee attributes. Additionally, it includes commands to set default values and restrict certain fields to predefined options.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
6 views
SQL Part 4 Practice Questions and Answers
The document outlines the SQL commands to create and manage an Employees table with various constraints, including primary keys, foreign keys, unique constraints, and check constraints. It also details the creation of related tables such as Departments, Projects, Cities, and Bonuses, along with rules to ensure data integrity and specific conditions for employee attributes. Additionally, it includes commands to set default values and restrict certain fields to predefined options.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4
1.
Create the Employees table with constraints
CREATE TABLE Employees ( EmployeeID INT PRIMARY KEY, -- PRIMARY KEY constraint FirstName VARCHAR(50) NOT NULL, -- NOT NULL constraint LastName VARCHAR(50) NOT NULL, -- NOT NULL constraint Department VARCHAR(50) NOT NULL, -- NOT NULL constraint Salary INT CHECK (Salary > 50000 AND Salary < 100000), -- CHECK constraint HireDate DATE NOT NULL, -- NOT NULL constraint City VARCHAR(50) DEFAULT 'Unknown' -- DEFAULT constraint );