Creating Tables in SQL
Creating Tables in SQL
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.
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.
Similar topics
» creating Views in SQL
» steps to help you creating a new database manually from beginning to end
» How To List All Tables in Your Schema?
» How To Get a List of All Tables in the Database?
» Accessing tables of other users in SQL
» steps to help you creating a new database manually from beginning to end
» How To List All Tables in Your Schema?
» How To Get a List of All Tables in the Database?
» Accessing tables of other users in SQL
Permissions in this forum:
You cannot reply to topics in this forum
Sun Jan 31, 2010 12:35 am by Micheal
» Accessing tables of other users in SQL
Sun Jan 31, 2010 12:34 am by Micheal
» Grouping commands in SQL
Sun Jan 31, 2010 12:32 am by Micheal
» Operations on Result Sets in SQL
Sun Jan 31, 2010 12:31 am by Micheal
» Subqueries in SQL
Sun Jan 31, 2010 12:30 am by Micheal
» Joining Relations in SQL
Sun Jan 31, 2010 12:28 am by Micheal
» Delete comand in SQL
Sun Jan 31, 2010 12:27 am by Micheal
» Update command in SQL
Sun Jan 31, 2010 12:26 am by Micheal
» Insert command in SQL
Sun Jan 31, 2010 12:23 am by Micheal