0% found this document useful (0 votes)
16 views7 pages

19-04-2024

The document shows SQL commands used to query, modify, and create indexes on database tables. It retrieves data from tables, describes table and index structures, adds and updates columns, and builds bitmap and standard indexes on various columns.

Uploaded by

Anand Rohit
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)
16 views7 pages

19-04-2024

The document shows SQL commands used to query, modify, and create indexes on database tables. It retrieves data from tables, describes table and index structures, adds and updates columns, and builds bitmap and standard indexes on various columns.

Uploaded by

Anand Rohit
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/ 7

SQL> select * from emp;

EMP_NO EMP_NAME SALARY MANAGER DEPT_NO


---------- -------------------- ---------- -------------------- ----------
COMM
----------
5000 SSS 20000 QQQ 400

6000 PPP 45392 WWW 200


5.3

7000 SSS 89392 AAA 300

EMP_NO EMP_NAME SALARY MANAGER DEPT_NO


---------- -------------------- ---------- -------------------- ----------
COMM
----------
8000 DDD 99392 BBB 400
7.2

9000 EEE 32421 JJJ 500


9.9

10000 GGG 48392 EEE 600


1.4

EMP_NO EMP_NAME SALARY MANAGER DEPT_NO


---------- -------------------- ---------- -------------------- ----------
COMM
----------
1000 AAA 45000 GGG 100
2.3

2000 BBB 55000 HHH 200


3.3

8 rows selected.

SQL> col emp_name for a10


SQL> /

EMP_NO EMP_NAME SALARY MANAGER DEPT_NO COMM


---------- ---------- ---------- -------------------- ---------- ----------
5000 SSS 20000 QQQ 400
6000 PPP 45392 WWW 200 5.3
7000 SSS 89392 AAA 300
8000 DDD 99392 BBB 400 7.2
9000 EEE 32421 JJJ 500 9.9
10000 GGG 48392 EEE 600 1.4
1000 AAA 45000 GGG 100 2.3
2000 BBB 55000 HHH 200 3.3

8 rows selected.
SQL> desc user_indexes;
Name Null? Type
----------------------------------------- -------- ----------------------------
INDEX_NAME NOT NULL VARCHAR2(128)
INDEX_TYPE VARCHAR2(27)
TABLE_OWNER NOT NULL VARCHAR2(128)
TABLE_NAME NOT NULL VARCHAR2(128)
TABLE_TYPE VARCHAR2(11)
UNIQUENESS VARCHAR2(9)
COMPRESSION VARCHAR2(13)
PREFIX_LENGTH NUMBER
TABLESPACE_NAME VARCHAR2(30)
INI_TRANS NUMBER
MAX_TRANS NUMBER
INITIAL_EXTENT NUMBER
NEXT_EXTENT NUMBER
MIN_EXTENTS NUMBER
MAX_EXTENTS NUMBER
PCT_INCREASE NUMBER
PCT_THRESHOLD NUMBER
INCLUDE_COLUMN NUMBER
FREELISTS NUMBER
FREELIST_GROUPS NUMBER
PCT_FREE NUMBER
LOGGING VARCHAR2(3)
BLEVEL NUMBER
LEAF_BLOCKS NUMBER
DISTINCT_KEYS NUMBER
AVG_LEAF_BLOCKS_PER_KEY NUMBER
AVG_DATA_BLOCKS_PER_KEY NUMBER
CLUSTERING_FACTOR NUMBER
STATUS VARCHAR2(8)
NUM_ROWS NUMBER
SAMPLE_SIZE NUMBER
LAST_ANALYZED DATE
DEGREE VARCHAR2(40)
INSTANCES VARCHAR2(40)
PARTITIONED VARCHAR2(3)
TEMPORARY VARCHAR2(1)
GENERATED VARCHAR2(1)
SECONDARY VARCHAR2(1)
BUFFER_POOL VARCHAR2(7)
FLASH_CACHE VARCHAR2(7)
CELL_FLASH_CACHE VARCHAR2(7)
USER_STATS VARCHAR2(3)
DURATION VARCHAR2(15)
PCT_DIRECT_ACCESS NUMBER
ITYP_OWNER VARCHAR2(128)
ITYP_NAME VARCHAR2(128)
PARAMETERS VARCHAR2(1000)
GLOBAL_STATS VARCHAR2(3)
DOMIDX_STATUS VARCHAR2(12)
DOMIDX_OPSTATUS VARCHAR2(6)
FUNCIDX_STATUS VARCHAR2(8)
JOIN_INDEX VARCHAR2(3)
IOT_REDUNDANT_PKEY_ELIM VARCHAR2(3)
DROPPED VARCHAR2(3)
VISIBILITY VARCHAR2(9)
DOMIDX_MANAGEMENT VARCHAR2(14)
SEGMENT_CREATED VARCHAR2(3)
ORPHANED_ENTRIES VARCHAR2(3)
INDEXING VARCHAR2(7)

SQL> select index_name from user_indexes where table_name='EMP';

INDEX_NAME
--------------------------------------------------------------------------------
IDX

SQL> desc user_ind_columns;


Name Null? Type
----------------------------------------- -------- ----------------------------
INDEX_NAME VARCHAR2(128)
TABLE_NAME VARCHAR2(128)
COLUMN_NAME VARCHAR2(4000)
COLUMN_POSITION NUMBER
COLUMN_LENGTH NUMBER
CHAR_LENGTH NUMBER
DESCEND VARCHAR2(4)
COLLATED_COLUMN_ID NUMBER

SQL> select index_name,column_name from user_ind_columns where table_name='EMP';

INDEX_NAME
--------------------------------------------------------------------------------
COLUMN_NAME
--------------------------------------------------------------------------------
IDX
EMP_NO

SQL> desc student;


Name Null? Type
----------------------------------------- -------- ----------------------------
STUDENT_ID NUMBER
FNAME NOT NULL VARCHAR2(10)
LNAME NOT NULL VARCHAR2(10)
AGE NOT NULL NUMBER(38)

SQL> select * from student;

STUDENT_ID FNAME LNAME AGE


---------- ---------- ---------- ----------
45 hhh lll 32
32 mmm nnn 12
45 hhh lll 32
2 mmm nnn 12

SQL> alter table student add(gender varchar2(1));

Table altered.

SQL> update student set gender='F' where student_id=45;

2 rows updated.

SQL> update student set gender='M' where student_id=32;


1 row updated.

SQL> update student set gender='M' where student_id=2;

1 row updated.

SQL> commit;

Commit complete.

SQL> select * from student;

STUDENT_ID FNAME LNAME AGE G


---------- ---------- ---------- ---------- -
45 hhh lll 32 F
32 mmm nnn 12 M
45 hhh lll 32 F
2 mmm nnn 12 M

SQL> create bitmap index idx1 on student(gender);

Index created.

SQL> select index_name,index_type from user_indexes where table_name='STUDENT';

INDEX_NAME
--------------------------------------------------------------------------------
INDEX_TYPE
---------------------------
IDX1
BITMAP

SQL> select * from emp;

EMP_NO EMP_NAME SALARY MANAGER DEPT_NO COMM


---------- ---------- ---------- -------------------- ---------- ----------
5000 SSS 20000 QQQ 400
6000 PPP 45392 WWW 200 5.3
7000 SSS 89392 AAA 300
8000 DDD 99392 BBB 400 7.2
9000 EEE 32421 JJJ 500 9.9
10000 GGG 48392 EEE 600 1.4
1000 AAA 45000 GGG 100 2.3
2000 BBB 55000 HHH 200 3.3

8 rows selected.

SQL> create index idx2 on emp(salary+comm);

Index created.

SQL> select index_name,index_type from user_indexes where table_name='STUDENT';

INDEX_NAME
--------------------------------------------------------------------------------
INDEX_TYPE
---------------------------
IDX1
BITMAP

SQL> select index_name,index_type from user_indexes where table_name='EMP';

INDEX_NAME
--------------------------------------------------------------------------------
INDEX_TYPE
---------------------------
IDX
NORMAL

IDX2
FUNCTION-BASED NORMAL

SQL> select * from salesman;


select * from salesman
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> select * from sales;


select * from sales
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> create index sales_prod on cluster salesprod;


create index sales_prod on cluster salesprod
*
ERROR at line 1:
ORA-00943: cluster does not exist

SQL> create table emp


2 (
3 eid number(10),
4 ename varchar2(100),
5 did number(2)
6 )
7 cluster empdept(did);
cluster empdept(did)
*
ERROR at line 7:
ORA-00943: cluster does not exist

SQL> ----------------------------------------------------------
SQL> create table dept
2 (
3 did number(2),
4 dname varchar2(100)
5 )
6 cluster empdept(did);
cluster empdept(did)
*
ERROR at line 6:
ORA-00943: cluster does not exist

SQL> create table sales(sales_id number(10),sales_name varchar2(10),prod_id number)


cluster salesprod(prod_id);
create table sales(sales_id number(10),sales_name varchar2(10),prod_id number)
cluster salesprod(prod_id)

*
ERROR at line 1:
ORA-00943: cluster does not exist

SQL> create table empl


2 (
3 eid number(10),
4 ename varchar2(100),
5 did number(2)
6 )
7 cluster empdept(did);
cluster empdept(did)
*
ERROR at line 7:
ORA-00943: cluster does not exist

SQL> ----------------------------------------------------------
SQL> create table dept1
2 (
3 did number(2),
4 dname varchar2(100)
5 )
6 cluster empdept(did);
cluster empdept(did)
*
ERROR at line 6:
ORA-00943: cluster does not exist

SQL> create index empdept_indx on cluster empdept;


create index empdept_indx on cluster empdept
*
ERROR at line 1:
ORA-00943: cluster does not exist

SQL> create cluster empdept (did number(2));

Cluster created.

SQL> create index empdept_indx on cluster empdept;

Index created.

SQL> create table empl


2 (
3 eid number(10),
4 ename varchar2(100),
5 did number(2)
6 )
7 cluster empdept(did);
create table empl
*
ERROR at line 1:
ORA-00955: name is already used by an existing object

SQL> create table emp1


2 (
3 eid number(10),
4 ename varchar2(100),
5 did number(2)
6 )
7 cluster empdept(did);

Table created.

SQL> create table dept1


2 (
3 did number(2),
4 dname varchar2(100)
5 )
6 cluster empdept(did);

Table created.

SQL> exit

You might also like