Unlock

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 18

Lab 1

create table studentD (


ID int,
Name varchar (50),
Age int,
Grade Real,
Address varchar (50),
);
Insert into studentD values (1,'Ram',19,3.1,'Pokhara');
Insert into studentD values (2,'Jyoti',21,3.2,'Gaighat');
Insert into studentD values (3,'Dinesh',22,2.8,'Ktm');
Insert into studentD values (4,'Shyam',20,2.6,'Bkt');
Insert into studentD values (5,'Hari',22,3.5,'Jnk');
select * from studentD;

--to add new column


alter table studentD
Add phoneno int;
Insert into studentD values (6,'Prerna',19,3.4,'Ktm',9876);
--to change the data type
alter table satudentD
alter column phoneno bigint;
select * from studentD;
--to change the data type
alter table studentD
alter column phoneno bigint;
insert into studentD values (7,'Diya',20,'Bkt',9856);
--to drop a column
alter table studentD
Drop column Grade
select * from studentD;

--to add any constraint


Alter table studentD
Add constraint Ram unique(name)
select * from studentD;

Truncate table studentD


select * from studentD;
Lab 2: TO BE FAMILIER WITH DML(DATA MANIPULATION LANGUAGE)

create table employee(


employeeid int,
Employeename varchar(40),
Employeesalary bigint,
Employeepost varchar(40)
);
select * from employee
Insert into Employee values(1,'Anu',10000,'manager');
Insert into Employee values(2,'Sita',15000,'manager');
Insert into Employee values(3,'Jay',20000,'manager');
Insert into Employee values(4,'Nisha',25000,'manager');
Insert into Employee values(5,'Mani',30000,'manager');

--to insert null value


insert into employee(Employeeid,Employeename,Employeesalary) values(6,'sneha',60000);
--to fetch single column
select Employeeid from employee;
--to fetch multiple column
select Employeeid, Employeename from employee

--to fetch single row


select * from employee where Employeeid=1
--to delete one row
delete from employee where Employeeid=1;

update employee
set Employeepost ='clerk' where Employeeid=2;

update employee
set Employeesalary=1000000;

update employee
set Employeesalary=100000*1.10 where Employeeid=3
select * from Employee
Lab 3

create table Worldcup(


Teamname varchar(40),
Teamno int,
Teamplayerno int,
Teampoints int,
Teamcolour varchar(40),
);
select * from Worldcup12
insert into Worldcup12 values(1,'Australia',11,5,'Yellow')
insert into Worldcup12 values(2,'India',12,7,'blue')
insert into Worldcup12 values(3,'Pak',10,3,'green')
insert into Worldcup12 values(4,'sa',8,8,'green')
insert into Worldcup12 values(5,'Nepal',11,7,'navyblue')

--Where clause
Find the name of team whose jersey colour is Yellow
select Teamname from Worldcup where Teamcolour='Yellow'

--find teamname whose point is 7


select Teamname from Worldcup where Teampoints=7

--find the jersey colour of the team whose team no. is 4


select Teamcolour from Worldcup where Teamno=4

--find the no of team whose point is 7 and jersey colour is blue


select Teamno from Worldcup12 where Teampoints=7 and Teamcolour='blue'
--find the name of team whose teamno is 2 or team colour is green
select Teamname from Worldcup12 where Teamno=2 or Teamcolour='green'

-- find the name of team  whose teampoints is between 5 and 10


  select Teamname from Worldcup12 where teampoints between 5 and 10

--Arrange table in ascending order of Teampoints


 select * from Worldcup12 order by Teampoints Asc;
--Arrange table in descending order of Teampoints
 select * from Worldcup12 order by Teampoints DESC;

Lab 4
create table student(
studentid int,
name varchar(50),
department varchar(50),
grade int,
);
select*from student;
Insert into student values(1,'anil','BIM',3)
Insert into student values(2,'avik','BBA',5)
Insert into student values(3,'bikas','BBA',4)
Insert into student values(4,'chetan','BBA',6)
Insert into student values(5,'raji','BCA',5)

--to find avg grade of each department


select avg(grade)from student
group by department;

select avg(grade) as average grade from student


group by department;

select avg(grade) as averagegrade, department from student


 group by department;
--to find no of students in each department
 select count(studentid) as total,department from student
 group by department;

--to find no of student more than 1


 select count(studentid) as total,department from student
 group by department
 having count(studentid)>1;

--to find the names starting with A


 select name from student
 where name like'A%';

--to find the names ending with a


 select name from student
 where name like'%a';
--to find the names having five characters only
 select name from student
 where name like'_____';

-- retrive two rows


 select top 2*from student

--to find data/row with highest grade


 select top 1* from student
 order by grade desc;

--to find department


 select distinct department from student;

  
--to find no of student with 1,2,3
 select name from student where studentid in(1,2,3)

LAB 5:

CREATE TABLE INFO123 (


ID INT NOT NULL PRIMARY KEY,
Name VARCHAR (50),
Address VARCHAR (50) DEFAULT 'NEPAL',
Marks INT CHECK (Marks> 40),
Phoneno BIGINT NOT NULL,
Post VARCHAR (40) CHECK ( Post IN ( 'CEO' , 'MANAGER')),
Major VARCHAR (40) CHECK (LEN(Major)>5)
);
select * from INFO123

insert into INFO123 values(1,'Niharika','New Road',80, 98000000, 'CEO','Business')


insert into INFO123 values(2,'Shruti','Dhapasi', 81, 97000000, 'CEO', 'Marketing')
insert into INFO123 values(3,'Nistha','Koteshor',85, 91000000,'MANAGER','Mathematics')
insert into INFO123 values(4,'Kripa','Golfutar',70,930000000,'MANAGER','Accounts')
insert into INFO123 values(5,'Aron','New Road',75,92000000,'MANAGER','Businesss');

create table COURSES(


CID int check(CID>100),
CName varchar(40) Unique,
ID int foreign key references INFO123 (ID),
);
insert into COURSES values (101, 'BBA',1)
insert into COURSES values (111, 'BCA',2)
insert into COURSES values (112, 'BBM', 3)

select*from COURSES;

LAB REPORT 6  (SQL JOINS)

create table Student1(


Id int,
Name varchar(50),
Address varchar(50),
Height int
);

Select from Student1


insert into Student1 values(1,'Anil','Ktm',5);
insert into Student1 values(2,'Bikash','Bkt',6);
insert into Student1 values(3,'Chetan','Ktm',6);
insert into Student1 values(4,'Deepak','Bkt',5);
create table Course1(
CId int,
CName varchar(50),
CGrade real,
SId int
);

select* from Course1


insert into Course1 values(101,'DBMS',3.0,1);
insert into Course1 values(102,'Java',3.5,1);
insert into Course1 values(103,'Accounts',3.2,2);
insert into Course1 values(104,'C',3.4,5);

--Perform inner,left,right and full join.

select * from Student1


inner join Course1
on Student1.Id=Course1.SId;
select * from Student1
left join Course1
on Student1.Id=Course1.SId;

select * from Student1


right join Course1
on Student1.Id=Course1.SId;

select * from Student1


full join Course1
on Student1.Id=Course1.SId;
-- find the name of student with maximum height.
select name from Student1 where Height=(select max(Height) from student1);

--find the courses that student with Id=1 studies.


select CName from Course1 where SId=1;

--find the number of student from bhaktapur.


select count(Id) from Student1 where Address='Bkt';
--find the name of student with heighest grade.
select Name from Student1
full join Course1
on Student1.Id=Course1.SId
where CGrade=(select max(CGrade) from Course1);

You might also like