0% found this document useful (0 votes)
47 views3 pages

Aep 4

The document describes an experiment to create an index on a table to delete duplicate rows. It inserts data into the emp43 table, which creates some duplicate rows. It then: 1) Creates an index on the eid column to delete duplicate rows based on the eid, ename, and sal columns. 2) Creates a composite index on the eid and ename columns. 3) Creates an index on the sal column in reverse order and then rebuilds it without the reverse order. 4) Uses rownum to select the first two salaries from the table.

Uploaded by

Sachin Jain
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views3 pages

Aep 4

The document describes an experiment to create an index on a table to delete duplicate rows. It inserts data into the emp43 table, which creates some duplicate rows. It then: 1) Creates an index on the eid column to delete duplicate rows based on the eid, ename, and sal columns. 2) Creates a composite index on the eid and ename columns. 3) Creates an index on the sal column in reverse order and then rebuilds it without the reverse order. 4) Uses rownum to select the first two salaries from the table.

Uploaded by

Sachin Jain
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

EXPERIMENT-4

AIM: Create an Index on a table & delete the duplicate rows with the help of
an Index.
Procedure:
Creating table and inserting values into them:
SQL> create table emp43(eid number(10),ename char(10),sal number(10));

Table created.

SQL> insert into emp43 values('&eid','&ename','&sal');


Enter value for eid: 101
Enter value for ename: sachin
Enter value for sal: 30000
old 1: insert into emp43 values('&eid','&ename','&sal')
new 1: insert into emp43 values('143','sachin','30000')

1 row created.

SQL> /
Enter value for eid: 102
Enter value for ename: sahil
Enter value for sal: 35000
old 1: insert into emp43 values('&eid','&ename','&sal')
new 1: insert into emp43 values('102','sahil','35000')

1 row created.

SQL> /
Enter value for eid: 103
Enter value for ename: neha
Enter value for sal: 40000
old 1: insert into emp43 values('&eid','&ename','&sal')
new 1: insert into emp43 values('103','neha','40000')

1 row created.

SQL> /
Enter value for eid: 101
Enter value for ename: sachin
Enter value for sal: 30000
old 1: insert into emp43 values('&eid','&ename','&sal')
new 1: insert into emp43 values('104','sachin','30000')

1 row created.

SQL> /
Enter value for eid: 104
Enter value for ename: rohit
Enter value for sal: 35000
old 1: insert into emp43 values('&eid','&ename','&sal')
new 1: insert into emp43 values('104','rohit','35000')

1 row created.

SQL> /
Enter value for eid: 103
Enter value for ename: neha
Enter value for sal: 40000
old 1: insert into emp43 values('&eid','&ename','&sal')
new 1: insert into emp43 values('103','neha','40000')

1 row created.

SQL>select * from emp43;


EID ENAME SAL
---------- ---------- ----------
101 sachin 30000
102 sahil 35000
103 neha 40000
101 sachin 30000
104 rohit 35000
103 neha 30000

Creating Index on the table:

SQL> create index sa1 on emp43(eid);

Index created.
Deleting the duplicate rows of the table using index:
SQL> delete from emp43 where rowid not in(select min(rowid) from emp43
group by eid,ename,sal);

2 rows deleted.

SQL> select * from emp43;

EID ENAME SAL


---------- ---------- ----------
101 sachin 30000
102 sahil 35000
103 neha 40000
104 rohit 35000

Creating Composite Index on the table:


SQL> create index sa2 on emp43(eid,ename) ;
Index created.
Altering Index:
SQL> create index sa3 on emp43(sal) reverse;
Index created.
SQL> alter index sa3 rebuild noreverse;
Index altered.
Use of rownum:
SQL> select rownum,sal from emp43 where rownum<3;

ROWNUM SAL
---------------- ----------
1 30000
2 35000

SQL> commit;

Commit complete.

You might also like