SQL tutorial | Interview questions | Oracle
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Creating Tables in SQL

Go down

Creating Tables in SQL Empty Creating Tables in SQL

Post by Micheal Sun Jan 31, 2010 12:19 am

The SQL command for creating an empty table has the following form:
create table <table> (
<column 1> <data type> [not null] [unique] [<column constraint>],
. . . . . . . . .
<column n> <data type> [not null] [unique] [<column constraint>],
[<table constraint(s)>]
);
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
6
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.

Micheal
Admin

Posts : 243
Join date : 2010-01-10

http://sql-tutorial.co.cc

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum