select'[' + p.TABLE_SCHEMA + '].[' + p.TABLE_NAME + ']' as [table],c.COLUMN_NAME,ident_current(p.TABLE_SCHEMA + '.' + p.TABLE_NAME) as MaxID,cls.DATA_TYPE,cast(100 - isnull(ident_current(p.TABLE_SCHEMA + '.' + p.TABLE_NAME), 0) * 100 /case cls.DATA_TYPEwhen 'int' then 2147483647when 'smallint' then 32767when 'tinyint' then 128end as decimal(4, 1))as [% of range left]fromINFORMATION_SCHEMA.TABLE_CONSTRAINTS pinner join INFORMATION_SCHEMA.KEY_COLUMN_USAGE con c.TABLE_NAME = p.TABLE_NAMEand c.CONSTRAINT_NAME = p.CONSTRAINT_NAMEinner join INFORMATION_SCHEMA.COLUMNS clson c.TABLE_NAME = cls.TABLE_NAMEand c.COLUMN_NAME = cls.COLUMN_NAMEwherep.CONSTRAINT_TYPE = 'PRIMARY KEY'and cls.DATA_TYPE in ('int', 'smallint', 'tinyint')order by5 asc
Monday, 30 April 2018
Primary Key Capacity
Use the following SQL to determine how "full" your primary keys are, based on the number of existing values, and the data type used:
Subscribe to:
Posts (Atom)
Updating massive amount of rows whilst avoiding blocking
The following SQL is a good means to split an update on a massive table into smaller chunks, whilst reducing blocking. The method is to upda...
-
Microsoft Distributed Transaction Coordinator (abbreviated to MSDTC, or DTC) is usually very quick and simple to set up. However, it isn...
-
Migrations between SQL Servers can be laborious, and doing them manually leaves a lot of room for human error. Scripting a migration using t...
-
Scheduling SSIS packages from SQL Agent can produce the following error on a new installation of SQL Server: “Connecting to the Integration...