Vous êtes sur la page 1sur 5

Creating and

Altering Tables
Designing Tables
Tables provide structure for data
Columns
Metadata
Names for data
Data types
Control data placed into fields
Implicit validation
Rows
Actual data
Table Concepts
bigint
8 bytes
int
4 bytes
smallint
2 bytes
tinyint
1 byte
Integer Types
money
8 bytes
smallmoney
4 bytes
numeric(p,s) & decimal(p,s)
Precision
Total number of digits
Scale
Digits after decimal
float(x)
Configurable size in bits
Other Number Types
date
time
datetime & datetime2
datetimeoffset
datetime2 with GMT offset
Date and Time Types
All have a configurable length
Specifies the number of characters
8,000 without unicode
4,000 with unicode
Variable character types can use max
Up to 2GB of storage
Options
Variable length (var)
Unicode (n)
Data types
char(size)
nchar(size)
varchar(size or max)
nvarchar(size or max)
Character Data Types
binary(size)
Fixed size up to 8,000 bytes
varbinary(size or max)
Variable size up to 8,000 bytes
Use max keyword for up to 2GB of storage
Binary Data Types
text
varchar(max)
ntext
nvarchar(max)
image
varbinary(max)
Deprecated Data Types
32 hex character identifiers
Algorithm guarantees uniqueness
Unique identifier datatype
Globally Unique Identifiers (GUIDs)
Managing Tables
CREATE TABLE <name>
(
<columnName> <datatype> [NULL | NOT NULL]
, ...
);
Creating Tables
ALTER TABLE <name>

Adding a column
ADD <columnName> <datatype> [NULL | NOT NULL]
Changing a data type
ALTER COLUMN <columnName> <newDatatype> [NULL | NOT NULL]
Removing a column
DROP COLUMN <columnName>
Altering Tables

Vous aimerez peut-être aussi