0% found this document useful (0 votes)
8 views

SQL Practice

The document outlines SQL queries for creating and modifying two tables: Employee and Departments, including constraints and alterations to the Employee table. It details the structure of the tables, including data types and constraints, and shows the results of various operations such as adding columns and dropping the table. The final output indicates the successful execution of commands and the non-existence of the Employee table after it has been dropped.

Uploaded by

Suwathi V
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

SQL Practice

The document outlines SQL queries for creating and modifying two tables: Employee and Departments, including constraints and alterations to the Employee table. It details the structure of the tables, including data types and constraints, and shows the results of various operations such as adding columns and dropping the table. The final output indicates the successful execution of commands and the non-existence of the Employee table after it has been dropped.

Uploaded by

Suwathi V
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

EXERCISE 1

S.NO.1:

QUERY:

CREATE TABLE Employee(

EmpID NUMBER(6)PRIMARY KEY,

EmpName VARCHAR2(50)NOT NULL,

DepartmentID NUMBER(4),

Salary NUMBER(10,2)CHECK(Salary>0),

Email VARCHAR2(100)UNIQUE);

Table created.

desc Employee

OUTPUT:

Name Null? Type

----------------------------------------- -------- ----------------------------

EMPID NOT NULL NUMBER(6)

EMPNAME NOT NULL VARCHAR2(50)

DEPARTMENTID NUMBER(4)

SALARY NUMBER(10,2)

EMAIL VARCHAR2(100)

QUERY:

CREATE TABLE Departs(

DepartID NUMBER(4)PRIMARY KEY,

DepartName VARCHAR2(50)NOT NULL);

Table created.

desc Departments

OUTPUT:

Name Null? Type

----------------------------------------- -------- ----------------------------

DEPARTMENTID NOT NULL NUMBER(4)

DEPARTMENTNAME NOT NULL VARCHAR2(50)


S.NO.2:

QUERY:

ALTER TABLE Employee

ADD CONSTRAINT fk_department

FOREIGN KEY(DepartmentID)

REFERENCES Departments(DepartmentID);

Table altered.

desc Employee

OUTPUT:

Name Null? Type

----------------------------------------- -------- ----------------------------

EMPID NOT NULL NUMBER(6)

EMPNAME NOT NULL VARCHAR2(50)

DEPARTMENTID NUMBER(4)

SALARY NUMBER(10,2)

EMAIL VARCHAR2(100)

QUERY:

ALTER TABLE Employee

MODIFY EmpName VARCHAR2(100);

Table altered

ALTER TABLE Employee

ADD DateOfJoining DATE;

Table altered.

desc Employee

OUTPUT:

Name Null? Type

----------------------------------------- -------- ----------------------------

EMPID NOT NULL NUMBER(6)

EMPNAME NOT NULL VARCHAR2(100)

DEPARTMENTID NUMBER(4)
SALARY NUMBER(10,2)

EMAIL VARCHAR2(100)

DATEOFJOINING DATE

QUERY:

ALTER TABLE Employee

2 DROP COLUMN Email;

Table altered.

desc Employee

OUTPUT:

Name Null? Type

----------------------------------------- -------- ----------------------------

EMPID NOT NULL NUMBER(6)

EMPNAME NOT NULL VARCHAR2(100)

DEPARTMENTID NUMBER(4)

SALARY NUMBER(10,2)

DATEOFJOINING DATE

S.NO. 3

QUERY:

DROP TABLE Employee;

Table dropped.

OUTPUT:

Object employee does not exist

You might also like