Tuesday 20 August 2013

How to create Tables in Oracle

The SQL command for creating an empty table has the following form:
create table (
[not null] [unique] [],
. . . . . . . . .
[not null] [unique] [],
[]
);
For each column, a name and a data type must be specified and the column name must be
unique within the table definition. Column definitions are separated by comma. There is no
difference between names in lower case letters and names in upper case letters. In fact, the
only place where upper and lower case letters matter are strings comparisons. A not null
constraint is directly specified after the data type of the column and the constraint requires
defined attribute values for that column, different from null.
The keyword unique specifies that no two tuples can have the same attribute value for this
column. Unless the condition not null is also specified for this column, the attribute value
null is allowed and two tuples having the attribute value null for this column do not violate
the constraint.
Example: The create table statement for our EMP table has the form
create table EMP (
EMPNO number(4) not null,
ENAME varchar2(30) not null,
JOB varchar2(10),
MGR number(4),
HIREDATE date,
SAL number(7,2),
DEPTNO number(2)
);
Remark: Except for the columns EMPNO and ENAME null values are allowed.

No comments:

Post a Comment