Chandan Kumar Jha .Dbms
Chandan Kumar Jha .Dbms
PACTICAL FILE
CREATE
ALTER.
DROP
3. Write queries to execute following DML commands :
UPDATE
DELETE
4. Write the queries to execute DCL commands.
Primary Key
Unique Key
Not Null
Foreign Key
6. Write queries to execute following Aggregate functions
Group By
Having
8. Differentiate IS NULL and IS NOT NULL by applying onto table.
Intersection
Union
Set Difference
11. Apply Selection and Projection relational operation on table and generate output.
12. Retrieve data from more than one table using inner join, left outer, right outer and
full outer Joins.
13. Create index and View on a table in DBMS.
1: Give description about E-R diagram with all terminology in pictorial form.
+------------------+ +--------------+
| Student | | Course |
+------------------+ +--------------+
| Name | | Title |
| Age | | Credits |
+------------------+ +--------------+
| |
| |
| +---------------------+ |
+---------------------+
| Enroll ID (PK) |
| Student ID (FK) |
| Course ID (FK) |
+---------------------+
CREATE
ALTER.
DROP
Create:
id INT,
name VARCHAR(50),
age INT
);
Alter:
Drop:
3: Write queries to execute following DML commands : • INSERT: Insert five records
in each table. • UPDATE • DELETE
INSERT:
UPDATE:
UPDATE employees
SET age = 31
WHERE id = 1;
DELETE:
WHERE id = 3;
GRANT:
REVOKE:
5 : Create table using following integrity constraints: • Primary Key • Unique Key •
Not Null • Foreign Key
PRIMARY KEY:
name VARCHAR(50),
age INT
);
UNIQUE KEY:
name VARCHAR(50),
age INT
);
NOT NULL KEY:
id INT,
price DECIMAL(10,2)
);
FOREIGN KEY:
name VARCHAR(50),
email VARCHAR(50)
);
order_date DATE,
customer_id INT,
);
FROM sales;
AVG:
SELECT AVG(price) AS average_price
FROM products;
COUNT:
FROM customers;
MINIMUM:
FROM employees;
MAXIMUM:
FROM employees;
FROM sales
GROUP BY category;
HAVING:
FROM sales
GROUP BY category
John 3000
Mary null
adam 5000
IS NULL:
SELECT *
FROM employees
IS NOT NULL:
SELECT *
FROM employees
9 : Apply following logical operators onto the table: • BETWEEN, IN, AND, OR and
NOT
id name price
1 Laptop 1000
2 Phone 500
3 Tablet 800
4 Tv 1500
5 headphone 100
BETWEEN:
SELECT *
FROM products
IN:
SELECT *
FROM products
AND:
SELECT *
FROM products
OR:
SELECT *
FROM products
NOT:
SELECT *
FROM products
10 : Take two tables and show following results .Intersection • Union • Set
Difference
Id name
1 John
2 Mary
3 Adam
4 Emily
id name
3 Adam
4 Emily
5 Sarah
6 Michael
INTERSECTION:
SELECT *
FROM table1
INTERSECT
SELECT *
FROM table2;
id name
3 Adam
4 Emily
UNION:
SELECT *
FROM table1
UNION
SELECT *
FROM table2;
id name
1 John
2 Mary
3 Adam
4 Emily
5 Sarah
6 Michael
SET DIFFERENCE:
SELECT *
FROM table1
EXCEPT
SELECT *
FROM table2;
id name
1 John
2 Mary
SELECT *
FROM employees
PROJECTION:
FROM employees;
John 5000
Mary 4000
David 6000
Sarah 4500
12 : Retrieve data from more than one table using inner join, left outer, right outer
and full outer Joins.
id name city
1001 1 500
1002 2 700
1003 1 300
1004 3 900
INNER JOIN:
FROM customers
FROM customers
FROM customers
Name
ON table_name (column_name);
ON customers (City);
CREATING A VIEW:
FROM table_name
WHERE condition;
FROM customers;