0% found this document useful (0 votes)
65 views2 pages

Essential SQL Questions and Queries

sql

Uploaded by

cfs.hodcsnip
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)
65 views2 pages

Essential SQL Questions and Queries

sql

Uploaded by

cfs.hodcsnip
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
  • SQL Questions Part 1
  • SQL Questions Part 2

SQL Questions

1. In SQL, which command will be used to add a new record in a table?

(A) UPDATE (B) ADD (C) INSERT (D) ALTER TABLE

2. Mr. Atharva is given a task to create a database, Admin. He has to create a table, users in the

database with the following columns:

User_id - int

User_name - varchar(20)

Password - varchar(10)

Help him by writing SQL queries for both tasks.

3. Ms. Rita is a database administrator at a school. She is working on the table, student containing

the columns like Stud_id, Name, Class, and Stream. She has been asked by the Principal to strike

off the record of a student named Rahul with student_id as 100 from the school records and add

another student with the following details:

Stud_id - 123

Name - Rajeev

Class - 12

Stream - Science

Help her by writing SQL queries for both tasks.

4. Consider the table Stationery and write the output of the following SQL queries:

(i) SELECT DISTRIBUTOR, SUM(QTY) FROM STATIONERY GROUP BY DISTRIBUTOR;

(ii) SELECT ITEMNO, ITEM FROM STATIONERY WHERE DISTRIBUTOR = 'Classic Plastics'

AND PRICE > 10;

(iii) SELECT ITEM, QTY * PRICE AS 'AMOUNT' FROM STATIONERY WHERE ITEMNO = 402;
5. Based on the table Rent_cab:

(i) Add a primary key to a column name Vcode.

(ii) Increase the charges of all the cabs by 10%.

(iii) Delete all the cabs whose maker name is 'Carus'.

6. Consider the tables GAMES and PLAYERS:

(i) Display the game type and average number of games played in each type.

(ii) Display prize money, name of the game, and name of the players from the tables Games and

Players.

(iii) Display the types of games without repetition.

(iv) Display the name of the game and prize money of those games whose prize money is known.

Common questions

Powered by AI

To remove a student record with Stud_id 100, the query is 'DELETE FROM student WHERE Stud_id = 100;'. To add a new student, Rajeev, the query is 'INSERT INTO student (Stud_id, Name, Class, Stream) VALUES (123, 'Rajeev', 12, 'Science');'.

To calculate the value, the query is 'SELECT ITEM, QTY * PRICE AS 'AMOUNT' FROM STATIONERY WHERE ITEMNO = 402;'. This multiplies QTY by PRICE for the item with ITEMNO 402.

Use the query 'SELECT prize_money, game_name, player_name FROM GAMES INNER JOIN PLAYERS ON GAMES.game_id = PLAYERS.game_id;'. This joins both tables on shared game IDs.

To make Vcode a primary key, use 'ALTER TABLE Rent_cab ADD PRIMARY KEY (Vcode);'. To increase charges by 10%, use 'UPDATE Rent_cab SET charges = charges * 1.1;'.

The query is 'SELECT ITEMNO, ITEM FROM STATIONERY WHERE DISTRIBUTOR = 'Classic Plastics' AND PRICE > 10;'. This command filters the Stationery table for items meeting both specified conditions.

The query is 'SELECT game_name, prize_money FROM GAMES WHERE prize_money IS NOT NULL;'. This filters for games with known prize money.

The SQL query to calculate the total quantity of items grouped by distributor is 'SELECT DISTRIBUTOR, SUM(QTY) FROM STATIONERY GROUP BY DISTRIBUTOR;'.

The query to delete entries is 'DELETE FROM Rent_cab WHERE maker = 'Carus';'. This statement removes all cabs whose maker is 'Carus'.

To create a database named Admin, the SQL query is 'CREATE DATABASE Admin;'. To create a table named users with columns User_id (int), User_name (varchar(20)), and Password (varchar(10)), the query is 'CREATE TABLE users (User_id INT, User_name VARCHAR(20), Password VARCHAR(10));'.

To display average games played, use 'SELECT game_type, AVG(num_of_games) FROM GAMES GROUP BY game_type;'. For unique types, use 'SELECT DISTINCT type FROM GAMES;'.

SQL Questions
1. In SQL, which command will be used to add a new record in a table?
   (A) UPDATE  (B) ADD  (C) INSERT  (D) A
5. Based on the table Rent_cab:
   (i) Add a primary key to a column name Vcode.
   (ii) Increase the charges of all the cabs

You might also like