SQL Constraints
SQL Constraints
Sample Tables
Cross join 1
Self join
Except Output
Set Operators
3
3
CT *
FROM employees
FROM employees e1
A primary key is a unique identifier for ROSS JOIN departments; INNER JOIN employees e2
(
of the first SELECT query that are not present EX EPT
epartment
C
Syntax
if the user not giving any value
Add constraint pk_student_idprimary key (student_id)
Employee_Details1 Employee_Details2
Create table student_course
which you are trying to make the primary student_id int foreign key references student(student_id),
Inner join
key using the alter command first you have student_course varchar(100),
SELECT *
) FROM employees
Foreign key
Union Union All Intersect Except
Add default to be decided for professor
' '
A foreign key is a column or a set of Set operators are used to combine two result set together SQL
columns in a database table that
heck onstraint Left join
nion Output
C C
refers to the primary key of another
table, establishing a link between the U
SELECT *
ON
Get all distinct rows between
Create table student_course
employees.department_id = Employee_Details1 and
(
Create table student
departments.department_id; Employee_Details2 table.
student_id int foreign keyreferences student(student_id),
(
student_course varchar(100),
student_id int primary key,
professor varchar(100)
student_name varchar(30),
SELECT * FROM Employee_Details1
Right join
U
Alter table student_course
Alter table student
CT *
SELE
Add constraint fk_student_Id foreign key references Add constraint ck_age check(student_age>0) FROM employees
Get all rows with duplicates between
student(student_id) RIGHT JOIN departments
Employee_Details1 and
ON
Employee_Details2 table.
SQL
employees.department_id =
Joins
departments.department_id;
U nique Key
Inner Join
SELECT * FROM Employee_Details1
Cheat Sheet
UNION
values in a specified column or SELECT * FROM Employee_Details2; two SELECT queries, including all rows,
combination of columns are distinct
including duplicates.
within a database table.
Full join
Intersect Output
(
FROM employees
student_name varchar(30),
ON
Full Outer
Join
between the result sets of two SELECT INTERSE T