The SQL CREATE TABLE statement is the SQL command that adds a new table to an SQL database. Tables are a basic unit of organization and storage of data in SQL. Each table tends to represent an entity such as a customer, product, code or event. A table is similar to a file in a non-database system.
Tables are organized into rows and columns. For example, a customer table would likely have a seperate row for each customer. Columns are attributes that describe a row. For example, a row in a customer table would have columns like customer_name, customer_nbr, account_balance_amt and established_date.
Anytime you want to add a new table to the database you would use the SQL CREATE TABLE statement.
The SQL CREATE TABLE command is used as follows.
SQL CREATE TABLE Statement Syntax
The number of characters that can make up SQL table names and column names varies by DBMS. In many cases the limit is 30 characters. The leading character of the name must be alphabetic - not a number or special character. The name of a new table can not duplicate the name of an existing table and should not be the same as a SQL reserved word. The underscore character can be used to improve readability. The same column name can not be repeated within a table. List elements are seperated by commas.
Here are some example datatypes:
SQL Datatype | Description |
integer(size) int(size) smallint(size) tinyint(size) | Integers |
decimal(size,decimals) numeric(size,decimals) | Numbers with decimals |
char(size) | Fixed length character string |
varchar(size) | Variable length character string |
date | A date in yyyymmdd format |
SQL CREATE TABLE Statement Example
The following example creates a table named product with columns named product_nbr, product_name, product_status_code, start_date, end_date and raw_material_cost_amt.
This SQL CREATE TABLE Statement is executed:
Advertisements:
Infogoal.com is organized to help you gain mastery.
Examples may be simplified to facilitate learning.
Content is reviewed for errors but is not warranted to be 100% correct.
In order to use this site, you must read and agree to the
terms of use, privacy policy and cookie policy.
Copyright 2006-2020 by Infogoal, LLC. All Rights Reserved.