0% found this document useful (0 votes)
17 views10 pages

ex1.doc.3.1.25

The document details the creation and manipulation of SQL tables in Oracle Database, including the creation of 'Employee' and 'Department' tables, adding constraints, modifying columns, and performing data manipulation operations such as inserting, updating, and deleting records. It also describes the creation of a 'students' table and various operations performed on it. The document illustrates SQL commands and their outcomes, showcasing the database management process.

Uploaded by

Suwathi V
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views10 pages

ex1.doc.3.1.25

The document details the creation and manipulation of SQL tables in Oracle Database, including the creation of 'Employee' and 'Department' tables, adding constraints, modifying columns, and performing data manipulation operations such as inserting, updating, and deleting records. It also describes the creation of a 'students' table and various operations performed on it. The document illustrates SQL commands and their outcomes, showcasing the database management process.

Uploaded by

Suwathi V
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

TABLE CREATION:

Microsoft Windows [Version 10.0.19045.5247]


(c) Microsoft Corporation. All rights reserved.
C:\Windows\System32>sqlplus
SQL*Plus: Release 11.2.0.2.0 Production on Fri Jan 3 10:46:36 2025
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Enter user-name: system
Enter password:
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL> CREATE TABLE Employee(EmpID NUMBER(2) PRIMARY KEY,EmpName VARCHAR2(50)
NOT NULL,Department NUMBER(4),Salary NUMBER(10,2) CHECK(SALARY>0),Email
VARCHAR2(100) UNIQUE);
Table created.
SQL> DESC Employee
Name Null? Type
----------------------------------------- -------- ----------------------------
EMPID NOT NULL NUMBER(2)
EMPNAME NOT NULL VARCHAR2(50)
DEPARTMENT NUMBER(4)
SALARY NUMBER(10,2)
EMAIL VARCHAR2(100)
SQL>

CREATE TABLE DEPARTMENT


SQL> CREATE TABLE Department(Department NUMBER(4) PRIMARY KEY, DepartmentName
VARCHAR2(50) NOT NULL);
Table created.

SQL>
DESC Department
Name Null? Type
----------------------------------------- -------- ----------------------------
DEPARTMENT NOT NULL NUMBER(4)
DEPARTMENTNAME NOT NULL VARCHAR2(50)

ALTER TABLE:

SQL> ALTER TABLE Employee


2 ADD CONSTRAINT fk_department
3 FOREIGN KEY (DEPARTMENT)
4 references Department(Department);
Table altered.
SQL> desc Employee
Name Null? Type
----------------------------------------- -------- ----------------------------
EMPID NOT NULL NUMBER(2)
EMPNAME NOT NULL VARCHAR2(50)
DEPARTMENT NUMBER(4)
SALARY NUMBER(10,2)
EMAIL VARCHAR2(100)

MODIFY :

SQL> ALTER TABLE Employee


2 MODIFY Salary NUMBER(12,2);
Table altered.
SQL> desc employee
Name Null? Type
----------------------------------------- -------- ----------------------------
EMPID NOT NULL NUMBER(2)
EMPNAME NOT NULL VARCHAR2(50)
DEPARTMENT NUMBER(4)
SALARY NUMBER(12,2)
EMAIL VARCHAR2(100)

DROP COLUMN:

SQL> ALTER TABLE Employee


2 DROP COLUMN Email;
Table altered.
SQL> desc employee
Name Null? Type
----------------------------------------- -------- ----------------------------
EMPID NOT NULL NUMBER(2)
EMPNAME NOT NULL VARCHAR2(50)
DEPARTMENT NUMBER(4)
SALARY NUMBER(12,2)

DROP TABLE:

SQL> DROP TABLE Employee;


Table dropped.
SQL> desc Employee
ERROR:
ORA-04043: object Employee does not exist

SQL>
DATA MANIPULATION LANGUAGE
EX:04
Table creation:
Microsoft Windows [Version 10.0.19045.5247]
(c) Microsoft Corporation. All rights reserved.
C:\Windows\system32>SQLPLUS
SQL*Plus: Release 11.2.0.2.0 Production on Tue Jan 7 09:47:35 2025
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Enter user-name: system
Enter password:
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL> create table emp(eno number(4),ename varchar2(15),salary number(6));
Table created.
SQL> desc emp;
Name Null? Type
----------------------------------------- -------- ----------------------------
ENO NUMBER(4)
ENAME VARCHAR2(15)
SALARY NUMBER(6)

INSERT VALUES:
SQL> insert into emp values(&1,'&2',&3);
Enter value for 1: 1001
Enter value for 2: employee1
Enter value for 3: 14000
old 1: insert into emp values(&1,'&2',&3)
new 1: insert into emp values(1001,'employee1',14000)
1 row created.
SQL> /
Enter value for 1: 1003
Enter value for 2: employee3
Enter value for 3: 8000
old 1: insert into emp values(&1,'&2',&3)
new 1: insert into emp values(1003,'employee3',8000)
1 row created.

SQL> /
Enter value for 1: 1004
Enter value for 2: employee4
Enter value for 3: 7000
old 1: insert into emp values(&1,'&2',&3)
new 1: insert into emp values(1004,'employee4',7000)
1 row created.

SQL> /
Enter value for 1: 1005
Enter value for 2: employee5
Enter value for 3: 9000
old 1: insert into emp values(&1,'&2',&3)
new 1: insert into emp values(1005,'employee5',9000)
1 row created.

SQL> select*from emp;


ENO ENAME SALARY
---------- --------------- ----------
1001 employee1 14000
1003 employee3 8000
1004 employee4 7000
1005 employee5 9000
SQL> INSERT INTO emp(ENO,ENAME) VALUES(4,'Robert White');

1 row created.

SQL> select*from emp;

ENO ENAME SALARY


---------- --------------- ----------
1001 employee1 14000
1003 employee3 8000
1004 employee4 7000
1005 employee5 9000
4 Robert White

EX:05
( DATA UPDATING)
SQL> update emp set ENAME='LOGU'where ENO=1003;
1 row updated.
SQL> select*from emp;
ENO ENAME SALARY
---------- --------------- ----------
1001 employee1 14000
1003 LOGU 8000
1004 employee4 7000
1005 employee5 9000
4 Robert White

Alter table:
SQL> alter table emp modify(ENAME varchar2(15));
Table altered.
SQL> SELECT*from emp;
ENO ENAME SALARY
---------- --------------- ----------
1001 employee1 14000
1003 LOGU 8000
1004 employee4 7000
1005 employee5 9000
4 Robert White
SQL>
Updating a single row:
SQL> create table students(studentid number,sname varchar2(15),Age number,department varchar2(6));
Table created.
SQL> desc students
Name Null? Type
----------------------------------------- -------- ----------------------------
STUDENTID NUMBER
SNAME VARCHAR2(15)
AGE NUMBER
DEPARTMENT VARCHAR2(6)

SQL> insert into students values(&1,'&2',&3,'&4');


Enter value for 1: 1
Enter value for 2: A
Enter value for 3: 20
Enter value for 4: Tamil
old 1: insert into students values(&1,'&2',&3,'&4')
new 1: insert into students values(1,'A',20,'Tamil')

1 row created.
SQL> /
Enter value for 1: 2
Enter value for 2: B
Enter value for 3: 20
Enter value for 4: com
old 1: insert into students values(&1,'&2',&3,'&4')
new 1: insert into students values(2,'B',20,'com')
1 row created.
SQL> /
Enter value for 1: 3
Enter value for 2: C
Enter value for 3: 18
Enter value for 4: CA
old 1: insert into students values(&1,'&2',&3,'&4')
new 1: insert into students values(3,'C',18,'CA')
1 row created.
SQL> SELECT*FROM STUDENTS;

STUDENTID SNAME AGE DEPART


---------- --------------- ---------- ------
1A 20 Tamil
2B 20 com
3C 18 CA

SQL> UPDATE STUDENTS SET Age=23,DEPARTMENT='MATHS'WHERE STUDENTID=1;

1 row updated.
SQL> select*from students;

STUDENTID SNAME AGE DEPART


---------- --------------- ---------- ------
1A 23 MATHS
2B 20 com
3C 18 CA

SQL> select*from students;


STUDENTID SNAME AGE DEPART
---------- --------------- ---------- ------
1A 23 ACC
2B 20 ACC
3C 18 CA

SQL> update students set Age=Age+1 where department='ACC';


2 rows updated.
SQL> select*from students;

STUDENTID SNAME AGE DEPART


---------- --------------- ---------- ------
1A 24 ACC
2B 21 ACC
3C 18 CA
SQL> select*from emp;

ENO ENAME SALARY


---------- --------------- ----------
1001 employee1 14000
1003 LOGU 8000
1004 employee4 7000
1005 employee5 9000
4 Robert White
SQL> delete from emp where ENAME='employee1';
1 row deleted.
SQL> select*from emp;

ENO ENAME SALARY


---------- --------------- ----------
1003 LOGU 8000
1004 employee4 7000
1005 employee5 9000
4 Robert White

SQL> spool off;


not spooling currently
SQL> delete from studentS where department='ACC';
2 rows deleted.
SQL> SELECT*from students;
STUDENTID SNAME AGE DEPART
---------- --------------- ---------- ------
3C 18 CA
SQL> delete from students;
1 row deleted.
SQL> select*from students;
no rows selected
SQL>

You might also like