You are on page 1of 3

# Primary Key with errors (Duplicates):-

Create Database Employee;

create table Emp_reg(Emp_id int primary key, fname varchar(30), email_id varchar(20),Ph_no
bigint,salary int, city varchar(30));

insert into employee.emp_reg values (1, 'atul', 'atul@gmail.com', 8904536798,30000,'boragaon'),

(2, 'Rohan', 'Rohan@gmail.com', 4564785127, 45000,'Kolhapur'),

(3, 'Ram', 'Ram@gmail.com', 7894562581,35200 ,'sangali'),

(3, 'shyam', 'Shyam@gmail.com ', 7824537895,45000,'Miraj'),

(5, 'pratik', 'Pratik@gmail.com',34567891445,26300,'Jat');

Output:-

#Primary Key
create database Employee;
Create table Employee.emp_reg(E_id int primary key, fname varchar(20),email_id
varchar(35), Ph_No bigint, salary int, city varchar(45));
insert into employee.emp_reg(E_id,fname,email_id,Ph_no,salary,city) value (1, 'atul',
'atul@gmail.com', 8904536798,30000,'boragaon'),
(2, 'Rohan', 'Rohan@gmail.com', 4564785127, 45000,'Kolhapur'),
(3, 'Ram', 'Ram@gmail.com', 7894562581,35200 ,'sangali'),
(4, 'shyam', 'Shyam@gmail.com ', 7824537895,45000,'Miraj'),
(5, 'pratik', 'Pratik@gmail.com',34567891445,26300,'Jat');
#Primary key with null values
Create table Employee.emp_reg1(E_id int primary key, fname varchar(20),email_id varchar(35),
Ph_No bigint, salary int, city varchar(45));
insert into employee.emp_reg1(E_id,fname,email_id,Ph_no,salary,city) value (1, 'atul',
'atul@gmail.com', 8904536798,30000,'boragaon'),
(2, 'Rohan', 'Rohan@gmail.com', 4564785127, 45000,'Kolhapur'),
(3, 'Ram', 'Ram@gmail.com', 7894562581,35200 ,'sangali'),
(null, 'shyam', 'Shyam@gmail.com ', 7824537895,45000,'Miraj'),
(5, 'pratik', 'Pratik@gmail.com',34567891445,26300,'Jat');

#Foreign Key:-
create table employee.Project(Pro_id int, Emp_id int , client_id int ,Pro_date date, foreign key
(emp_id) references employee.Emp_reg(E_id));
insert into employee.project values (2345,1,4,20120126),
(9876,2,5,20190228),(3455,3,6,20171012);

# Foreign key with no value exist in referenced table:-


create table employee.Project(Pro_id int, Emp_id int , client_id int ,Pro_date date, foreign key
(emp_id) references employee.Emp_reg(E_id));
insert into employee.project values (2345,1,4,20120126),
(9876,2,5,20190228),(3455,3,6,20171012);
#foreign key with Null Values :-
create table employee.Project1(Pro_id int, Emp_id int , client_id int ,Pro_date date, foreign key
(emp_id) references employee.Emp_reg(E_id));
insert into employee.project1 values (2345,1,4,20120126),
(9876,2,5,20190228),(3455,null,6,20171012);

#Foreign key With Not Null Values :-


Create
Database Employee;
Create table Employee.Emp_reg(Emp_id int Not null, fnmae varchar(30),
Email_id varchar(20),Ph_no bigint, salary int, city varchar(30));
insert into employee.emp_reg(E_id,fname,email_id,Ph_no,salary,city) value (1,
'atul', 'atul@gmail.com', 8904536798,30000,'boragaon'),
(2, 'Rohan', 'Rohan@gmail.com', 4564785127, 45000,'Kolhapur'),
(3, 'Ram', 'Ram@gmail.com', 7894562581,35200 ,'sangali'),
(4, 'shyam', 'Shyam@gmail.com ', 7824537895,45000,'Miraj'),
(5, 'pratik', 'Pratik@gmail.com',34567891445,26300,'Jat');

Output :-

You might also like