You are on page 1of 24

4. To increase the cost of all the models in Model table by 7.

Update Model set Cost=Cost+7;

-- Create a new database (if not exists)

CREATE DATABASE IF NOT EXISTS YourDatabaseName;

-- Switch to the new database

USE YourDatabaseName;

-- Create the Model table (if not exists)

CREATE TABLE IF NOT EXISTS Model (

ModelID INT PRIMARY KEY,

ModelName VARCHAR(255) NOT NULL,

Cost DECIMAL(10, 2) NOT NULL

);

UPDATE Model

SET Cost = Cost + 7;


5. To display the ConsumerName and City of all Hyderabad and Bangalore in consumer table.

-- Create a new database (if not exists)

CREATE DATABASE IF NOT EXISTS YourDatabaseName;

-- Switch to the new database

USE YourDatabaseName;

-- Create the Consumer table (if not exists)

CREATE TABLE IF NOT EXISTS Consumer (

ConsumerID INT PRIMARY KEY,

ConsumerName VARCHAR(255) NOT NULL,

City VARCHAR(100) NOT NULL

);

-- Display ConsumerName and City of consumers in Hyderabad and Bangalore

SELECT ConsumerName, City

FROM Consumer

WHERE City = 'Hyderabad' OR City = 'Bangalore';


6. Add the price of all the items in Items table by 5.

Update Items set Price=Price+5;

-- Create a new database (if not exists)

CREATE DATABASE IF NOT EXISTS YourDatabaseName;

-- Switch to the new database

USE YourDatabaseName;

-- Create the Items table (if not exists)

CREATE TABLE IF NOT EXISTS Items (

ItemID INT PRIMARY KEY,

ItemName VARCHAR(255) NOT NULL,

Price DECIMAL(10, 2) NOT NULL

);

-- Update the Price of all items in the Items table by 5

UPDATE Items

SET Price = Price + 5;


7. To display the ItemName, Maunfacturer, ExpiryDate of all the items that expired on or before '2010-12-31'.

-- Create a new database (if not exists)

CREATE DATABASE IF NOT EXISTS YourDatabaseName;

-- Switch to the new database

USE YourDatabaseName;

-- Create the Items table (if not exists)

CREATE TABLE IF NOT EXISTS Items (

ItemID INT PRIMARY KEY,

ItemName VARCHAR(255) NOT NULL,

Manufacturer VARCHAR(255) NOT NULL,

ExpiryDate DATE NOT NULL

);

-- Display ItemName, Manufacturer, ExpiryDate of items that expired on or before '2010-12-31'

SELECT ItemName, Manufacturer, ExpiryDate

FROM Items

WHERE ExpiryDate <= '2010-12-31';


8. To display the records of the Consumer Table where city begins with letter 'B'. select * from Consumer where City
like "B%" ;

-- Create a new database (if not exists)

CREATE DATABASE IF NOT EXISTS YourDatabaseName;

-- Switch to the new database

USE YourDatabaseName;

-- Create the Consumer table (if not exists)

CREATE TABLE IF NOT EXISTS Consumer (

ConsumerID INT PRIMARY KEY,

ConsumerName VARCHAR(255) NOT NULL,

City VARCHAR(100) NOT NULL

);

-- Display records of Consumer Table where City begins with the letter 'B'

SELECT *

FROM Consumer

WHERE City LIKE 'B%';


9. To display the records from Items table whose name ends with the letter 's'. select * from Items where Name like
"s";

-- Create a new database (if not exists)

CREATE DATABASE IF NOT EXISTS YourDatabaseName;

-- Switch to the new database

USE YourDatabaseName;

-- Create the Items table (if not exists)

CREATE TABLE IF NOT EXISTS Items (

ItemID INT PRIMARY KEY,

ItemName VARCHAR(255) NOT NULL,

Manufacturer VARCHAR(255) NOT NULL,

ExpiryDate DATE NOT NULL

);

-- Display records from Items table whose name ends with the letter 's'

SELECT *

FROM Items

WHERE ItemName LIKE '%s'


10. To display minimum and maximum price of all the items. select min (Price), max(Price) from Items;

-- Create a new database (if not exists)

CREATE DATABASE IF NOT EXISTS YourDatabaseName;

-- Switch to the new database

USE YourDatabaseName;

-- Create the Items table (if not exists)

CREATE TABLE IF NOT EXISTS Items (

ItemID INT PRIMARY KEY,

ItemName VARCHAR(255) NOT NULL,

Price DECIMAL(10, 2) NOT NULL

);

-- Display the minimum and maximum price of all the items

SELECT MIN(Price) AS MinPrice, MAX(Price) AS MaxPrice

FROM Items
11. To display id and SName of all shops located in RK Nagar. select Id, SName from Shop where Area="RK Nagar';

-- Create a new database (if not exists)

CREATE DATABASE IF NOT EXISTS YourDatabaseName;

-- Switch to the new database

USE YourDatabaseName;

-- Create the Shop table (if not exists)

CREATE TABLE IF NOT EXISTS Shop (

Id INT PRIMARY KEY,

SName VARCHAR(255) NOT NULL,

Area VARCHAR(100) NOT NULL

);

-- Display Id and SName of shops located in RK Nagar

SELECT Id, SName

FROM Shop

WHERE Area = 'RK Nagar';


12. To display Name and Price of all the items(Items table) in ascending order of their Name. select Name, Price from
Items order by Name;

-- Create a new database (if not exists)

CREATE DATABASE IF NOT EXISTS YourDatabaseName;

-- Switch to the new database

USE YourDatabaseName;

-- Create the Items table (if not exists)

CREATE TABLE IF NOT EXISTS Items (

ItemID INT PRIMARY KEY,

Name VARCHAR(255) NOT NULL,

Price DECIMAL(10, 2) NOT NULL

);

-- Display Name and Price of all items in ascending order of their Name

SELECT Name, Price

FROM Items

ORDER BY Name;
13. To display PName and Price of all those products whose price is in the range of 15000 and 25000. select PName,
Price from Product where Price between 15000 and 25000;

-- Create a new database (if not exists)

CREATE DATABASE IF NOT EXISTS YourDatabaseName;

-- Switch to the new database

USE YourDatabaseName;

-- Create the Product table (if not exists)

CREATE TABLE IF NOT EXISTS Product (

ProductID INT PRIMARY KEY,

PName VARCHAR(255) NOT NULL,

Price DECIMAL(10, 2) NOT NULL

);

-- Display PName and Price of products in the range of 15000 and 25000

SELECT PName, Price

FROM Product

WHERE Price BETWEEN 15000 AND 25000;


14. To display the price, PName and quantity of those products which have quantity more than 120. select Price,
PName, Quantity from Product where Quantity > 120;

-- Create a new database (if not exists)

CREATE DATABASE IF NOT EXISTS YourDatabaseName;

-- Switch to the new database

USE YourDatabaseName;

-- Create the Product table (if not exists)

CREATE TABLE IF NOT EXISTS Product (

ProductID INT PRIMARY KEY,

PName VARCHAR(255) NOT NULL,

Price DECIMAL(10, 2) NOT NULL,

Quantity INT NOT NULL

);

-- Display Price, PName, and Quantity of products with quantity more than 120

SELECT Price, PName, Quantity

FROM Product

WHERE Quantity > 120;


15. To display the DName of the dealers who are either from Delhi or from Kolkata.

select DName from dealers where City = "Delhi" or City = "Kolkata".

-- Create a new database (if not exists)

CREATE DATABASE IF NOT EXISTS YourDatabaseName;

-- Switch to the new database

USE YourDatabaseName;

-- Create the Dealers table (if not exists)

CREATE TABLE IF NOT EXISTS Dealers (

DealerID INT PRIMARY KEY,

DName VARCHAR(255) NOT NULL,

City VARCHAR(100) NOT NULL

);

-- Display DName of dealers from Delhi or Kolkata

SELECT DName

FROM Dealers

WHERE City = 'Delhi' OR City = 'Kolkata';


16. To display all the records of Product table on the basis of price in descending order. select * from Product order
by Price desc;

-- Create a new database (if not exists)

CREATE DATABASE IF NOT EXISTS YourDatabaseName;

-- Switch to the new database

USE YourDatabaseName;

-- Create the Product table (if not exists)

CREATE TABLE IF NOT EXISTS Product (

ProductID INT PRIMARY KEY,

PName VARCHAR(255) NOT NULL,

Price DECIMAL(10, 2) NOT NULL,

Quantity INT NOT NULL

);

-- Display all records of Product table on the basis of price in descending order

SELECT *

FROM Product

ORDER BY Price DESC;


17. To display the details of those items whose supplier code (SNo) is 104 or quantity in stock table is more than 100.

-- Create a new database (if not exists)

CREATE DATABASE IF NOT EXISTS YourDatabaseName;

-- Switch to the new database

USE YourDatabaseName;

-- Create the Stock table (if not exists)

CREATE TABLE IF NOT EXISTS Stock (

ItemID INT PRIMARY KEY,

ItemName VARCHAR(255) NOT NULL,

SNo INT NOT NULL,

Quantity INT NOT NULL

);

-- Display details of items from Stock table where SNo is 104 or Quantity is more than 100

SELECT *

FROM Stock

WHERE SNo = 104 OR Quantity > 100;


18. To display ItemNo and itemName of those items from stock table whose price is more than 5. select ItemNo,
ItemName from Stock where Price > 5;

-- Create a new database (if not exists)

CREATE DATABASE IF NOT EXISTS YourDatabaseName;

-- Switch to the new database

USE YourDatabaseName;

-- Create the Stock table (if not exists)

CREATE TABLE IF NOT EXISTS Stock (

ItemNo INT PRIMARY KEY,

ItemName VARCHAR(255) NOT NULL,

Price DECIMAL(10, 2) NOT NULL

);

-- Display ItemNo and ItemName of items from Stock table where Price is more than 5

SELECT ItemNo, ItemName

FROM Stock

WHERE Price > 5;


19. To display details of all items in the Stock table in ascending order of stockdate. select * from Stock order by
StockDate;

-- Create a new database (if not exists)

CREATE DATABASE IF NOT EXISTS YourDatabaseName;

-- Switch to the new database

USE YourDatabaseName;

-- Create the Stock table (if not exists)

CREATE TABLE IF NOT EXISTS Stock (

ItemID INT PRIMARY KEY,

ItemName VARCHAR(255) NOT NULL,

StockDate DATE NOT NULL

);

-- Display details of all items from Stock table in ascending order of StockDate

SELECT *

FROM Stock

ORDER BY StockDate;
20. Add a new column named "areaname" in the supplier table.

Alter table Supplier add areaname varchar (25);

-- Assuming the database is already created, switch to it

USE YourDatabaseName;

-- Add a new column named "areaname" to the Supplier table

ALTER TABLE Supplier

ADD areaname VARCHAR(25);


21. To display the details of those clients whose city is Delhi.

select * from Client where City = "Delhi" ;

-- Create a new database (if not exists)

CREATE DATABASE IF NOT EXISTS YourDatabaseName;

-- Switch to the new database

USE YourDatabaseName;

-- Create the Client table (if not exists)

CREATE TABLE IF NOT EXISTS Client (

ClientID INT PRIMARY KEY,

ClientName VARCHAR(255) NOT NULL,

City VARCHAR(100) NOT NULL

);

-- Display details of clients from Client table whose City is Delhi

SELECT *

FROM Client

WHERE City = 'Delhi';


22. To display the details of the products whose price is in the range of 50 to 100(both values included).

select * from Product where Price between 50 and 100;

-- Create a new database (if not exists)

CREATE DATABASE IF NOT EXISTS YourDatabaseName;

-- Switch to the new database

USE YourDatabaseName;

-- Create the Product table (if not exists)

CREATE TABLE IF NOT EXISTS Product (

ProductID INT PRIMARY KEY,

ProductName VARCHAR(255) NOT NULL,

Price DECIMAL(10, 2) NOT NULL

);

-- Display details of products from Product table whose Price is between 50 and 100

SELECT *

FROM Product

WHERE Price BETWEEN 50 AND 100;


23. To display the details of those products whose name ends with 'Wash'. select * from Product where
Name like "%Wash";

-- Create a new database (if not exists)

CREATE DATABASE IF NOT EXISTS YourDatabaseName;

-- Switch to the new database

USE YourDatabaseName;

-- Create the Product table (if not exists)

CREATE TABLE IF NOT EXISTS Product (

ProductID INT PRIMARY KEY,

Name VARCHAR(255) NOT NULL,

Price DECIMAL(10, 2) NOT NULL

);

-- Display details of products from Product table whose Name ends with 'Wash'

SELECT *

FROM Product

WHERE Name LIKE '%Wash';


24. Add a new column named "areaname" in the Client table.

Alter table Client add areaname varchar (25);

-- Assuming the database is already created, switch to it

USE YourDatabaseName;

-- Add a new column named "areaname" to the Client table

ALTER TABLE Client

ADD areaname VARCHAR(25);

25. To display details of all models in the Model table in ascending order of DateofManufacture. select * from Model
order by DateofManufacture;

-- Create a new database (if not exists)

CREATE DATABASE IF NOT EXISTS YourDatabaseName;

-- Switch to the new database

USE YourDatabaseName;

-- Create the Model table (if not exists)

CREATE TABLE IF NOT EXISTS Model (

ModelID INT PRIMARY KEY,

ModelName VARCHAR(255) NOT NULL,

DateofManufacture DATE NOT NULL

);

-- Display details of all models from Model table in ascending order of DateofManufacture

SELECT *

FROM Model

ORDER BY DateofManufacture;
26. To display details of those models whose cost is below 2000. select * from Model where Cost < 2000;

-- Create a new database (if not exists)

CREATE DATABASE IF NOT EXISTS YourDatabaseName;

-- Switch to the new database

USE YourDatabaseName;

-- Create the Model table (if not exists)

CREATE TABLE IF NOT EXISTS Model (

ModelID INT PRIMARY KEY,

ModelName VARCHAR(255) NOT NULL,

Cost DECIMAL(10, 2) NOT NULL

);

-- Display details of models from Model table whose Cost is below 2000

SELECT *

FROM Model

WHERE Cost < 2000;


27. To display the records of Company Table where CompName ends with the letter 'a'. select * from Company where
CompName like "%";

-- Create a new database (if not exists)

CREATE DATABASE IF NOT EXISTS YourDatabaseName;

-- Switch to the new database

USE YourDatabaseName;

-- Create the Company table (if not exists)

CREATE TABLE IF NOT EXISTS Company (

CompanyID INT PRIMARY KEY,

CompName VARCHAR(255) NOT NULL,

// Add other columns as needed

);

-- Display records of Company Table where CompName ends with the letter 'a'

SELECT *

FROM Company

WHERE CompName LIKE '%a';


28. To decrease the cost of all the models in Model table by 15.

Update Model set Cost = Cost - 15;

-- Create a new database (if not exists)

CREATE DATABASE IF NOT EXISTS YourDatabaseName;

-- Switch to the new database

USE YourDatabaseName;

-- Create the Model table (if not exists)

CREATE TABLE IF NOT EXISTS Model (

ModelID INT PRIMARY KEY,

ModelName VARCHAR(255) NOT NULL,

Cost DECIMAL(10, 2) NOT NULL

);

-- Decrease the cost of all models in Model table by 15

UPDATE Model

SET Cost = Cost - 15;

You might also like