0% found this document useful (0 votes)
6 views3 pages

DBMS 2nd, 3rd, 4th, Practical

The document outlines a series of SQL commands for database management, including Data Definition Language (DDL) and Data Manipulation Language (DML) operations. It demonstrates creating databases and tables, inserting and updating records, and performing joins between tables. Additionally, it covers creating views and indexes, as well as executing various queries to retrieve and manipulate data.

Uploaded by

kartikahire656
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

DBMS 2nd, 3rd, 4th, Practical

The document outlines a series of SQL commands for database management, including Data Definition Language (DDL) and Data Manipulation Language (DML) operations. It demonstrates creating databases and tables, inserting and updating records, and performing joins between tables. Additionally, it covers creating views and indexes, as well as executing various queries to retrieve and manipulate data.

Uploaded by

kartikahire656
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

DBMS 2nd, 3rd, 4th, practical

SQL DDL:

show databases;
create database employee;
use employee;
create table emp_details(emp_no int(10),emp_name varchar(30),emp_gender
varchar(1),emp_sal int(30));
show tables;
alter table emp_details add emp_dept varchar(20);
desc emp_details;
insert into emp_details values(1,'Ram','M',300000,'designing');
insert into emp_details values(2,'Soham','M',300000,'designing');
insert into emp_details values(3,'Mohan','M',250000,'management');
insert into emp_details values(4,'Om','M',400000,'coding');
select * from emp_details;
create table emp_info as select emp_no,emp_name,emp_gender from emp_details;
select * from emp_info;
truncate table emp_info;
select * from emp_info;
drop table emp_info;
select * from emp_info;
create view emp_view1 as select * from emp_details;
create view emp_view2 as select * from emp_details where emp_dept="designing";
select * from emp_view1;
select * from emp_view2;
update emp_details set emp_dept="coding" where emp_name="Mohan";
select * from emp_details;
drop view emp_view1;
drop view emp_view2;
create index emp_ind on emp_details(emp_no,emp_name);
show index from emp_details;

-----------------------------------------------------------------------------------
------------------------

SQL DML:

show databases;
create database student;
use student;
create table stud_tab(stud_id int(4),stud_name varchar(20),stud_dept
varchar(10),stud_dob date,stud_address varchar(10));
desc stud_tab;
insert into stud_tab values(1,'Ram','Comp','2002-11-05','Pune');
insert into stud_tab values(2,'Soham','IT','2002-09-03','Nashik');
insert into stud_tab values(3,'Ramesh','Comp','2002-03-19','Pune');
insert into stud_tab values(4,'Mohan','AI&DS','2002-02-22','Nagpur');
select * from stud_tab;
alter table stud_tab add shift varchar(10);
update stud_tab set shift='first' where stud_id=1;
update stud_tab set shift='second' where stud_id=2;
update stud_tab set shift='first' where stud_id=3;
update stud_tab set shift='first' where stud_id=4;
select * from stud_tab;
insert into stud_tab values(5,'Omkar','ENTC','2002-06-26','Pune','second');
select * from stud_tab;
delete from stud_tab where stud_address='Nagpur';
select * from stud_tab;
update stud_tab set stud_id=4 where stud_name='Omkar';
select * from stud_tab;
select * from stud_tab where stud_dob between '2002-01-01' and '2002-07-01';
alter table stud_tab add stud_fees int(15);
update stud_tab set stud_fees=15000 where stud_id=1;
update stud_tab set stud_fees=20000 where stud_id=2;
update stud_tab set stud_fees=20000 where stud_id=3;
update stud_tab set stud_fees=15000 where stud_id=4;
select * from stud_tab;
select * from stud_tab where stud_fees=(select max(stud_fees) from stud_tab);
select sum(stud_fees) from stud_tab;
create table stud_info as select stud_id,stud_name from stud_tab;
select stud_id from stud_tab union select stud_id from stud_info;

-----------------------------------------------------------------------------------
--

SQL joins:

show databases;
create database customer;
show databases;
use customer;
create table cust_tab(id int(4),name varchar(20),quantity int(4),price int(10),item
varchar(20));
show tables;
create table cust_info(id int(4),name varchar(20),address varchar(20),mobile
varchar(20));
desc cust_tab;
desc cust_info;
alter table cust_tab add primary key(id);
alter table cust_info add foreign key(id) references cust_tab(id);
insert into cust_tab values(1,'Ram',1,15,'Milk');
insert into cust_tab values(2,'Soham',2,20,'Toast');
insert into cust_tab values(3,'Mohan',4,5,'Parle-G');
insert into cust_tab values(4,'Om',2,20,'Coca Cola');
select * from cust_tab;
alter table cust_tab add totalprice int(4);
update cust_tab set totalprice=quantity*price where id=1;
update cust_tab set totalprice=quantity*price where id=2;
update cust_tab set totalprice=quantity*price where id=3;
update cust_tab set totalprice=quantity*price where id=4;
select * from cust_tab;
insert into cust_info values(1,'Ram','Pune','9943569081');
insert into cust_info values(2,'Soham','Pune','9978491281');
insert into cust_info values(3,'Mohan','Nashik','8782356712');
insert into cust_info values(4,'Om','Nagpur','7823450189');
select * from cust_info;
select cust_tab.id,cust_tab.name,cust_tab.item,cust_info.address from cust_tab
inner join cust_info on cust_tab.id=cust_info.id;
select cust_tab.id,cust_tab.name,cust_tab.item,cust_info.address from cust_tab left
outer join cust_info on cust_tab.id=cust_info.id;
select cust_tab.id,cust_tab.name,cust_tab.item,cust_info.address from cust_tab
right outer join cust_info on cust_tab.id=cust_info.id;
create view mul_view as select cust_tab.id,cust_tab.name,cust_info.address from
cust_tab,cust_info where cust_info.id=cust_tab.id;
select * from mul_view;

You might also like