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

All Commands

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)
6 views4 pages

All Commands

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/ 4

1.

Show databases;

2.create database ajb;

3. Use ajb;

4.drop database ajb;

5. create table T1 (Roll_No int, Name varchar(20), Class int, Section


char(1), Date_Of_Admission date, Total_Marks int);

6. To display table structure---→ desc T1; or describe T1;

7. To insert record ---

Insert into T1 values (2, ‘Zina’, 10, ‘B’,’2014-01-18’ ,360),

(3, ‘Vinay’, 10, ‘C’,’2014-01-18’ ,420),

(4, ‘Dina’, 10, ‘A’,’2014-01-18’ ,461),

(5, ‘Diya’, 10, ‘B’,’2014-01-18’ ,490),

(6, ‘Chandan’, 10, ‘A’,’2014-01-18’ ,390),

(7, ‘Mayank’, 10, ‘C’,’2014-01-18’ ,450),

(8, ‘Fiona’, 10, ‘C’,’2014-01-18’ ,380);

8. To see the records --→ select *from T1;

9. To add new column at the end -→ Alter table T1 add Grade Char(2);

10. To add new column at a specific location -→Alter table T1 add


Percentage float(3,2) after Total_Marks;

11.To modify existing column or to change the data type → Alter table
T1 modify Name char(30);
12. To modify the data type of an existing column and shift it to a
specific location→

Alter table T1 modify Grade char(1) after Total_Marks;

13. To modify the data type of an existing column and shift it to first
position -→

Alter table T1 modify Percentage float(2,2) first;

14. To rename an existing column --→

Alter table T1 change Section Sec varchar(4) ;

15. To rename an existing column and shift it to a specific position→

Alter table T1 change Name StdName varchar(40) after Sec ;

16. To rename an existing column and shift it to the first position→

Alter table T1 change StdName Name varchar(30) first ;

17. To drop/delete a column→ Alter table T1 drop Percentage;

18. To rename a table→ Alter table T1 rename TT;

19. To drop/delete/destroy a table → drop table TT;

20. To add primary key constraints →

Alter table TT add primary key(Roll_No);

21. To delete primary key constraints →

Alter table TT drop primary key;

22. To select selected columns and all rows →

select Roll_No, Name from TT;


23. To select selected rows and all columns →select *from TT where
Sec=’C’;

24. To select selected columns and selected rows →select Roll_No,


Name from TT where Sec=’C’;

25. To eliminate duplicate values → select distinct Sec from TT;

26. To retrieving all values → select all Sec from TT;

27. To find a match for any string of any length :→ select *from TT
where Name like ‘D%’;

Or

select *from TT where Name like ‘%a’;

28. To find a match for any single character :→ select *from TT where
Name like ‘C______’;

29. To search record between a range:→ select *from TT where


Total_Marks between 360 and 461;

30. To perform calculation:→ select Roll_No, Name,


Total_Marks/500*100 from TT;

31. To search records based on condition:→select *from TT where


Total_Marks<=400;

32. Use of logical operator AND:→ select *from TT where


Total_Marks> 360 and Total_marks< 461;

33. Use of logical operator OR:→ select *from TT where Sec=’A’ or


Sec=’C’;

34. Use of logical operator NOT:→ select *from TT where Not(Sec=’A’);


35. Sorting of data in ascending order using order by clause:→

select *from TT order by Name;

36. Sorting of data in descending order using order by clause:→

select *from TT order by Roll_No desc;

37. To delete specific row:→

Delete from TT where Sec=’A’;

38. To delete all rows:→ Delete from TT;

39. To update data in a table:→

Update TT set Name=’Anita’ where Sec=’C’;

40. To find sum, average, maximum and minimum value of


Total_Marks:→

Select sum(Total_Marks), avg(Total_Marks), max(Total_Marks),

Min(Total_Marks) from TT;

41. To count the no. of records:→

Select count(*) from TT where Name=’Anita’;

42. To count the no. of values in a column:→

Select count(Roll_No) from TT;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy