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

DBMS Query Questions

The document outlines SQL queries for managing a Customer and Purchase database. It includes creating tables, inserting records, updating values, deleting records, and displaying data based on various conditions. The queries cover operations such as filtering, sorting, and calculating derived values like tax and discount.

Uploaded by

hilalayzha8
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)
7 views5 pages

DBMS Query Questions

The document outlines SQL queries for managing a Customer and Purchase database. It includes creating tables, inserting records, updating values, deleting records, and displaying data based on various conditions. The queries cover operations such as filtering, sorting, and calculating derived values like tax and discount.

Uploaded by

hilalayzha8
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

DBMS QUERIES

1. Create the following table Customer with the given constraints.


Field Name Datatype Size Constraint
CustomerId Integer 4 Primary Key
Customername Varchar 12
Amountdue Integer 6
Datejoin Date
Place Varchar 15
2. Add 2 records into customer table.
3. Display the records with amountdue in the range 5000 – 10000.
4. Display the records customername wise.
5. Display the records in the descending order of datejoin.
6. Increase the amountdue by 1000 for customers from Dubai.
7. Display the records with datejoin after 1st January 2022 and
amountdue below 8000.
8. Decrease the amountdue by 2% for the customers from Ajman.
9. Delete the records with amountdue below 900.
10. Add a new column Category with the datatype varchar
and size 10.
11. Fill the column Category with VIP for all records.
12. Remove the column Place from the table.
13. Display customername, amountdue and tax. Calculate tax
as 2% of amountdue.
14. Consider the following Purchase table and answer the
queries.
Device_ID Device_Name Category Price Qty
D1 Mouse I 800 25
D2 Wifi-router NW 2000 12
D3 Printer O 17000 10
D4 Keyboard I 1200 30
D4 Modem NW 9000 15
a. Create the table Purchase.
Assuming that some records are already existing in the table:
b. Display the records in the descending order of price.
c. Display the records with Qty between 15 and 30.
d. Display name and price of devices with category O.
e. Decrease the price by 3% for devices with category NW.
f. Display Device_ID, Price and Discount. Calculate discount as
5% of price.
g. Increase the qty by 10 for devices with price below 1500.
h. Add a new record with values “D5”, “Scanner”, “I”, 5000, 8.

1. Create the Customer table with constraints:

CREATE TABLE Customer (


CustomerId INTEGER PRIMARY KEY,
Customername VARCHAR(12),
Amountdue INTEGER(6),
Datejoin DATE,
Place VARCHAR(15)
);

2. Insert 2 records into the Customer table(here added 4


records)

INSERT INTO Customer


VALUES (101, 'John', 7500, '2023-03-15', 'Dubai');
INSERT INTO Customer
VALUES (201, 'Alice', 5500, '2022-01-01', 'Ajman');
INSERT INTO Customer
VALUES ( 301,'Anu', 10000, '2023-08-10', 'Sharjah');
INSERT INTO Customer
VALUES (401, 'Nila', 7000, '2023-08-10', 'UAQ');
Select *from customer;

3. Display records with Amountdue in the range 5000-10000:

SELECT * FROM Customer


WHERE Amountdue BETWEEN 5000 AND 10000;
4. Display records sorted by Customername

SELECT * FROM Customer

ORDER BY Customername;

5. Display records in descending order of Datejoin:

SELECT * FROM Customer


ORDER BY Datejoin DESC;

6. Increase the Amountdue by 1000 for customers from Dubai:

UPDATE Customer
SET Amountdue = Amountdue + 1000
WHERE Place = 'Dubai';

7. Display records where Datejoin is after 1st January 2022 and


Amountdue is below 8000:

SELECT * FROM Customer


WHERE Datejoin > '2022-01-01' AND Amountdue < 8000;

8. Decrease Amountdue by 2% for customers from Ajman:

sql
Copy code
UPDATE Customer
SET Amountdue = Amountdue -0.02
WHERE Place = 'Ajman';

9. Delete records where Amountdue is below 900:

sql
Copy code
DELETE FROM Customer
WHERE Amountdue < 900;

10. Add a new column Category with datatype varchar(10):

sql
ALTER TABLE Customer
ADD Category VARCHAR(10);

11. Fill the Category column with 'VIP' for all records:

UPDATE Customer
SET Category = 'VIP' ;

12. Remove the Place column from the Customer table:

ALTER TABLE Customer


DROP COLUMN Place;

13. Display Customername, Amountdue, and calculate tax


(2% of Amountdue):

sql
Copy code
SELECT Customername, Amountdue, (Amountdue * 0.02) AS Tax
FROM Customer;

14)

a. Create the Purchase table:

CREATE TABLE Purchase (


Device_ID VARCHAR(5) PRIMARY KEY,
Device_Name VARCHAR(20),
Category CHAR(2),
Price INT,
Qty INT
);

b. Display the records in the descending order of Price:

SELECT * FROM Purchase


ORDER BY Price DESC;

c. Display the records with Qty between 15 and 30:


SELECT * FROM Purchase
WHERE Qty BETWEEN 15 AND 30;

d. Display the Device_Name and Price of devices with Category =


'O':

SELECT Device_Name, Price FROM Purchase


WHERE Category = 'O';

e. Decrease the Price by 3% for devices with Category = 'NW':

UPDATE Purchase
SET Price = Price * 0.03
WHERE Category = 'NW';

f. Display Device_ID, Price, and calculate Discount (5% of Price):

SELECT Device_ID, Price, (Price * 0.05) AS Discount


FROM Purchase;

g. Increase the Qty by 10 for devices with Price below 1500:

UPDATE Purchase
SET Qty = Qty + 10
WHERE Price < 1500;

h. Add a new record with values "D5", "Scanner", "I", 5000, 8:

INSERT INTO Purchase


VALUES ('D5', 'Scanner', 'I', 5000, 8);

You might also like