The syntax for creating a table logically follows many of the same steps that you did when using the GUI, but it will all be done with the statements. This script will exactly replicate everything that you did with the GUI:
Breaking the script into separate lines, it’s easy to see how the T-SQL commands perform the actions defined in the GUI (it also makes it easier to read). The
CREATE TABLE statement in this context is self-explanatory. After that, you’re defining the schema and the table name. Within the parenthesis, you define each of the columns. First is the name of the column followed by the data type and, for most columns, the ability of the column to store
NULL values. The table will be stored on the
PRIMARY file group.
The first column,
PersonID, is defined as an identity value through the
IDENTITY keyword. It also includes the increment and seed values within the parenthesis, just like from the GUI.
If you wanted to delete this table through T-SQL, the command is:
DROP TABLE dbo.Person;
That’s really all there is to it. The T-SQL language is very easy to use and is pretty straightforward when it comes to data definition language (DDL). It gets very complex when we start to talk about data manipulation language (DML). That’ll be saved for more blog posts later in the series.
The next post will drill down on the various data types available within SQL Server.