2 Day Developer > Using SQL > Using Data Definition Langu... > Creating a Table With SQL
Creating a Table With SQL |
Previous |
Next |
To create a database object, such as a table, use the SQL CREATE
statement as shown in Example: Creating a Simple Table Using SQL. When you create a table, you need to provide datatypes for each column. For more information about tables, see "Managing Tables".
Creating a Simple Table Using SQL
-- create a simple table for keeping track of birthdays CREATE TABLE my_birthdays ( first_name VARCHAR2(20), last_name VARCHAR2(25), bday_date DATE );
Optionally, you can provide NOT
NULL
constraints, as shown in Example: Creating a Table With NOT NULL Constraints Using SQL. The NOT
NULL
constraint is discussed in "NOT NULL Constraint".
Creating a Table With NOT NULL Constraints Using SQL
-- create a table with NOT NULL constraints in the HR schema CREATE TABLE personal_info ( employee_id NUMBER(6,0) NOT NULL, birth_date DATE NOT NULL, social_security_id VARCHAR2(12) NOT NULL, marital_status VARCHAR2(10), dependents_claimed NUMBER(2,0) DEFAULT 1, contact_name VARCHAR2(45) NOT NULL, contact_phone VARCHAR2(20) NOT NULL, contact_address VARCHAR2(80) NOT NULL );
For information about creating a table with the Object Browser page, see "Creating a Table".