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

Assignment1 Solution

Uploaded by

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

Assignment1 Solution

Uploaded by

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

Assignment : 6_1

1.Table name student1: (Perform DDL AND DML command)


Columns : Student_id, student_name, student_age, student_std
5 rows data :

Answer 1:
show databases;
use rahul1;
create table student1 (
student_id int(10) not null,
student_name varchar(20),
student_age int(10),
student_std int(10)
);
describe student1;
select* from student1;
insert into student1(
student_id, student_name, student_age, student_std)
values(100,"Rahul",26,12);
select* from student1;
insert into student1
values(101,"Ram",25,12),(102,"Ranjan",23,10),
(103,"Ruhi",21,11),(104,"Ruchi",20,08);
select* from student1;
-- DDL and DML commands (create, alter, drop, truncate, rename,
insert, update, delete)
Alter table student1 add column student_contact int(10);
select* from student1;
Alter table student1 rename column student_contact to
student_mob;
select* from student1;
commit;
truncate table student1;
select* from student1;
-- DML commands
insert into student1
values(101,"Ram",25,12,98765438), (102,"Ranjan",23,10,98473216),
(103,"Ruhi",21,11,89764215), (104,"Ruchi",20,08,63157895);
select*from student1;
update student1
set student_mob = 56437853
where student_id = 101;
select*from student1;
delete from student1
where student_id = 104;
select*from student1;
delete from student1
where student_id in (102,103);
select*from student1;
drop table student1;
select*from student1;
rollback;
select*from student1;

2. Table name customer1:( Perform TCL command)


Columns : c_id, c_name, c_age, c_billamount
5 rows data:
use rahulsaini;

create table custmor (


c_id int(10),
c_name varchar(20),
c_age int(10),
c_billamount int(10)
);
select*from custmor;
insert into custmor
values(101,"Ram",25,22000),(102,"Ranjan",23,25900),
(103,"Ruhi",21,11000),(104,"Ruchi",20,24000),
(105,"Rohit",24,20000);
select*from custmor;
commit;
insert into custmor
values(106,"Raman",26,27000);
select*from custmor;

delete from custmor


where c_id = 105;
select*from custmor;

rollback;
select*from custmor;
commit;
insert into custmor
values(106,"Raman",26,27000);
select*from custmor;

savepoint rahul;
select*from custmor;

delete from custmor


where c_id = 105;
select*from custmor;
rollback to rahul;
select*from custmor;
3. Table name student_details:( Perform primary key)
Columns : Student_id, student_name, student_age, student_std
5 rows data :
use rahul1;
create table student3 (
student_id int(10) not null,
student_name varchar(20),
student_age int(10),
student_std int(10),
primary key(student_id)
);
describe student3;
select* from student3;
insert into student3(
student_id, student_name, student_age, student_std)
values(100,"Rahul",26,12),(101,"Ram",25,12),
(102,"Ranjan",23,10),(103,"Ruhi",21,11),
(104,"Ruchi",20,08);
select* from student3;

insert into student3


values(101,"Ram",25,12);
select* from student3;
insert into student3
values(105,"Ram",25,12);
select* from student3;
drop table student3;
select* from student3;

4. Table name student_info:( Perform foreign key)


Columns : Student_id, student_name, student_age, student_city1
5 rows data:
Table name city_info:
Columns: city_id, student_city
5 rows data:
use rahul1;
create table city_info(
city_id int(10),
student_city varchar(20),
primary key(city_id)
);

select * from city_info;


describe city_info;

INSERT INTO city_info Values(1,"mumbai"),(2,"delhi"),(3,"kolkata"),


(4,"bangalore"),(5,"chennai"),(6,"hyderabad");
select * from city_info;

create table student_info(


student_id int(10),
student_name varchar(10),
student_age int(10),
student_city1 int(10),
primary key(student_id),
foreign key(student_city1) references city_info(city_id)
);
Select * from student_info;

INSERT INTO student_info


Values(101," Ajay ",18,5),
(102," Rohit ",16,4),
(103," Akash ",17,2),
(104," Rahul ",16,2),
(105," Vijay ",19,1),
(106," Rohit ",14,3);
Select * from student_info;
select * from city_info;
SELECT * FROM student_info JOIN city_info
ON student_info.student_city1= city_info.city_id;
SELECT * FROM city_info JOIN student_info
ON city_info.city_id = student_info.student_city1;

You might also like