0% found this document useful (0 votes)
9 views5 pages

class 11 revision test

The document contains a series of SQL commands to manage a STUDENT table, including creating the table, inserting data, modifying structure, and querying information. It also involves creating a BOYS table based on the STUDENT table and applying various constraints and updates. The commands demonstrate basic SQL operations such as SELECT, INSERT, UPDATE, DELETE, and ALTER TABLE.

Uploaded by

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

class 11 revision test

The document contains a series of SQL commands to manage a STUDENT table, including creating the table, inserting data, modifying structure, and querying information. It also involves creating a BOYS table based on the STUDENT table and applying various constraints and updates. The commands demonstrate basic SQL operations such as SELECT, INSERT, UPDATE, DELETE, and ALTER TABLE.

Uploaded by

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

Type and execute SQL commands to do the following :

1. Create a table STUDENT with the following fields :

Rollno (int), Name (varchar(20)), Gender (char(1)) and Marks (Decimal(4,1))

2. Add the following rows to the table

3. Display the structure of the table

4. Display all tables in the database

5. Display the result of the expression 7+8/3

6. Display details of the male students who have secured less than 90.

7. Display all the details in descending order of marks and in ascending order of Name.

8. Add a new column Grade (char(1)) to the table.

9. Set the Grade as ‘A’ for those students whose mark is above 90.

10. Display the names of the students who do not have a grade.

11. Delete the students whose mark is below 80.

12. Change name to “Anitha” and marks to 89.0 of the student whose roll number is 2.

13. Modify the data type of column Name to varchar(30)

14. Delete the column Grade.

15. Display roll number, name and marks of the students whose roll number is 2 and 4

16. Display name and marks-3 for all students.

17. Display the student details in the following format Deepa ‘has secured’ 86.5

18. Display names of the students having five letters and ending with ‘a’

19. Add a new row with Rollno =10 , name=’Shakthi’ and Gender=’M’

20. Display names of the students whose marks are entered in the table.

21. Create a table BOYS which will have name and marks of all the boys from STUDENT table.

22. Display the contents of BOYS table.


23. Add a PRIMARY KEY data constraint on the column Name.

24. Change Name column in BOYS table to B_NAME.


-- 1. Create a table STUDENT

CREATE TABLE STUDENT (

Rollno INT,

Name VARCHAR(20),

Gender CHAR(1),

Marks DECIMAL(4,1)

);

-- 2. Add the following rows to the table

INSERT INTO STUDENT (Rollno, Name, Gender, Marks) VALUES

(1, 'Rahul', 'M', 92.5),

(2, 'Anitha', 'F', 85.0),

(3, 'Deepa', 'F', 88.0),

(4, 'Karan', 'M', 75.5);

-- 3. Display the structure of the table

DESCRIBE STUDENT;

-- 4. Display all tables in the database

SHOW TABLES;

-- 5. Display the result of the expression 7+8/3

SELECT 7 + 8 / 3 AS result;

-- 6. Display details of the male students who have secured less than 90.

SELECT * FROM STUDENT WHERE Gender = 'M' AND Marks < 90;

-- 7. Display all the details in descending order of marks and in ascending order of Name.

SELECT * FROM STUDENT ORDER BY Marks DESC, Name ASC;


-- 8. Add a new column Grade to the table.

ALTER TABLE STUDENT ADD Grade CHAR(1);

-- 9. Set the Grade as ‘A’ for those students whose mark is above 90.

UPDATE STUDENT SET Grade = 'A' WHERE Marks > 90;

-- 10. Display the names of the students who do not have a grade.

SELECT Name FROM STUDENT WHERE Grade IS NULL;

-- 11. Delete the students whose mark is below 80.

DELETE FROM STUDENT WHERE Marks < 80;

-- 12. Change name to “Anitha” and marks to 89.0 of the student whose roll number is 2.

UPDATE STUDENT SET Name = 'Anitha', Marks = 89.0 WHERE Rollno = 2;

-- 13. Modify the data type of column Name to varchar(30).

ALTER TABLE STUDENT MODIFY Name VARCHAR(30);

-- 14. Delete the column Grade.

ALTER TABLE STUDENT DROP COLUMN Grade;

-- 15. Display roll number, name and marks of the students whose roll number is 2 and 4.

SELECT Rollno, Name, Marks FROM STUDENT WHERE Rollno IN (2, 4);

-- 16. Display name and marks-3 for all students.

SELECT Name, Marks - 3 AS Adjusted_Marks FROM STUDENT;

-- 17. Display the student details in the following format: Deepa ‘has secured’ 86.5

SELECT CONCAT(Name, ' has secured ', Marks) AS Details FROM STUDENT;

-- 18. Display names of the students having five letters and ending with ‘a’.
SELECT Name FROM STUDENT WHERE Name LIKE '____a';

-- 19. Add a new row with Rollno =10 , name=’Shakthi’ and Gender=’M’.

INSERT INTO STUDENT (Rollno, Name, Gender, Marks) VALUES (10, 'Shakthi', 'M', NULL);

-- 20. Display names of the students whose marks are entered in the table.

SELECT Name FROM STUDENT WHERE Marks IS NOT NULL;

-- 21. Create a table BOYS which will have name and marks of all the boys from STUDENT table.

CREATE TABLE BOYS AS SELECT Name, Marks FROM STUDENT WHERE Gender = 'M';

-- 22. Display the contents of BOYS table.

SELECT * FROM BOYS;

-- 23. Add a PRIMARY KEY data constraint on the column Name.

ALTER TABLE BOYS ADD PRIMARY KEY (Name);

-- 24. Change Name column in BOYS table to B_NAME.

ALTER TABLE BOYS CHANGE Name B_NAME VARCHAR(20);

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