Monday, June 14, 2010

Maximum Capacity Specifications for Database Objects in SQL Server 2008 R2

The following table specify the maximum sizes and numbers of various Database Objects defined in SQL Server 2008 components:

Database objectMaximum sizes/numbers (32-bit)Maximum sizes/numbers (64-bit)
Columns per index1616
Columns per Primary Key1616
Columns per Foreign Key1616
Columns per SELECT statement40964096
Columns per INSERT statement40964096
Database Size524,272 TB524,272 TB
No of Databases per SQL Server instance32,76732,767
Files per database32,76732,767
Maximum File size (data)16 TB16 TB
Maximum File size (log)2 TB2 TB
Foreign key references per table253253
Identifier length in characters128128
Nested stored procedure levels3232
Nested subqueries3232
Nested trigger levels3232
REFERENCES per table253253
Nonclustered indexes per table999999
xml indexes per table249249
Parameters per stored procedure21002100
Parameters per user-defined functions21002100
Partitions per partitioned table or index10001000
Btach Size65,536 * Network Packet Size65,536 * Network Packet Size
Bytes per GROUP BY, ORDER BY8,0608,060
Bytes per key (PK, FK, Index)900900
Bytes per row8,0608,060
Bytes in source text of a stored procedurelesser than batch size or 250 MBlesser than batch size or 250 MB
Bytes per varchar(max), xml, text, or image column2^31-12^31-1
Characters per ntext or nvarchar(max) column2^30-12^30-1

Reference: BOL, here is link

Wednesday, June 9, 2010

Explain Candidate Key, Alternate Key, and Composite Key

A Candidate Key is one that can uniquely identify each row of a table.
Generally a candidate key becomes the Primary Key of the table.

If the table has more than one Candidate Key, one of them will become the Primary Key, and the rest are called Alternate Keys.

A key formed by combining at least two or more columns is called Composite Key.

What's the difference between a primary key and a unique key constraints?

Both Primary Key and Unique Key enforce uniqueness of the column on which they are defined. But by default primary key creates a clustered index on the column, where are unique creates a nonclustered index by default.

Another major difference is that, primary key doesn't allow NULLs, but unique key allows one NULL.

Primary key:
  1. Primary key used to uniqly identify each row in Table.
  2. Primary key does not allow duplicate values and Null values.
  3. Primary key is default Clustered Indexes
  4. One table can have only one Primary key.

 Unique Key:

  1. Unique Key is used to uniqly identify each row in Table.
  2. Unique Key does not allow duplicate values but allowes only one Null value.
  3. Unique Key is default Non- Clustered Indexe
  4. One table can have more than one Unique Keys.