SQL Assignments 1

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Ass|gnments 1

Q1: Create an employee table that contains Iive columns:


Such as Employee Id, last name, First name, Phone number and Department number with the
Iollowing constraints.
1. %he last name and Iirst name should be not null.
2. Make a check constraint to check the department number is between 9 and 100.
3. Make a primary constraint on the employee ID column.
4. Make a Ioreign key on the department number column.
5. Use the "delete " to delete all records.
6. Use the "phone number" as a unique key.

SQL > CREATE TABLE employee
(empid NUMBER(10),
lastname VARCHAR2(20) not null,
firstname VARCHAR2 (20) not null,
phone_no VARCHAR2 (15),
deptno NUMBER(2) CHECK (deptno BE%EEN 9 AND 100),
constraint pk_employee_01 PRIMARY KEY (empid),
constraint fk_dept_01 FOREIGN KEY (deptno)
references dept (deptno) ON DELE%E CASCADE,
constraint uk_employee_01 UNQUE (phone_no));


Q2: Create an employee table that contains Iive columns:
Such as Employee Id, last name, First name, Phone number and Department number

1. Add a salary column to the employee table.

2. ModiIy the "ename" column size Irom varchar10 to varchar15.

3. Rename the "employee" table to the "iselIemployee" table.

4. Create a view to display the employee names oI the 'Accounting department only.

Q: Copy the 'EMP table to another table and name the new table "employee." In the new
employee table use the employee name, job, commission and department number.
A: SQL > CREATE TABLE employee
AS SELECT ename, job, comm, deptno
FROM emp;

Q: Add a salary column to the employee table.
A: SQL > ALTER TABLE employee
ADD (salary NUMBER(8,2));

Q: ModiIy the "ename" column size Irom varchar10 to varchar15.
A: SQL > ALTER TABLE employee
MODIFY (ename VARCHAR2(15));

Q: Rename the "employee" table to the "iselIemployee" table.
A: SQL > RENAME employee TO iself_employee;

Q: Create a view to display the employee names oI the 'Accounting department only.
A: SQL > CREATE VIEW employee_name
AS SELECT ename
FROM iself_employee
WHERE deptno 10;

You might also like