Search tables for value

Search for any column in any table that has a specific value where the column is a specific data type 12345678910111213DECLARE @SearchGUID UNIQUEIDENTIFIER = ‘BF3CBDB9-39A9-487D-8754-FC4120E4D993’; DECLARE @SQL NVARCHAR(MAX) = ”; …

SQL Server High CPU

Troubleshoot high CPU from specific queries https://learn.microsoft.com/en-us/troubleshoot/sql/database-engine/performance/troubleshoot-high-cpu-usage-issues Identify Queries Contributing to High CPU 12345678910111213141516171819202122232425SELECT TOP 10 s.session_id,            r.status,            r.cpu_time,   …

MS SQL Server Database Logging

In order to enable MSSQL Server database logging into the MSSQL Log 1). Open an elevated Poershell prompt 2). Run the query 1Invoke-Sqlcmd -Query "EXEC xp_instance_regwrite N’HKEY_LOCAL_MACHINE’, N’Software\Microsoft\MSSQLServer\MSSQLServer’, N’AuditLevel’, REG_DWORD, …

Database Repair MSSQL

Command: 1DBCC CHECKDB Returned: 123456789101112DBCC results for ‘AP_TypeLocations’. There are 3004 rows in 14 pages for object "AP_TypeLocations". Msg 8976, Level 16, State 1, Line 1 Table error: Object ID …

MSSQL Transaction Log Full

Check Log Space in MSSQL Server 1DBCC SQLPERF(‘logspace’) If the error occurs: The transaction log for database ‘AIMS’ is full due to ‘ACTIVE_TRANSACTION’ Alter the logging levels of the database …

MS SQL Determine Enterprise Features

Use the following to determine if your MSSQL database has features only available inĀ enterprise versions of the product (partitioning, compression, encryption, etc). 1select * from sys.dm_db_persisted_sku_features

TSQL Determine Table Size

Determine the size of database tables in a MSSQL Server Database. 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647SELECT     DB_NAME() AS DatabaseNase ,     GETDATE() AS DateCreated ,     TableName,     Rows …

TSQL is decimal an INT

Determine if a decimal number can be converted to an INT without any loss of precision. Check if either of the rightmost two digits are non-zero 123substring(convert(varchar(10), a.DebitAmount), len(convert(varchar(10), a.DebitAmount)) …

Determine Disk Size of Tables

To see the disk size of database tables in MSSQL: 12345678910111213141516171819202122SELECT     t.NAME AS TableName,     p.rows AS RowCounts,     SUM(a.total_pages) * 8 AS TotalSpaceKB,     …