0% found this document useful (0 votes)
20 views2 pages

Create A Table: Applies To

Crear tabla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

Create A Table: Applies To

Crear tabla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Create a Table

APPLIES TO:   SQL Server   Azure SQL Database   Azure Synapse


Analytics   Parallel Data Warehouse

To create a table, you must provide a name for the table, and the names and data
types of each column in the table. It is also a good practice to indicate whether null
values are allowed in each column. To create a table, you must have the CREATE
TABLE permission, and the ALTER SCHEMA permission on the schema that will contain
the table. The db_ddladmin fixed database role has these permissions.

Most tables have a primary key, made up of one or more columns of the table. A
primary key is always unique. The Database Engine will enforce the restriction that
any primary key value cannot be repeated in the table.

For a list of data types and links for a description of each, see Data Types (Transact-
SQL).

 Note

The Database Engine can be installed as case sensitive or non-case sensitive. If the
Database Engine is installed as case sensitive, object names must always have the
same case. For example, a table named OrderData is a different table from a table
named ORDERDATA. If the Database Engine is installed as non-case sensitive, those
two table names are considered to be the same table, and that name can only be
used one time.

Switch the Query Editor connection to the TestData database

In a Query Editor window, type and execute the following code to change your
connection to the TestData database.

SQLCopy
USE TestData
GO
Create the table

In a Query Editor window, type and execute the following code to create a table
named Products. The columns in the table are named ProductID, ProductName, Price,
and ProductDescription. The ProductID column is the primary key of the
table. int, varchar(25), money, and varchar(max) are all data types. Only
the Price and ProductionDescription columns can have no data when a row is
inserted or changed. This statement contains an optional element ( dbo.) called a
schema. The schema is the database object that owns the table. If you are an
administrator, dbo is the default schema. dbo stands for database owner.

SQLCopy
CREATE TABLE dbo.Products
(ProductID int PRIMARY KEY NOT NULL,
ProductName varchar(25) NOT NULL,
Price money NULL,
ProductDescription varchar(max) NULL)
GO

You might also like