Step 1: Creating a basic table |
First, we need a couple of tables. Create two tables, one named EMP and the other named DEPT, based on the following specifications. Add the necessary definition to your create statements to place the two tables in the USERS01 tablespace.
Be sure that you explicitly name your constraints. I would suggest that you use a format of table_column_type, for example SDEPT_DEPTNO_PK.
Table Name | Column Name | Data Type | Constraint |
S_DEPT | DEPTNO | NUMBER(2) | PK |
DNAME | VARCHAR2(14) | ||
LOC | CHAR(13) | ||
S_EMP | EMPNO | NUMBER(4) | PK |
ENAME | VARCHAR2(10) | ||
JOB | VARCHAR2(9) | ||
MGR | NUMBER(4) | FK References EMPNO | |
HIREDATE | DATE | ||
SAL | NUMBER(7,2) | ||
COMM | NUMBER(7,2) | ||
DEPTNO | NUMBER(2) | FK References S_DEPT |
Table created.Now query the DBA_TABLES view to verify that your tables are in the correct place.
Table created.
Hint: You will need a where clause that limits the select to just your tables; otherwise, you will get some very interesting results.Your response will look similar to this:
TABLE_NAME TABLESPACE_NAME
------------------------------ ---------------------
S_DEPTUSERS01
S_EMPUSERS01
Step 2: Determining table storage |
Your response will look similar to this:
TABLE_NAME INITIAL_EXTENT NEXT_EXTENT MAX_EXTENTS PCT_INCREASESince the two tables were created without specifying initial, next, and max extents, the tables inherited their storage from the tablespace they were assigned to. To validate this, query the same information from the DBA_TABLESPACES dictionary view and compare.
------------------------------ --------------- -------------- --------------- --------------
S_EMP16384 16384 2147483645 0
S_DEPT16384 16384 2147483645 0
Your response will look similar to this:
TABLESPACE_NAMEINITIAL_EXTENT NEXT_EXTENT MAX_EXTENTS PCT_INCREASE
------------------------------ --------------- -------------- -------------- --------------
USERS0116384 16384 2147483645 0
Step 3: Specifying storage at creation |
Table Name Column Name Data Type ConstraintS_ITEM ITEMNO NUMBER(2) PK
DESCRIPTION VARCHAR2(20)
PRICE NUMBER(7,2)
Your response will look similar to this:
Table created.
Now query the DBA_TABLES view again to verify that the new table has the correct settings.
Your response will look similar to this:
TABLE_NAMEINITIAL_EXTENT NEXT_EXTENT MAX_EXTENTS PCT_INCREASE
------------------------------ ---------------- -------------- -------------- --------------
S_EMP16384 16384 2147483645 0
S_DEPT16384 16384 2147483645 0
S_ITEM524288 524288 100 0
Step 4: Temporary tables |
For this part of the lab, you are going to create a new table based on the definition of the S_DEPT table. Before you do this, though, we want to put some data in the table. Download the LOAD_DEPT.SQL file from Doc Sharing and run the script to load your S_DEPT table with four records.
Now, create a new table named G_DEPT based on the S_DEPT table. Make sure that it will preserve the data on commit, and make sure that the data in S_DEPT gets transferred to the new table. After the table is created, query the new G_DEPT table to verify that the data is there.
Your response will look similar to this:
Table created.Your response will look similar to this:
DEPTNO DNAME LOCRemember that this is only a work table, good for a single session. To compare this new type of table to the three that you have already created, query the DBA_TABLES view as you did in step three, to list all four tables now. Notice the difference in the G_DEPT table.
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
Your response will look similar to this:
TABLE_NAME INITIAL_EXTENT NEXT_EXTENT MAX_EXTENTS PCT_INCREASE
------------------------------ --------------- -------------- -------------- ---------------
S_EMP16384 16384 2147483645 0
S_DEPT16384 16384 2147483645 0
G_DEPT
S_ITEM524288 16384 2147483645 0
Step 5: Adding a column to an existing table |
Your response will look similar to this:
Table altered.
Step 6: Renaming an existing column and changing data type |
Your response will look similar to this:
Table altered.Additionally, some of the table’s locations are turning out to be longer names than the column will allow, and it was also decided that the data type needed to be a VARCHAR2 in place of a CHAR data type. Write and execute the required statement to change the column data type to a VARCHAR2 with a length of 30.
Your response will look similar to this:
Table altered.
Step 7: Adding an index to a column |
Your response will look similar to this:
Index created.Looks like the table is much more functional now, but you need to make sure that all the changes are intact. Verify the changes made to the S_DEPT table by first doing issuing the describe command on the table to look at the column names and data types. Next, write and execute a query using the data dictionary that will list all of the indexes that are in the S_DEPT table. This should also verify that your new index is in place.
Your response will look similar to this:
NameYour response will look similar to this:Null? Type
----------------------------------- ---------- ------------
DEPTNONOT NULL NUMBER(2)
DNAMEVARCHAR2(14)
LOCATIONVARCHAR2(30)
LOCATION_PICBLOB
INDEX_NAME
------------------------------ ------------------------------ -----------------
S_DEPT_PRIMARY_KEY S_DEPT
LOC_BM_IDX
Related Documents
No comments:
Post a Comment