0% found this document useful (0 votes)
4 views9 pages

DBMS 1

Uploaded by

SAGAR parihar
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)
4 views9 pages

DBMS 1

Uploaded by

SAGAR parihar
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/ 9

PROGRAM -1

 Query : To create a customer table.


Input :
CREATE TABLE Customers (

customer_id INT,

first_name VARCHAR(50) not null,

last_name VARCHAR(50),

age INT,

country VARCHAR(50)

);

INSERT INTO Customers (customer_id,first_name, last_name, age, country) VALUES

(1,'Denji', 'Bond', 17, 'Japan'),

(2,'Harry', 'Potter', 20, 'USA'),

(3,'Jerome', 'Patrick', 22, 'UK'),

(4,'Kevin', 'Henry', 19, 'India'),

(5,'Layla', 'Davila', 30, 'USA'),

(6,'Sunny', 'Deol', 38, 'UAE'),

(7,'Dua', 'Lipa', 26, 'Germany'),

(8,'Tom', 'Holland', 41, 'Japan'),

(9,'Dinesh', 'Sharma', 20, 'UK'),

(10,'Umesh', 'Yadav', 18, 'Russia');


 Query : To order the customers by their age
Input :
SELECT * FROM Customers

ORDER BY age;

 Query : To order the customers by last_name in alphabatical order.


Input :
SELECT * FROM Customers

ORDER BY last_name;
 Query : To order the customers by last_name in alphabetically descending
order.
Input :
SELECT * FROM Customers

ORDER BY last_name DESC;

 Query : To order the customers name in alphabatical order.


Input :
SELECT * FROM Customers

ORDER BY first_name ASC;


 Query : Find the Customer whose customer_id is >4.
Input :
SELECT * FROM Customers

WHERE customer_id > 4;

 Query : Find the Customer whose customer_id is not 4.


Input :
SELECT * FROM Customers

WHERE customer_id <> 4;


 Query : Find the Customer whose name starts with ‘H’ and is from ‘USA’.
Input :
SELECT * FROM Customers

WHERE first_name LIKE 'H%' AND country = 'USA';

 Query : Find the Customer whose name starts with ‘D’ and is from ‘USA’.
Input :
SELECT * FROM Customers

WHERE first_name LIKE 'D%' AND country = 'USA';

 Query : Find the Customer whose name starts with ‘D’ and is from a country
whose name starts with ‘U’.
Input :
SELECT * FROM Customers

WHERE first_name LIKE 'D%' AND (country = 'USA' or country LIKE 'U%');

 Query : Find the Customer who is from ‘USA’ or a country whose name starts
with ‘U’.
Input :
SELECT * FROM Customers

WHERE first_name LIKE 'r%' AND country = 'USA' or country LIKE 'U%';
 Query : Find the Customers whose names does not starts with ‘D’.
Input :
SELECT * FROM Customers

WHERE first_name NOT LIKE 'D%';

 Query : Find the Customers whose customer_id not between 2 and 4.


Input :
SELECT * FROM Customers

WHERE customer_id NOT BETWEEN 2 AND 4;


 Query : Find the first_name which is not 'Denji' and ‘Harry’.
Input :
SELECT * FROM Customers

WHERE first_name NOT IN ('Denji', 'Harry');

 Query : Find the customers whose age is not ‘31’ and ‘22’.
Input :
SELECT * FROM Customers

WHERE age NOT IN (31, 22);


 Query : Find the customers whose age is less than or equal to 20.
Input :
SELECT * FROM Customers

WHERE NOT age > 20;

 Query : Update the first and last name of customer.


Input :
UPDATE Customers

SET first_name = 'Deepak', last_name= 'Frankfurt'

WHERE customer_id = 1;
 Query : Update the age of a customer.
Input :
UPDATE Customers

SET age = 30

WHERE customer_id = 5;

You might also like