SQL CREATE TABLE |
SQL Sample Code - SQL CREATE TABLE Statement |
The statement below creates a database table. You must have created a database before creating a table. See SQL CREATE DATABASE to learn how to do this.
| CREATE TABLE table_name ( column_name1 column1_data_type, column_name2 column2_data_type, column_name3 column3_data_type, column_name4 column4_data_type, .... ); |
See the SQL samples section below for an explanation of the CREATE TABLE statement.
What does the SQL CREATE TABLE Statement do? |
The SQL CREATE TABLE statement creates a table within a database.
Sample – SQL CREATE TABLE |
In this SQL sample we will create a table called ‘tblCompany’ with 3 columns; Company_ID, Company_Name and Sales.
Use the CREATE TABLE statement below:
| CREATE TABLE tblCompany (Company_ID int CompanyName varchar(255) Sales int); |
The table will look like this:.
| Company_ID | CompanyName | Sales |
The ‘int’, ‘varchar(255)’ elements of the statement are the data types. To learn more about these and more go to the Data Type sections of this website.
| Data-Type | Description (MySQL) |
| int (Integer) | A normal-size integer. The signed range is -2147483648 to 2147483647. |
| varchar | Character String Value. The length can be specified as a value from 0 to 65,535. |
Related SQL Sample Code:
|
|