Skip to content
Archive of entries posted on July 2009

SQL Server Bigint Max Value

The maximum value for an Bigint in SQL Server is: -9223372036854775808 through 9223372036854775807 And the byte size is 8 bytes other maximum values: Int: -2147483648 through 2147483647 (4 bytes) SmallInt: -32768 through 32767 (2 bytes) TinyInt: 0 through 255 (1 byte)

SQL Server Max Int Value

The maximum value for an integer in SQL Server is: -2147483648 through 2147483647 And the byte size is 4 bytes other maximum values: BigInt: -9223372036854775808 through 9223372036854775807 (8 bytes) SmallInt: -32768 through 32767 (2 bytes) TinyInt: 0 through 255 (1 byte)

Add Column Default Value

In SQL Server there are two ways to add a column with a default value. Add Default Value to Existing Column — Add default to existing column DateOfHire: ALTER TABLE [dbo].[Employees] ADD DEFAULT (getdate()) FOR [DateOfHire] — Add default value to existing column IsTerminated ALTER TABLE [dbo].[Employees] ADD DEFAULT ((0)) FOR [IsTerminated] Add New Column [...]

SQL Server Hosting

Stub created to discuss SQL Server Hosting companies. Discuss hosts through link below.

Add Foreign Key

To Add a foreign key to a column in an existing table, use ALTER TABLE ADD CONSTRAINT ALTER TABLE dbo.President_Lookup ADD CONSTRAINT fk_PresidentID FOREIGN KEY (PresidentID) REFERENCES dbo.Presidents (PresidentID)

Case Statement

The SQL Server case statement is a conditional statement that returns a single value based on the evaluation of a statement. Case statements can be used in a SELECT list, WHERE clause and even an ORDER BY clause. Case statement can also be nested. This provides a lot of pliability for evaluating multiple expressions. We’ll [...]

Add Constraint

To add a constraint to an existing table use the alter table statement with the add constraint command. There are four different types of constraints: Primary Key Constraints – Enforces unique values for specified column, can be referenced. Foreign Key Constraints – Enforces a reference to a primary key Unique Constraints – Ensures unique values [...]

Add Index

To add an index in SQL Server use the CREATE INDEX statements. When adding indexes remember there can only be one clustered index per table. The main options when creating an index are clutered or nonclustered or unique vs non unique. Using SQL 2005+ you can also specify columns to include at the leaf level [...]

Add Primary Key

In order to add a primary key to an existing table we need to use the Alter Table command. Add a primary key for a new column ALTER TABLE dbo.Presidents ADD PresidentID int NOT NULL IDENTITY(1,1) CONSTRAINT PK_PresidentID PRIMARY KEY NONCLUSTERED Note however that the ordering of the identity field will not be predictable for [...]

Add User Role

Roles can be created inside a database that encapsulate permissions. These permissions can be granular (as in denying read permissions to one table), or they can be global (as in being able to write to all tables). Using the CREATE ROLE state we will walk through some typical examples. First of all, we need to [...]