Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
68 views4 pages

Xii-Ip-Sql Commands (Practice)

This document contains 30 SQL commands related to creating and managing databases and tables, inserting and modifying data, joining tables, and retrieving data using clauses like WHERE, GROUP BY, HAVING, and ORDER BY. It includes commands for creating databases and tables, inserting sample data, selecting data through queries, updating and deleting data, adding/dropping columns and primary keys, and joining two tables.

Uploaded by

P R A G Z
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)
68 views4 pages

Xii-Ip-Sql Commands (Practice)

This document contains 30 SQL commands related to creating and managing databases and tables, inserting and modifying data, joining tables, and retrieving data using clauses like WHERE, GROUP BY, HAVING, and ORDER BY. It includes commands for creating databases and tables, inserting sample data, selecting data through queries, updating and deleting data, adding/dropping columns and primary keys, and joining two tables.

Uploaded by

P R A G Z
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/ 4

SQL COMMANDS(PRACTICALS)-30[THIRTY]-QUERIES-TERM-II

1) COMMAND FOR CREATING A DATABASE:-

create database students;

2) COMMAND FOR USING THE(OPEN)DATABASE:-

use students;

3) COMMAND FOR CREATING TABLE:-

create table student(admno int,name varchar(30),class int,sec char,rno int,address


varchar(30));

4) COMMAND FOR SHOWING THE STRUCTURE OF TABLE:-

describe student;

5) COMMAND TO SHOW TABLES PRESENT IN DATABASE:-

show tables;

6) COMMAND FOR INSERTING DATA INTO A TABLE:-

insert into student values(1234,"Aditi sharma",9,"A",4,"SJE nagar");


insert into student values(2605,"Shreya nagpal",10,"D",7,"Jor baghpuram");
insert into student values(3712,"Tanya verma",11,"C",21,"Malviya nagar");
insert into student values(5612,"Krish gupta",12,"B",15,"Janak puri");
insert into student values(6523,"Zayn malik",11,"E",40,"Rohini nagar");
insert into student values(4031,"Shivani mehta",9,"A",33,"Hauz khaspuram");

7) COMMAND TO VIEW THE CONTENTS OF THE TABLE:-

select*from student;

8) COMMAND TO RETRIEVE DATA:-

select name,class from student;

9) COMMAND FOR USING KEYWORD DISTINCT:-

select DISTINCT sec from student;

10) COMMAND FOR USING WHERE CLAUSE:-

select name,class from student WHERE class>9;

11) COMMAND FOR USING ORDER BY CLAUSE:-

select*from student ORDER BY class,name;

12) COMMAND FOR USING UPDATE:-

update student SET class=12 WHERE name="shreya nagpal";


select*from student;

13) COMMAND FOR USING ALTER(TO MODIFY STRUCTURE OF TABLE):-


alter table student ADD marks int;
select*from student;

14) COMMAND FOR USING LIKE OPERATOR:-

select name,class from student WHERE name like 'S%';

15) COMMAND FOR USING AGGREGATE FUNCTIONS:-

select max(class),min(admno)from student;

16) COMMAND FOR USING GROUP BY:-

select max(class),name from student group by name;

17) COMMAND FOR USING HAVING CLAUSE:-

select avg(admno),class from student group by class HAVING avg(admno)>2000;

18) COMMAND FOR USING GROUP BY WITH ORDER BY CLAUSE:-

select sum(class),sec from student group by class ORDER BY class desc;

update student SET marks=498 WHERE name="Aditi sharma";


update student SET marks=400 WHERE name="Shreya nagpal";
update student SET marks=350 WHERE name="Tanya verma";
update student SET marks=320 WHERE name="Krish gupta";
update student SET marks=300 WHERE name="Zayn malik";
update student SET marks=298 WHERE name="Shivani mehta";

select*from student;

19) COMMAND FOR USING GROUP BY AND HAVING CLAUSE WITH WHERE CLAUSE:-
select avg(marks),name,class from student WHERE class in(9,12) GROUP BY name having
avg(marks)<2000;

create table sports(admno int,game varchar(20),coach_name varchar(30),class


int,grade char);

describe sports;

insert into sports values(1234,"cricket","Narendra",9,"A");


insert into sports values(2605,"volley ball","Priyanka",10,"D");
insert into sports values(3712,"cricket","SK Singh",11,"C");
insert into sports values(5612,"Basket ball","Priyanka",12,"B");
insert into sports values(6523,"Football","Narendra",11,"E");
insert into sports values(4031,"cricket","SK Singh",9,"A");
select*from sports;

20) COMMAND FOR EQUII-JOIN OF TABLES:-

select*from student,sports WHERE student.admno=sports.admno;

21) COMMAND TO RETRIEVE DATA FROM TWO TABLES:-

select name,grade from student,sports WHERE student.admno=sports.admno and


coach_name="SK Singh";

22) COMMAND FOR USING GROUP BY CLAUSE IN JOIN:-


select avg(marks),grade from student,sports WHERE student.admno=sports.admno GROUP
BY grade;

23) COMMAND FOR USING GROUP BY AND ORDER BY CLAUSE IN EQUII-JOIN:-

select sum(marks),grade from student,sports WHERE student.admno=sports.admno GROUP


BY address ORDER BY sum(marks) desc;

24) COMMAND FOR USING WHERE CLAUSE AND GROUP BY:-

select name,class from student WHERE marks>10 GROUP BY class;

25) COMMAND FOR ADDING PRIMARY KEY:-

alter table student ADD primary key(admno);


select*from student;

26) COMMAND TO DELETE A COLUMN:-

alter table student drop rno;

27) COMMAND TO REMOVE PRIMARY KEY:-

alter table student drop primary key;

28) COMMAND TO INCREASE MARKS:-

update student SET marks=marks+10;


select*from student;

29) COMMAND TO CHANGE DATA TYPE OF AN EXISTING COLUMN:-

alter table student modify marks decimel(8,2);


select*from student;

30) COMMAND TO DELETE A TABLE:-

drop table sports;


show tables;

COMMIT;

You might also like