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. Here is the proof (Thanks to BJ) [cc lang=”sql”] DECLARE @max bigint, @min bigint SELECT @max = 127, @min = 1 WHILE @min = 1 BEGIN BEGIN TRY SELECT @max = @max * 2 + 1 END TRY BEGIN CATCH BEGIN TRY SET @min = -1 – @max END TRY BEGIN CATCH SET @min = 0 END CATCH END CATCH END SELECT @min , @max [/cc] other maximum values: Int: -2147483648 through 2147483647 (4 bytes) SmallInt: -32768 through 32767 (2 bytes) TinyInt: 0 through 255 (1 byte) Continue reading ...

SQL Server Max Int Value

The maximum values for an integer in SQL Server are: -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) Here is the proof (thanks to BJ): [cc lang=”sql”] DECLARE @max int, @min int SELECT @max = 127, @min = 1 WHILE @min = 1 BEGIN BEGIN TRY SELECT @max = @max * 2 + 1 END TRY BEGIN CATCH BEGIN TRY SET @min = -1 – @max END TRY BEGIN CATCH SET @min = 0 END CATCH END CATCH END SELECT @min , @max [/cc]

Add Column Default Value

You can add a default value to a new OR existing column in SQL Server without dropping it. Specifying a default constraint should not cause any blocking. Only when setting a column to NULL OR NOT NULL will cause blocking. But to set the NULLABLE attribute, you need to use ALTER COLUMN instead. When adding this default value, it’s always best to specify the constraint name. If you don’t the system will generate a random constraint name instead. This can wreak havoc because this default constraint name will not be the same name generated on your dev / stage / production systems. This is why it’s always best to specify the name. Add Default Value to Existing Column [cc lang=”sql”] — Add default to existing column DateOfHire: ALTER TABLE [dbo].[Employees] ADD CONSTRAINT DF_Employees_DateOfHire DEFAULT (GETDATE()) FOR [DateOfHire] — Add default value to existing column IsTerminated ALTER TABLE [dbo].[Employees] ADD CONSTRAINT DF_Employees_IsTerminated DEFAULT (0) FOR [IsTerminated] [/cc] Add New Column with Default Value [cc lang=”sql”] — Add new column DateOfHire with default ALTER TABLE Employees ADD DateOfHire datetime CONSTRAINT DF_Employees_DateOfHire DEFAULT (GETDATE()) — Add new column IsTerminated with default (no constraint name specified NOT RECOMMENDED) ALTER TABLE Employees ADD IsTerminated datetime DEFAULT (0) [/cc] Add Default Value with Create Table [cc lang=”sql”] CREATE TABLE [dbo].[Employees] ( [EmployeeID] [int] IDENTITY(1,1) NOT NULL, [FirstName] [varchar](50) NULL, [LastName] [varchar](50) NULL, [SSN] [varchar](9) NULL, — Add default of zero [IsTerminated] [bit] NOT NULL CONSTRAINT DF_Employees_IsTerminated DEFAULT (0) , — Add default of getdate() [DateAdded] [datetime] […] Continue reading ...

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 [cc lang=”sql”] ALTER TABLE dbo.President_Lookup ADD CONSTRAINT fk_PresidentID FOREIGN KEY (PresidentID) REFERENCES dbo.Presidents (PresidentID) [/cc] Continue reading ...

Featured Articles

 Site Author

  • Thanks for visiting!
css.php