You are on page 1of 3

MySQL Basic Commands

Simple Queries

1. show databases;
2. create database School12;
3. show databases;
4. use School12;

5. create table Student(


Rno int primary key,
Name varchar(25) NOT NULL,
Gender varchar(6),
Marks int,
Scode varchar(4)
);
6. desc Student;

7.
insert into Student value(1, “Shubham”, “Male”, 89, “S101”);
insert into Student value(2, “Sarnendu”, “Male”, 76, “S103”);
insert into Student value(3, “Sneha”, “Female”, 68, “S101”);
insert into Student value(4, “Sukalpo”, “Male”, 82, “S102”);
insert into Student value(5, “Ahana”, “Female”, 86, “S103”);
insert into Student value(6, “Aniket”, “Male”, 94, “S101”);
insert into Student value(7, “Subhra”, “Female”, 48, “S102”);
insert into Student value(8, “Dona”, “Female”, 63, “S103”);
insert into Student value(9, “Adrija”, “Female”, 76, “S102”);
insert into Student value(10, “Rohit”, “Male”, 41, “S101”);
8. Select * from Student;

9. Select * from Student where Scode= “S101”;


10. Select Name from Student where Marks between 50 and 80;
11. Select * from Student;

12. Alter table Student add column(Contact varchar(11), Address varchar(20));


13. Select * from Student;
14. desc Student;

15. Alter table Student drop Contact;


16. Select * from Student;
17. desc Student;
18. Alter table Student modify Marks decimal;
19. desc Student;

20. Select * from Student;


21.
update Student set Address= “Shyamnagar” where Rno= 1;
update Student set Address= “Barrackpore” where Rno= 2;
update Student set Address= “Kalyani” where Rno= 3;
update Student set Address= “Naihati” where Rno= 4;
update Student set Address= “Shyamnagar” where Rno= 5;
update Student set Address= “Kankinara” where Rno= 6;
update Student set Address= “Khardah” where Rno= 7;
update Student set Address= “Barrackpore” where Rno= 8;
update Student set Address= “Naihati” where Rno= 9;
update Student set Address= “Sealdah” where Rno= 10;
22. Select * from Student;

23. Select * from Student order by Name;


24. Select * from Student order by Name desc;
25. Select Name, Marks from Student Order by Marks desc;

26. Select * from Student;


27. delete from Student where Rno= 6;
28. Select * from Student;

29. Select Gender, count(*) from Student group by Gender;


30. Select * from Student;

31. Select max(Marks) from Student;


32. Select min(Marks) from Student;
33. Select avg(Marks) from Student;
34. Select sum(Marks) from Student;
35. create table Stream(
Scode varchar(5) primary key,
SName varchar(15)
);
36. desc Stream;

37.
insert into Stream values(“S101”, “Science”);
insert into Stream values(“S102”, “Commerce”);
insert into Stream values(“S103”, “Humanities”);
38. Select * from Stream;

39. Select * from Student;


40. Select * from Student, Stream;

41. Select Name, SName from Student, Stream where Student.Scode=


Stream.Scode;
42. Select Name, SName from Student, Stream where Student.Scode= Stream.Scode
and Name= “Sukalpo”;
43. Select Name, Marks, SName from Student, Stream where Student.Scode=
Stream.Scode and Marks<= 50;

You might also like