|Lesson 13||Using SQL to create Tables|
|Objective|| Explain how to use SQL to create Database Tables|
Using SQL to create Tables
Once you have created a schema to hold your tables, you can enter the SQL statements to create those tables.
Following is the format of the SQL statement used to create a table:
CREATE TABLE TableName
( Column01Name Column01DataType Column01Constraints
Column02Name Column02DataType Column02Constraints…
PRIMARY KEY (ColumnXX) FOREIGN KEY (ColumnXX))
Indenting the column and other statements is not mandatory, but it does make the table's specification easier to read.
The ColumnName part of the statement is self-explanatory.
The ColumnDataType depends on the type of data the column will store.
A partial list of data types (or data domains) was presented earlier in this course. Again, the list of available domains will not be the same for every RDBMS. The final element lists the constraints on the column. Possible constraints for a column include whether it has a default value or any validation rules (e.g., the field must contain a value greater than zero).
The next lesson explains how to use SQL to build the database.