Documente Academic
Documente Profesional
Documente Cultură
1
LAB QUERY :-
1) Write a query to create tables EMPLOYEE AND DEPARTMENT WITH THE
GIVEN ATTRIBUTES
a) EMPLOYEE(E_ID,FIRST_NAME,MIDDLE_NAME,LAST_NAME,DEPARTMEN
T_Id,
SALARY,PHONE_NO,EMAIL_ADDRESS).
b) DEPARTMENT(DEPT_ID,DEPT_NAME,LOCATION,MANAGER)
OUTPUT:-
a)
2.
Output:- b)
3.
LAB QUERY
2) Write a query to list all the EMPLOYEE whose name starts with letter ‘l’.
Output:-
5.
Output:
Output:-
6.
The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.
Lab query :-
5) Write a query to add an attribute(column) in the table.
Output:-
7.
OUTPUT:-
8.
9.
SQL Constraints
SQL constraints are used to specify rules for the data in a table. Constraints are used to limit the
type of data that can go into a table.
Constraints can be specified when the table is created with the CREATE TABLE statement, or
after the table is created with the ALTER TABLE statement.Syntax:-
CREATE TABLE table_name (column1 datatype constraint,
column2 datatype constraint,column3 datatype constraint, ....);
o Types of constraints:
1. SQL NOT NULL Constraint:- Ensures that a column cannot have a NULL value
2. SQL UNIQUE Constraint:- Ensures that all values in a column are different
5. SQL CHECK Constraint:-Ensures that all values in a column satisfies a specific condition
6. SQL DEFAULT Constraint:- Sets a default value for a column when no value is specified
7. SQL INDEX Constraint:- Used to create and retrieve data from the database very quickly
10.
LAB QUERY
Output:-
12.
UNIQUE CONSTRAINTS
REFERENTIAL INTEGRITY CONSTRAINT
13.
8. Write a query to find the total salary being paid to each job description in
department you may leave where salary <3000.
Output:-
14.
10. Display the last name, department name, and salary of any employee whose
salary matches the salary of another employee with E_ID 1700.
Output:
15.
Unit II
Joins
A join is a mechanism that extracts information from one or more tables. It allows retrieval of
rows from two or more related tables that share a common set of values.
Syntax :- SELECT column-names FROM table-name1 JOIN table-name2
ON column-name1 = column-name2 WHERE condition
Types of joins:-
i. Equi join
ii. Cartesian product
iii. Outer join
iv. Self join
v. Inner join
i. Equi join
The EQUIJOIN or INNER JOIN is a join in which join condition contains an
equality operator(=). It combine rows that have equivalent values for the specified
columns.syntax:- SELECT column_list FROM table1, table2....
WHERE table1.column_name = table2.column_name;
16.
A outer join simply extends the results of an EQUIJOIN . while using the EQUI
JOIN, we have seen that if there exists records in one table which do not have
corresponding values in the second, then those rows will not be selected. We can
forcefully select such rows by using OUTER JOIN .
Syntax:- SELECT column_name(s) FROM table1
FULL OUTER JOIN table2 ON table1.column_name = table2.column_n
17.
v.Inner join
18.
LAB QUERY
11. Write a query to find all employees who earn more than the average salary in
their departments.
Output:-
Output:-
19.
13. Get employee name salary and max salary offered by his department.
Output:-
20.
15. Get department name and maximum salary provided by that department. If
there is no employee for department display maximum salary as 0.
Output:-
21.
16. Get the number of employees whose salary is greater than their manager’s salary.
Output:-
17. Get Manager Name and total number of employees working under that
manager.
Output:-
22.
23.
24.
20. Display the names of employees who earn a salary more than that of X and of
Y.
Output:-
25.