SQL Server 2016: Create a Table from an SQL Script
In SQL Server, you can create tables by running an SQL script with the CREATE TABLE
statement.
Having just created a table via the SSMS GUI, we will now create a table (or two) using an SQL script.
To create a table using SQL, use the CREATE TABLE
statement. Provide the column names and their data types, plus any other properties as required.
-
Open a New Query Window
-
Run the SQL Script
-
Check that the Table was Created
Table Options
The CREATE TABLE
statement accepts many additional options that allow you to specify the exact properties of the table.
There are too many to go into detail in this tutorial, but they include options for encryption, replication, indexes, and more.
However, we will be covering one of these options next — foreign key constraints — when we create a relationship between tables.