Tuesday, August 08, 2017

Database Fundamentals #7: Create a Table Using T-SQL

DZone Database Zone
Database Fundamentals #7: Create a Table Using T-SQL

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:

CREATE TABLE dbo.Person ( PersonID int IDENTITY(1,1) NOT NULL, FirstName varchar(50) NOT NULL, LastName varchar(50) NOT NULL, DateOfBirth date NULL ) ON [PRIMARY];

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.

No comments:

Fun With SQL: Functions in Postgres

DZone Database Zone Fun With SQL: Functions in Postgres In our previous  Fun with SQL  post on the  Citus Data  blog, we covered w...