MY mENU


Wednesday 7 March 2012

Create Command IN DBMS


Creating a Table:
A Table is a collection of rows and columns. Data in relational model is stored in tables. Before a table is created the following factors of a table are to be finalized.

  1. What data table is supposed to store.
  2. The name of the table. It should depict the content of the table.
  3. What are the columns that table should contains
  4. The name, data type and maximum length of each column of the table.
  5. What are the rules to be implemented to main data integrity of the table.

The following is an example of creation of COURSES table.  The following CREATE TABLE command is used to create COURSES table.
SQL> create table COURSES ( ccode varchar2(5),name varchar2(30),duration number(3),fee number(5), prerequisite varchar2(100));
Table Created

Rules to be followed for names:
The following are the rules to be followed while naming an Oracle Object. These rulesare applicable for name of the table and column.

  1. The name must begin with a letter - A-Z or a-z.
  2. Letters, digits and special characters – underscore (_), $ and # are allowed.
  3. Maximum length of the name is 30 characters.
  4. It must not be an SQL reserved word.
  5. There should not be any other object with the same name in your account.
DESCRIBE:
You can display the structure of a table using SQL*PLUS command DESCRIBE. It displays then name, datatype and whether the column can store null value for each column of the table.

Syntax:  DESC[RIBE] objectname
Displays the column definitions for the specified object. The object may be a table, view,
synonym, function or procedure.
To display the structure of COURSES table, enter:

SQL> DESC COURSES
Name                           Null? Type
---------------------------------------------- -------- ----------
CCODE                    NOT NULL VARCHAR2(5)
NAME                       VARCHAR2(30)
DURATION                 NUMBER(3)
FEE                              NUMBER(5)
PREREQUISITE           VARCHAR2(100)

DESCRIBE is an SQL*Plus command and can be abbreviated to DESC.



No comments:

Post a Comment