0% found this document useful (0 votes)
0 views

PracticeSet

The document outlines the creation of two tables, 'department' and 'student', along with their relationships and data entries. It includes various SQL queries for selecting, inserting, and joining data from these tables, as well as the creation of a 'customer' table with related operations. The document demonstrates how to manipulate and retrieve data using SQL commands, including views and different types of joins.

Uploaded by

lalitpatil784636
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

PracticeSet

The document outlines the creation of two tables, 'department' and 'student', along with their relationships and data entries. It includes various SQL queries for selecting, inserting, and joining data from these tables, as well as the creation of a 'customer' table with related operations. The document demonstrates how to manipulate and retrieve data using SQL commands, including views and different types of joins.

Uploaded by

lalitpatil784636
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

create table department(

dep_id int primary key,


dep_name varchar(20) NOT NULL
);

create table student(


id int primary key,
name varchar(30),
dept_no int,
foreign key(dept_no) references department(dep_id)
);

insert into department values (1, 'computer');


insert into department values (2, 'chemistry');
insert into department values (3, 'biotech');

select * from department;

select * from student;

insert into student values (1, 'sumit',1);


insert into student values (2, 'diptesh',1);
insert into student values (3, 'abujar',1)

insert into student values (4, 'aakash',2);


insert into student values (5, 'narendra',2);

insert into student values (6, 'roshan',3);


insert into student values (7, 'tushar',3);
insert into student values (8, 'vivek',3);

create VIEW STUD_VIEW AS


SELECT id,name from student

SELECT s.id, s.name, d.dep_name from student s, department d


where s.dept_no = d.dep_id;

select * from student where dept_no=1;


select * from department where dep_id=1;

select * from student cross join department;

select student.name, department.dep_name


from student inner join department
on department.dep_id = student.dept_no;

select department.dep_name, student.name


from student left outer join department
on department.dep_id = student.dept_no;

select student.name, department.dep_name


from student right outer join department
on department.dep_id = student.dept_no;

select department.dep_id, department.dep_name,


student.id, student.name, student.dept_no
from department full outer join student
on department.dep_id = student.dept_no;

create table customer(


cust_no int primary key,
name varchar(50) not null,
city varchar(50) not null
);

insert into customer values


(1,'sumit','keyboard'),
(2,'narendra','mouse'),
(3,'aakash','monitor'),
(4,'diptesh','monitor');

select * from customer;

select name,item from customer where item='monitor';

select name,city from customer where


item != (select item from customer where name='sumit')

select name from student


where student.name = (select department.dep_name from department
where department.dep_id = student.dept_no);

select name from customer


where customer.name = (select name from student where name = 'aakash');

You might also like