Database (SQL Lab Question)
Database (SQL Lab Question)
1. What is SQL?
2. Explain types of SQL commands.
3. Write a SQL statement to create a simple table name country which contains
columns country_id, country_name and region_id(country_id is primary
key of table).
4. Write a SQL statement to insert record with your own values into the table
country against each column.
5. Design a database of a company where database name is company. Create
tables in above database as follows:
Employee(eno, e_name, salary)
Department( dept_no, d_name, d_location)
(i) Display the table with all data values.
(ii) Find out the emp_name from the employee table.
(iii) Find out the salary of employee.
(iv) Update employee name from table.
(v) Add new column tel_number in employee table.
(vi) Display the department name which is situated at Delhi.
(vii) Display the department number of IT department.
6. Design a database of a shop where database name is shop. Create a table as
following:
Customer (ID, name, age, city, salary)
(i) Write a query to find the salary of person where age <= 26 and salary
>=25000 from the customer table.
(ii) Write a query to find the salary of a person where age <= 26 or salary
>= 33000 from customer table.
(iii) Write a query to find the customer detail using “IN” and
“BETWEEN” operator where age can be 25 or 27.
(iv) List name of customer whose name start ‘_a%’.
(v) List name of customer Like ‘A%’.
(vi) Find the list of all customer who live in ‘Bombay’ or ‘Delhi’ or
‘Madras’ city.
7. Create a table as follows:
Product (product_id, name, description, price)
(i) Write a query to find the total price of product.
(ii) Write a query to find the average price of product.
(iii) Write a query to find the maximum price of product.
(iv) Write a query to find the minimum price of product.
(v) Write a query to find the total number of product.
8. JOIN Operations:
Create following tables:
Order (order_id, cust_id, order_name)
Customer (cust_id, cust_name, contact_name, country)
Employee (emp_id, lastname, firstname, birth_date)
(i) Write a query for select records that have matching values in both
tables (INNER JOIN).
(ii) Write a query for select all records with customer information
(INNER JOIN).
(iii) Write a query for select all customer and any orders they might have
(LEFT JOIN).
(iv) Write a query for return all employees and orders they might have
placed (RIGHT JOIN).
(v) Write a query for select all customers and all orders (FULL OUTER
JOIN).
(vi) Write a query for display the customer name that’s live in same city
(SELF JOIN)
9. Create an index on a combination of columns cust_name and contact_name
in the customer table.
10. Create a view that shows all customers whose country is Brazil from
customer table. Also show the view.
11. Create a view that selects every product in the product table with a price
higher than average price. Also show the view.