Skip to content

Instantly share code, notes, and snippets.

@DylanKnevitt
DylanKnevitt / SelectAllTables.sql
Last active December 18, 2015 02:49
A basic loop to select all columns from all tables/views in a database, useful with the Database Engine Tuning Advisor on SSMS for a very basic idea of what indices and statistics are missing.
DECLARE TOCURSOR CURSOR FOR
SELECT('SELECT * FROM [' + name + '];')
FROM sys.tables
--FROM sys.views
ORDER BY name ASC
DECLARE @query NVARCHAR(MAX)
OPEN TOCURSOR
FETCH NEXT FROM TOCURSOR INTO
@DylanKnevitt
DylanKnevitt / SelectAll.sql
Last active December 18, 2015 02:58
A loop to select all tables and views in a database. I will add more to this, such as executing stored procedures, doing inserts, updates, deletes and whatever other operations I can think of, as time goes on. This is all to test every object in your database with the Tuning advisor.
DECLARE TOCURSOR CURSOR FOR
SELECT('SELECT * FROM ' + name + ';')
FROM sys.tables
UNION ALL
SELECT('SELECT * FROM ' + name + ';')
FROM sys.views
DECLARE @query NVARCHAR(MAX)
@DylanKnevitt
DylanKnevitt / GetColumnAndTableByName
Last active August 29, 2015 14:06
Get Column and Table by name
SELECT * FROM sys.tables st
INNER JOIN sys.columns sc on sc.object_id = st.object_id
WHERE
sc.name = '' and st.name = ''
@DylanKnevitt
DylanKnevitt / LCD.md
Last active August 29, 2015 14:11
j5 LCD Documentation

The LCD class constructs an object that represents an LCD Display.

Parameters

  • options An object of property parameters
Property Name Type
@DylanKnevitt
DylanKnevitt / LCD_HowTo.md
Created December 10, 2014 17:02
LCD How To Guide
@DylanKnevitt
DylanKnevitt / FindNoPrimaryKeys.sql
Created September 21, 2015 09:21
Find all tables that do not have any Primary Keys
SELECT * FROM sys.tables st
LEFT JOIN sys.key_constraints kc on kc.parent_object_id = st.object_id and kc.type = 'PK'
WHERE kc.name is null
order by st.name asc
@DylanKnevitt
DylanKnevitt / ConvertFloatsToDecimal.sql
Last active January 19, 2016 07:38
I needed to convert a float type to decimal. I then thought, why not change them all! This generates the scripts that need to be run in order to do so.
--Find Type Here
--SELECT * FROM sys.Types
DECLARE @CurrentTypeName NVARCHAR(50) = 'float'
DECLARE @NewTypeName NVARCHAR(50) = 'decimal'
DECLARE @Nullable VARCHAR(8) = 'NOT NULL'
--Type specific Variables
DECLARE @DecimalPrecisionAndScale NVARCHAR(10) = '(18,2)'