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

Pavani 382

The document contains SQL commands to create tables, insert data, alter tables, update data, select data with various conditions, create primary and unique keys, and use savepoints and rollbacks. Tables are created to store student, employee, professor and university data. Data is inserted, updated and selected from the tables. Savepoints are used to rollback transactions and primary/unique keys are created and violated.

Uploaded by

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

Pavani 382

The document contains SQL commands to create tables, insert data, alter tables, update data, select data with various conditions, create primary and unique keys, and use savepoints and rollbacks. Tables are created to store student, employee, professor and university data. Data is inserted, updated and selected from the tables. Savepoints are used to rollback transactions and primary/unique keys are created and violated.

Uploaded by

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

SQL> create table students(sid integer,sname varchar2(20),gpa real,dob date);

Table created.

SQL> insert into students values(1,'pavani',9.2,'25-jan-1996');


1 row created.
SQL> insert into students values (&sid,'&sname',&gpa,'&dob');
Enter value for sid: 2
Enter value for sname: aiyushi
Enter value for gpa: 9
Enter value for dob: 18-aug-1996
old 1: insert into students values (&sid,'&sname',&gpa,'&dob')
new 1: insert into students values (2,'aiyushi',9,'18-aug-1996')
1 row created.
SQL> /
Enter value for
Enter value for
Enter value for
Enter value for
old 1: insert
new 1: insert

sid: 3
sname: prab
gpa: 8
dob: 31-aug-1995
into students values (&sid,'&sname',&gpa,'&dob')
into students values (3,'prab',8,'31-aug-1995')

1 row created.
SQL> alter table students add age integer ;
Table altered.

SQL> select * from students;


SID
---------1
2
3

SNAME
GPA DOB
AGE
-------------------- ---------- --------- ---------pavani
9.2 25-JAN-96
aiyushi
9 18-AUG-96
prab
8 31-AUG-95

SQL> update students set age=19 where sid=1;


1 row updated.
SQL> update students set age=20 where sid=2;
1 row updated.
SQL> update students set age=21 where sid=3;
1 row updated.
SQL> select * from students;
SID SNAME

GPA DOB

AGE

---------1
2
3

-------------------- ---------- --------- ---------pavani


9.2 25-JAN-96
19
aiyushi
9 18-AUG-96
20
prab
8 31-AUG-95
21

SQL> select * from students where age between 19 and 20;


SID
---------1
2

SQL>
Enter
Enter
Enter
Enter
Enter
old
new

SNAME
GPA DOB
AGE
-------------------- ---------- --------- ---------pavani
9.2 25-JAN-96
19
aiyushi
9 18-AUG-96
20

insert into students values (&sid,'&sname',&gpa,'&dob',&age);


value for sid: 4
value for sname: lakshmi
value for gpa: 9
value for dob: 23-mar-1995
value for age: 25
1: insert into students values (&sid,'&sname',&gpa,'&dob',&age)
1: insert into students values (4,'lakshmi',9,'23-mar-1995',25)

1 row created.
SQL> /
Enter value for sid: 5
Enter value for sname: sree
Enter value for gpa: 8.6
Enter value for dob: 16-nov-1995
Enter value for age: 23
old 1: insert into students values (&sid,'&sname',&gpa,'&dob',&age)
new 1: insert into students values (5,'sree',8.6,'16-nov-1995',23)
1 row created.
SQL> select * from students;
SID
---------1
2
3
4
5

SNAME
GPA DOB
AGE
-------------------- ---------- --------- ---------pavani
9.2 25-JAN-96
19
aiyushi
9 18-AUG-96
20
prab
8 31-AUG-95
21
lakshmi
9 23-MAR-95
25
sree
8.6 16-NOV-95
23

SQL> select * from students where sname like 'p-%i';


no rows selected
SQL> select * from students where sname like 'p_%i';
SID SNAME
GPA DOB
AGE
---------- -------------------- ---------- --------- ---------1 pavani
9.2 25-JAN-96
19
SQL> select * from students where sid in (1,2,3);

SID
---------1
2
3

SNAME
GPA DOB
AGE
-------------------- ---------- --------- ---------pavani
9.2 25-JAN-96
19
aiyushi
9 18-AUG-96
20
prab
8 31-AUG-95
21

SQL> create table stud(sid integer not null,sname varchar2(20),age integer);


Table created.
SQL> insert into stud values(&sid,'&sname',&age);
Enter value for sid: 1
Enter value for sname: pav
Enter value for age: 19
old 1: insert into stud values(&sid,'&sname',&age)
new 1: insert into stud values(1,'pav',19)
1 row created.
SQL> /
Enter value for sid: null
Enter value for sname: hani
Enter value for age: 20
old 1: insert into stud values(&sid,'&sname',&age)
new 1: insert into stud values(null,'hani',20)
insert into stud values(null,'hani',20)
*
ERROR at line 1:
ORA-01400: cannot insert NULL into ("PAVANI38"."STUD"."SID")
SQL> select * from stud;
SID SNAME
AGE
---------- -------------------- ---------1 pav
19
SQL> create table empl(empid integer UNIQUE,empname varchar2(20));
Table created.

SQL> insert into empl values(&empid,'&empname');


Enter value for empid: 1
Enter value for empname: pavani
old 1: insert into empl values(&empid,'&empname')
new 1: insert into empl values(1,'pavani')
1 row created.
SQL> /
Enter value for empid: 1
Enter value for empname: pav
old 1: insert into empl values(&empid,'&empname')
new 1: insert into empl values(1,'pav')
insert into empl values(1,'pav')
*

ERROR at line 1:
ORA-00001: unique constraint (PAVANI38.SYS_C005796) violated
SQL> /
Enter value for
Enter value for
old 1: insert
new 1: insert

empid: null
empname: pavaniii
into empl values(&empid,'&empname')
into empl values(null,'pavaniii')

1 row created.

SQL> create table fal(fname varchar2(20),courseid varchar2(20));


Table created.
SQL> insert into fal values('&fname','&courseid');
Enter value for fname:
Enter value for courseid:
old 1: insert into fal values('&fname','&courseid')
new 1: insert into fal values('','')
1 row created.

SQL> create table uni(unicode varchar2(20) primary key,uniname varchar2(20));


Table created.
SQL> insert into uni values ('&unicode','&uniname');
Enter value for unicode: 12
Enter value for uniname: gitam
old 1: insert into uni values ('&unicode','&uniname')
new 1: insert into uni values ('12','gitam')
1 row created.
SQL> /
Enter value for
Enter value for
old 1: insert
new 1: insert

unicode:
uniname:
into uni
into uni

13
rit
values ('&unicode','&uniname')
values ('13','rit')

1 row created.
SQL> /
Enter value for unicode: 12
Enter value for uniname: gvp
old 1: insert into uni values ('&unicode','&uniname')
new 1: insert into uni values ('12','gvp')
insert into uni values ('12','gvp')
*
ERROR at line 1:
ORA-00001: unique constraint (PAVANI38.SYS_C005797) violated
SQL> create table st(sid varchar2(20),sname varchar2(20));

Table created.
SQL> create table facu(sid varchar2(20),sname varchar2(20),gpa real,telephone in
teger);
Table created.
SQL> insert into facu values('&sid','&sname',&gpa,&telephone);
Enter value for sid: 1
Enter value for sname: pav
Enter value for gpa: 9.2
Enter value for telephone: 97048585
old 1: insert into facu values('&sid','&sname',&gpa,&telephone)
new 1: insert into facu values('1','pav',9.2,97048585)
1 row created.
SQL> SQL>create table fac(sid varchar2(20),sname varchar2(20),gpa real,telephon
e integer,primary key(sid,sname);
SP2-0734: unknown command beginning "SQL>create..." - rest of line ignored.
SQL> >create table fac(sid varchar2(20),sname varchar2(20),gpa real,telephone in
teger,primary key(sid,sname));
SP2-0734: unknown command beginning ">create ta..." - rest of line ignored.
SQL> create table fac(sid varchar2(20),sname varchar2(20),gpa real,telephone int
eger,primary key(sid,sname));
Table created.
SQL> insert into fac values('&sid','&sname',&gpa,&telephone);
Enter value for sid: 1
Enter value for sname: pav
Enter value for gpa: 9.2
Enter value for telephone: 85657
old 1: insert into fac values('&sid','&sname',&gpa,&telephone)
new 1: insert into fac values('1','pav',9.2,85657)
1 row created.
SQL> /
Enter value for
Enter value for
Enter value for
Enter value for
old 1: insert
new 1: insert

sid: 2
sname: pava
gpa: 5
telephone: 675
into fac values('&sid','&sname',&gpa,&telephone)
into fac values('2','pava',5,675)

1 row created.
SQL> /
Enter value for sid: 1
Enter value for sname: pav
Enter value for gpa: 5675666
Enter value for telephone: 5674766
old 1: insert into fac values('&sid','&sname',&gpa,&telephone)
new 1: insert into fac values('1','pav',5675666,5674766)
insert into fac values('1','pav',5675666,5674766)
*
ERROR at line 1:
ORA-00001: unique constraint (PAVANI38.SYS_C005798) violated

SQL> select * from students;


SID
---------1
2
3
4
5

SNAME
GPA DOB
AGE
-------------------- ---------- --------- ---------pavani
9.2 25-JAN-96
19
aiyushi
9 18-AUG-96
20
prab
8 31-AUG-95
21
lakshmi
9 23-MAR-95
25
sree
8.6 16-NOV-95
23

SQL> savepoint s1;


Savepoint created.
SQL> update students set age=20 where sid=1;
1 row updated.
SQL> savepoint s2;
Savepoint created.
SQL> delete from students where sid=3;
1 row deleted.
SQL> savepoint s3;
Savepoint created.

SQL>
Enter
Enter
Enter
Enter
Enter
old
new

insert into students values (&sid,'&sname',&gpa,'&dob',&age);


value for sid: 5
value for sname: iu
value for gpa: 7
value for dob: 25-jan-1996
value for age: 21
1: insert into students values (&sid,'&sname',&gpa,'&dob',&age)
1: insert into students values (5,'iu',7,'25-jan-1996',21)

1 row created.
SQL> select * from students;
SID
---------1
2
4
5
5

SNAME
GPA DOB
AGE
-------------------- ---------- --------- ---------pavani
9.2 25-JAN-96
20
aiyushi
9 18-AUG-96
20
lakshmi
9 23-MAR-95
25
sree
8.6 16-NOV-95
23
iu
7 25-JAN-96
21

SQL> rollback to s3;


Rollback complete.
SQL> select * from students;

SID
---------1
2
4
5

SNAME
GPA DOB
AGE
-------------------- ---------- --------- ---------pavani
9.2 25-JAN-96
20
aiyushi
9 18-AUG-96
20
lakshmi
9 23-MAR-95
25
sree
8.6 16-NOV-95
23

SQL> rollback to s2;


Rollback complete.
SQL> select * from students;
SID
---------1
2
3
4
5

SNAME
GPA DOB
AGE
-------------------- ---------- --------- ---------pavani
9.2 25-JAN-96
20
aiyushi
9 18-AUG-96
20
prab
8 31-AUG-95
21
lakshmi
9 23-MAR-95
25
sree
8.6 16-NOV-95
23

SQL> rollback to s1;


Rollback complete.
SQL> select * from emp;
no rows selected
SQL> savepoint s4;
Savepoint created.
SQL> commit;
Commit complete.
SQL> rollback to s4;
rollback to s4
*
ERROR at line 1:
ORA-01086: savepoint 'S4' never established

SQL> create table prof(pid integer,pname varchar2(20),age real);


Table created.

SQL> create table pro(pid integer,pname varchar2(20),age real,constraint p1 pri


mary key(pid));
Table created.

SQL> insert into pro values(&pid,'&pname',&age);


Enter value for pid: 1
Enter value for pname: laxmi
Enter value for age: 47
old 1: insert into pro values(&pid,'&pname',&age)
new 1: insert into pro values(1,'laxmi',47)
1 row created.
SQL> /
Enter value for
Enter value for
Enter value for
old 1: insert
new 1: insert

pid: 2
pname: anu
age: 50
into pro values(&pid,'&pname',&age)
into pro values(2,'anu',50)

1 row created.
SQL> /
Enter value for pid: 1
Enter value for pname: esf
Enter value for age: 34
old 1: insert into pro values(&pid,'&pname',&age)
new 1: insert into pro values(1,'esf',34)
insert into pro values(1,'esf',34)
*
ERROR at line 1:
ORA-00001: unique constraint (PAVANI38.P1) violated
SQL> create table pr(pid integer,pname varchar2(20),age real,constraint c1 check
(age>=15 and age<=30));
Table created.
SQL> insert into pr values(&pid,'&pname',&age);
Enter value for pid: 1
Enter value for pname: lax
Enter value for age: 40
old 1: insert into pr values(&pid,'&pname',&age)
new 1: insert into pr values(1,'lax',40)
insert into pr values(1,'lax',40)
*
ERROR at line 1:
ORA-02290: check constraint (PAVANI38.C1) violated

SQL> alter table pro modify age real constraint c not null;
Table altered.
SQL> insert into pro values(&pid,'&pname',&age);
Enter value for pid: 1
Enter value for pname: ga
Enter value for age:
old 1: insert into pro values(&pid,'&pname',&age)
new 1: insert into pro values(1,'ga',)
insert into pro values(1,'ga',)

*
ERROR at line 1:
ORA-00936: missing expression
SQL> /
Enter value for
Enter value for
Enter value for
old 1: insert
new 1: insert
insert into pro

pid: 4
pname: yr
age: null
into pro values(&pid,'&pname',&age)
into pro values(4,'yr',null)
values(4,'yr',null)
*

ERROR at line 1:
ORA-01400: cannot insert NULL into ("PAVANI38"."PRO"."AGE")
SQL> alter table pro drop constraint c;
Table altered.
SQL> alter table pro add constraint p primary key(pid);
alter table pro add constraint p primary key(pid)
*
ERROR at line 1:
ORA-02260: table can have only one primary key
SQL> alter table pr add constraint p2 primary key(pid);
Table altered.
SQL> insert into pr values(&pid,'&pname',&age);
Enter value for pid: 12
Enter value for pname: df
Enter value for age: 45
old 1: insert into pr values(&pid,'&pname',&age)
new 1: insert into pr values(12,'df',45)
insert into pr values(12,'df',45)
*
ERROR at line 1:
ORA-02290: check constraint (PAVANI38.C1) violated
SQL> /
Enter value for pid: 56
Enter value for pname: sdf
Enter value for age: 43
old 1: insert into pr values(&pid,'&pname',&age)
new 1: insert into pr values(56,'sdf',43)
insert into pr values(56,'sdf',43)
*
ERROR at line 1:
ORA-02290: check constraint (PAVANI38.C1) violated
SQL> /
Enter value for pid: 1
Enter value for pname: df
Enter value for age: 16

old
new

1: insert into pr values(&pid,'&pname',&age)


1: insert into pr values(1,'df',16)

1 row created.
SQL> /
Enter value for pid: 1
Enter value for pname: df
Enter value for age: 18
old 1: insert into pr values(&pid,'&pname',&age)
new 1: insert into pr values(1,'df',18)
insert into pr values(1,'df',18)
*
ERROR at line 1:
ORA-00001: unique constraint (PAVANI38.P2) violated
SQL> alter table pr drop constraint p2;
Table altered.
SQL> spool off;

You might also like