This website uses cookies that help the website function and also to track how you interact with our website. Enabling cookies helps us provide a better and optimized user experience. This website also includes third party cookies that are utilized in the analysis of how you interact with our website and for advertising purposes. The cookies will be stored in your comouter and the selected cookie consent status will be valid for a period of five years. You are provided with an option to change your cookie consent status at any point in time.
Creating a table in SQL Using the CREATE TABLE statement EXAMPLE - Creating a table using a SELECT INTO statement Basic CREATE TABLE
► SQL Programming
SQL Statements
Basic CREATE TABLE
The CREATE TABLE statement is used to create a new table in an SQL Server Database.
When creating a table, the table name and the column information are required.
A basic CREATE TABLE statement follows the following syntax:
Syntax of a Basic CREATE TABLE Statement to create a table in SQL
               
CREATE TABLE tableName ( Column_Information);
               
            
A basic CREATE TABLE statement only requires the table name, the column name and the column datatype for each column present in the table.


Note
You cannot create a table with no columns.
Line breaks in a statement are allowed. As long as the “;” and parenthesis are in the correct positions within your statement.
The VARCHAR datatype is used for short string data.
The INT datatype is used for integers.


Example:
In this example we create a table called Employees.
The Employees table consists of 4 columns
EmployeeName, datatype VARCHAR
EmployeeLastName, datatype VARCHAR
EmployeeAge, datatype INT
EmployeeDepartment, datatype VARCHAR
Create Employees Table Statement
               
CREATE TABLE Employees (EmployeeName VARCHAR,
                        EmployeeLastName VARCHAR, 
                        EmployeeAge INT, 
                        EmployeeDepartment VARCHAR);
               
            
The CREATE statement results in an empty table (no row data).
Copyright © 2024 AppliedEngr