You are on page 1of 16

Practical : DDL Commands.

Name : ___
Roll No : 43

create database Employee


use Employee
create table emp
(ID int,NAME varchar(20),ADDRESE varchar(20),SALARY money )
insert into emp values(101,'TEJAS','ROZODA',10000);
insert into emp values(102,'VEDANT','NAVHI',15000);
insert into emp values(103,'GAJANAN','MALKAPUR',20000);
insert into emp values(104,'GIRISH','SAVDA',25000);
select * from emp

alter table emp add AGE int;


update emp set AGE=22 where ID=101
update emp set AGE=24 where ID=102
update emp set AGE=26 where ID=103
update emp set AGE=28 where ID=104

exec sp_rename 'emp','emp_details'


select * from emp_details

truncate table emp_details

drop table emp_details

OUTPUT :
Practical : DML Commands.
Name : ___
Roll No : 43

create database Employee


use Employee
create table emp
(ID int not null,
NAME varchar(20),
AGE int ,
SALARY money,
ADDRESS varchar(30))
insert into emp values (101,'Tejas Lidhure',25,30000,'Jalgaon')
insert into emp values (102,'Vedant Zope',26,33000,'Pune')
insert into emp values (103,'Gajanan Talole',24,25000,'Malkapur')
insert into emp values (104,'Girish Bendale',25,40000,'Buldhana')
insert into emp values (105,'Harshal Patil',28,30000,'Amravati')

update emp set name='Manish Patil' where id=104


select * from emp
delete from emp where id=105

OUTPUT 1 : Update

OUTPUT 2 : Delete
Practical : Types of Constraints.
Name : ___
Roll No : 43

create database Employee2


use employee2
create table emp1
( ID int not null unique,
NAME varchar(25),
BATCH_NO int not null primary key,
AGE int check(AGE>=18),
SALARY_DATE datetime default getdate());

insert into emp1 values(101,'Girish Patil',3501,27,'')


insert into emp1 values(102,'Vedant Mahajan',3502,28,'')
insert into emp1 values(103,'Tejas Bendale',3503,24,'')
insert into emp1 values(104,'Gajanan Patil',3504,30,'')
select * from emp1

create table emp2


( ID int foreign key references emp1(ID),
NAME varchar(25),
BATCH_NO int not null,
AGE int check(AGE>45),
)

insert into emp2 values(101,'Girish Patil',3501,49)


insert into emp2 values(102,'Vedant Mahajan',3502,60)
insert into emp2 values(103,'Tejas Patil',3503,57)
select * from emp2

OUTPUT :
Practical : Select clause , where clause , OrderedBy , Distinct , GroupBy etc..
Name : ___
Roll No : 43

create database Student


create table std
(ID int,
NAME varchar(20),
ADDRESS varchar(20),
ADMISSION_DATE datetime default getdate(),
MARKS int )

insert into std values ( 11, 'Tejas', 'Jalgaon', ' ',99 )


insert into std values ( 12, 'Vedant', 'Nhavi', ' ',95 )
insert into std values ( 13, 'Gajanan', 'Malkapur', ' ',93 )
insert into std values ( 14, 'Harshal', 'Jalgaon', ' ',13)
insert into std values ( 15, 'Girish', 'Jalgaon', ' ',85)
select * from std

update std set NAME='Falgun' where ID = 14

select distinct name from std

select ID, NAME from std order by ID desc


select ID, NAME from std order by ID asc

select NAME, count(ID) from std group by NAME

OUTPUT :

OUTPUT : Use of Order By clause


OUTPUT : Use of Distinct clause

OUTPUT : Use of Group By clause


Practical : Aggregate Function.
Name : ___
Roll No : 43

create database Student


create table std
(ID int,
NAME varchar(20),
ADDRESS varchar(20),
ADMISSION_DATE datetime default getdate(),
MARKS int )

insert into std values ( 11, 'Tejas', 'Jalgaon', ' ',99 )


insert into std values ( 12, 'Vedant', 'Nhavi', ' ',95 )
insert into std values ( 13, 'Gajanan', 'Malkapur', ' ',93 )
insert into std values ( 14, 'Harshal', 'Jalgaon', ' ',13)
insert into std values ( 15, 'Girish', 'Jalgaon', ' ',85)

select * from std

select sum (MARKS) from std


select avg (MARKS) from std
select max (MARKS) from std
select min (MARKS) from std
select count (ID) from std

OUTPUT :

OUTPUT : Sum
OUTPUT : Avg

OUTPUT : Max

OUTPUT : Min

OUTPUT : Count
Practical : String Function.
Name : ___
Roll No : 43

create database StringFunction


select ascii('a')
select len('hello World')
select concat('Data','Base')
select lower('IMR')
select upper('jalgaon')
select replace('imrpune','pune','jalgaon')
select reverse('girish')
select space(7)
select substring('IndianArmy',1,6)

OUTPUT : Max

4
5

9
Practical : Date & Time Function.
Name : ___
Roll No : 43

select getdate()
select GETUTCDATE()
select day(getdate()) as 'day'
select month(getdate()) as 'month'
select year(getdate()) as 'year'
select datediff(day,2023-23-03,2023-5-03) as 'datediff'

OUTPUT :

1 4

2 5

3 6
Practical : Union,Intersection and Set Difference.
Name : ___
Roll No : 43

create database demo


use demo
create table teacher
(id int not null,
name varchar(20),
address varchar(25)
)
insert into teacher values(101,'Gajanan Talole','Malkapur')
insert into teacher values(102,'Vedant Zope','Jalgaon')
insert into teacher values(103,'Tejas Lidhure','Jalgaon')
select * from teacher

create table Department


(Did int,
Dname varchar(20),
Daddress varchar(25)
)
insert into Department values(101,'Nikesh Patil','Malkapur')
insert into Department values(102,'Vedant Zope','Jalgaon')
insert into Department values(105,'Mayur Patil','Jalgaon')
select * from Department

select id,name from teacher union select Did,Dname from Department


select id,name from teacher union all select Did,Dname from Department
select id,name from teacher intersect select Did,Dname from Department
select name from teacher except select Dname from Department

OUTPUT :

1 2

3 4
Practical : View.
Name : ___
Roll No : 43

create database Students


use Students
create table stud1
(ID int not null,
NAME varchar(25),
COURSE varchar(10),
AGE int)
insert into stud1 values(101,'Gajanan Talole','IMCA',20)
insert into stud1 values(102,'Vedant Zope','IMCA',22)
insert into stud1 values(103,'Harshal Patil','BCA',22)
insert into stud1 values(104,'Tejas Lidhure','IMCA',19)
create view v1 as select ID,NAME from stud1
select * from v1

OUTPUT :
Practical : Join (Inner Join, Left Join, Right Join, Full Join).
Name : ___
Roll No : 43

create database JoinDemo


create table teacher
( id int not null,
name varchar(20),
salary money )
truncate table teacher
insert into teacher values (101,'Nikesh Patil',20000)
insert into teacher values (102,'Vedant Mahajan',22000)
insert into teacher values (104,'Tejas Bendale',25000)
insert into teacher values (105,'Gajanan Patil',25000)
select * from teacher

create table department


( Did int not null,
Dname varchar(20),
payment_Date datetime)
insert into department values (101,'Nikesh Patil',' ')
insert into department values (103,'Girish Dhande',' ')
insert into department values (105,'Gajanan Patil',' ')
select * from department
drop table department

select teacher.id,teacher.name,department.Did,department.Dname from


teacher inner join department on teacher.id=department.Did

select teacher.id,teacher.name,department.Did,department.Dname from


teacher left join department on teacher.id=department.Did

select teacher.id,teacher.name,department.Did,department.Dname from


teacher right join department on teacher.id=department.Did

select teacher.id,teacher.name,department.Did,department.Dname from


teacher full join department on teacher.id=department.Did

OUTPUT :

1 2
3 4
Practical : Normalization.
Name : ___
Roll No : 43

create database impdata


create table emp
( ID int not null unique,
NAME varchar(25),
BATCH_NO int not null primary key,
AGE int check(AGE>=18),
SALARY_DATE datetime default getdate());

insert into emp values(101,'Girish Patil',3501,27,'')


insert into emp values(102,'Vedant Mahajan',3502,28,'')
insert into emp values(103,'Tejas Bendale',3503,24,'')
insert into emp values(104,'Gajanan Patil',3504,30,'')
insert into emp values(105,'Harshal Patil',3506,30,'')
select * from emp1

create table retired


( ID int foreign key references emp1(ID),
NAME varchar(25),
BATCH_NO int not null,
AGE int check(AGE>45),
Retired_Date date not null
)
insert into retired values(101,'Girish Patil',3501,60,'2020-02-03')
insert into retired values(102,'Vedant Mahajan',3502,60,'2020-03-27')
insert into retired values(103,'Tejas Patil',3503,59,'2019-4-15')
select * from retired

create table finance_emp


(id int not null,
name varchar(25),
ac_type varchar(25),
)
insert into Finance_emp values(501,'Atharv Borle','Trading')
insert into Finance_emp values(502,'Rushikesh Kolte','Trading')
insert into Finance_emp values(503,'Prathmesh Patil','Current')
insert into Finance_emp values(504,'Bhavesh Mahajan','Trading')
select * from finance_emp

create table workers


(wID int not null,
name varchar(25) not null,
Work varchar(20))
insert into workers values(51,'Ram kothari','ELectricion')
insert into workers values(52,'Rohan Ingle','Floor Cleaning')
insert into workers values(53,'Dnyaneshwar Patil','Washroom Cleaning')
select * from workers
OUTPUT : Employee

OUTPUT : Rrtired

OUTPUT : Finance_emp

OUTPUT : Worksers

You might also like