Database Reference
In-Depth Information
We once used timestamp to archive a large database. Each night we
would run a job to grab all the rows from all the tables where the time-
stamp was greater than the last row copied the night before. Timestamps
require 8 bytes of storage, and remember, 8 bytes can add up fast if you
add timestamps to all your tables.
Uniqueidentifier
The uniqueidentifier data type is probably one of the most interesting data
types available, and it is the topic of much debate. Basically, a uniqueiden-
tifier column holds a GUID—a string of 32 random characters in blocks
separated by hyphens. For example, the following is a valid GUID:
45E8F437-670D-4409-93CB-F9424A40D6EE
Why would you use a uniqueidentifier column? First, when you gen-
erate a GUID, it will be a completely unique value and no other GUID in
the world will share the same string. This means that you can use GUIDs
as PKs on your tables if you will be moving data between databases. This
technique prevents duplicate PKs when you actually copy data.
When you're using uniqueidentifier columns, keep in mind a couple of
things. First, they are pretty big, requiring 16 bytes of storage. Second, un-
like timestamps or identity columns (see the section on primary keys later
in this chapter), a uniqueidentifier does not automatically have a new
GUID assigned when data is inserted. You must use the NEWID function
to generate a new GUID when you insert data. You can also make the de-
fault value for the column NEWID(). In this way, you need not specify
anything for the uniqueidentifier column; SQL Server will insert the
GUID for you.
Xml
The xml data type is a bit outside the scope of this topic, but we'll say a few
words about it. Using the xml data type, SQL Server can hold Extensible
Markup Language (XML) data in a column. Additionally, you can bind an
XML schema to the column to constrain the XML data being stored. Like
the max data types, the xml data type is limited to 2GB of storage.
Table
A table data type can store the result set of T-SQL statements for process-
ing later. The data is stored in a similar fashion to the way an entire table
is stored. It is important to note that the table data type cannot be used on
Search WWH ::




Custom Search