0% found this document useful (0 votes)
2 views3 pages

SQL Class 2 Assignment

The document outlines a series of SQL database tasks including creating tables for 'Students', 'Customers', 'Employees', 'Books', and 'Orders', along with specific operations such as inserting, updating, deleting records, and retrieving data based on various conditions. It emphasizes the use of primary keys, foreign keys, and constraints like unique and check constraints. Additionally, it includes SQL queries for filtering and retrieving data based on age, price, and department criteria.

Uploaded by

damulya967
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)
2 views3 pages

SQL Class 2 Assignment

The document outlines a series of SQL database tasks including creating tables for 'Students', 'Customers', 'Employees', 'Books', and 'Orders', along with specific operations such as inserting, updating, deleting records, and retrieving data based on various conditions. It emphasizes the use of primary keys, foreign keys, and constraints like unique and check constraints. Additionally, it includes SQL queries for filtering and retrieving data based on age, price, and department criteria.

Uploaded by

damulya967
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

Assignment

Q. Create Database as SQL practice and use it for further questions.

Q. Create a table named "Students" with the following columns: StudentID (int),
FirstName (varchar), LastName (varchar), and Age (int). Insert at least three records into
the table.

ills
Q. Update the age of the student with StudentID 1 to 21. Delete the student with
StudentID 3 from the "Students" table.

Sk
Q. Retrieve the first names and ages of all students who are older than 20.

Q. Delete records from the same table where age<18.


a
at
Q. Create a table named "Customers" with the following columns and constraints:

CustomerID (int) as the primary key.

FirstName (varchar) not null.


D

LastName (varchar) not null.

Email (varchar) unique.


w

Age (int) check constraint to ensure age is greater than 18.


ro

Q. You have a table named "Orders" with columns: OrderID (int), CustomerID (int),
OrderDate (date), and TotalAmount (decimal). Create a foreign key constraint on the
"CustomerID" column referencing the "Customers" table.
G

Q. Create a table named "Employees" with columns:

EmployeeID (int) as the primary key.

FirstName (varchar) not null.

LastName (varchar) not null.

Salary (decimal) check constraint to ensure salary is between 20000 and 100000.
Q. Create a table named "Books" with columns:

BookID (int) as the primary key.

Title (varchar) not null.

ISBN (varchar) unique.

Q. Consider a table named "Employees" with columns: EmployeeID, FirstName,

ills
LastName, and Age. Write an SQL query to retrieve the first name and last name of
employees who are older than 30.

Sk
Q. Using the same "Employees" table, write an SQL query to retrieve the first name, last
name, and age of employees whose age is between 20 and 30.

Q. Given a table named "Products" with columns: ProductID, ProductName, Price, and
InStock (0- for out of stock, 1- for in stock). Write an SQL query to retrieve the product
a
names and prices of products that are either priced above $100 or are out of stock.
at
Q. Using the "Products" table, write an SQL query to retrieve the product names and
prices of products that are in stock and priced between 50 and 150.
D

Q. Consider a table named "Orders" with columns: OrderID, OrderDate, TotalAmount,


and CustomerID. Write an SQL query to retrieve the order IDs and total amounts of
w

orders placed by customer ID 1001 after January 1, 2023, or orders with a total amount
exceeding $500.
ro

Q. Retrieve the ProductName of products from the "Products" table that have a price
between $50 and $100.
G

Q. Retrieve the names of employees from the "Employees" table who are both from the
"Sales" department and have an age greater than 25, or they are from the "Marketing"
department.

Q. Retrieve the names of customers from the "Customers" table who are not from the
city 'New York' or 'Los Angeles'.
Q. Retrieve the names of employees from the "Employees" table who are either from the
"HR" department and have an age less than 30, or they are from the "Finance"
department and have an age greater than or equal to 35.

Q. Retrieve the names of customers from the "Customers" table who are not from the
city 'London' and either have a postal code starting with '1' or their country is not 'USA'.

ills
Sk
a
at
D
w
ro
G

You might also like