Difference between revisions of "Oracle:Sample Database"

From mi-linux
Jump to navigationJump to search
Line 53: Line 53:
 
user_tables refers to a data dictionary table, which is a set of tables which allows you to query what objects you own. See <section 22> for further information on the Data Dictionary.
 
user_tables refers to a data dictionary table, which is a set of tables which allows you to query what objects you own. See <section 22> for further information on the Data Dictionary.
  
=== 4. Getting Information about the Attributes of a Table ===
 
 
To get a description of a particular table use the DESCRIBE command.
 
 
To describe the table EMP:
 
 
  describe emp
 
 
Note, describe is a command proprietary to Oracle and is not part of the SQL standard. These commands are part of the Plus commands Oracle provides and do not need a semi-colon after them.
 
 
== Exercise 1 ==
 
 
Type in the SQL code to display the structure of the CUSTOMER table.
 
 
The result should be similar to the following:
 
 
Name                                      Null?    Type
 
----------------------------------------- -------- ----------------------------
 
CNO                                                NUMBER(4)
 
ORDERDATE                                          DATE
 
NAME                                              VARCHAR2(15)
 
CITY                                              VARCHAR2(15)
 
COUNTRY                                            VARCHAR2(15)
 
PNO                                                NUMBER(4)
 
DESCRIPTION                                        VARCHAR2(20)
 
QTY                                                NUMBER(4)
 
  
  

Revision as of 20:29, 15 February 2016

Main Page >> Oracle and SQL >> Getting Started >> SQL*Plus

Copying the Sample Database

The sample database used in this workbook needs to be set-up first by the following steps:

1. Download the setup script

  • Go to the Oracle web server: http://oradb-srv.wlv.ac.uk
  • Look for the link called sqlload.sql setup script
  • Right click on this and depending on your browser, select Save Link As...., Save Page As.... or Save Target As….
  • Save the file to your “Documents” Personal storage folder (U:\ drive)

Note, it is advisable not to save the file in any folders,or the Desktop to begin with, since that makes it hard to access via Oracle. Once the script is run, you can move the script somewhere else.

2. Run the setup script

Assuming you are logged into Oracle successfully (if not, see: using SQL*Plus) and have saved the file to your “Documents” folder, type:

 @  u:\sqlload

and press RETURN.

If you have saved your file somewhere else, for example, a memory stick, then replace the u:\ with the location of your file, including any subfolders, e.g., e:\oracle\sqlload

This sets up your database on the central server and this same database can be accessed from the MI labs, other University labs and from home.

Note, this command only needs to be executed once. If you re-run it, the command will drop the tables you previously created, thereby losing any changes you may have made to them.

3. List your tables

To check that your tables have been setup correctly, type:

 select table_name from user_tables;

If the system responds with:

TABLE_NAME
--------------------------------------------------------------------------
CUSTOMER
DEPT
EMP
SALGRADE

Then your tables are now ready to use. If it returns with:

 no rows selected

It means something went wrong and you need to carry out the previous steps again.

user_tables refers to a data dictionary table, which is a set of tables which allows you to query what objects you own. See <section 22> for further information on the Data Dictionary.


Sample data set

To see what the data looks like, refer to this page: Oracle Sample Dataset

Next Step

This concludes setting up the Oracle database. Return now to the Workbook for the next section.