SSMS Shortcuts:
New Query Window: ctrl + N
Toggle between open query windows: ctrl + F6
Toggle between tabs on results window: F6
Close query window: ctrl + F4
Results Pane on/off: ctrl + R
Object Explorer: F8
Registered Servers: ctrl + alt + G
Run Query: F5 (or ctrl + E)
Stop running query: alt + break OR fn + alt + B
Change database: ctrl + U
Template Explorer: ctrl + alt + T
Estimated Execution Plan: ctrl + L
Actual Execution Plan: ctrl + M
Comment out selected code: ctrl + K + C
Uncomment selected code: ctrl + K + U
Custom Shortcuts: I’ve created custom shortcuts for some items
Change Connection (Query.ChangeConnection): Ctrl + Q, Ctrl + C
SQL CMD Mode (Query.SQLCMDMode): Alt + C
CONVERT – Date Codes:
23: yyyy-mm-dd (ISO8601)
101: mm/dd/yyyy
110: mm-dd-yyyy
112: yyyymmdd
120: yyyy-mm-dd hh:mi:ss
121: yyyy-mm-dd hh:mi:ss.mmm
127: yyyy-mm-ddThh:mi:ss.mmmZ
Format Dates – Custom:
yyyy-MM-dd HH:mm:ss.fff – 2019-04-04 17:25:02.193
gg – Era (AD/BC)
tt – AM/PM
zz – Hours offset from UTC
Custom date and time format strings
Format Number:
FORMAT(123, ‘00000’) = 00123
FORMAT(123, ‘#####’) = 123
Hex: FORMAT(255, ‘X’) = FF
Percent: FORMAT(.45, ‘P’) = 45.00 %
Currency: FORMAT(123.45, ‘C’) = $123.45
T-SQL:
CHARINDEX (search phrase, text to search, (optional) start location int)
SUBSTRING (text to search, start location (int), length to return (int))
Check Constraint: ALTER TABLE TestTable ADD CONSTRAINT chkValidEndDate CHECK (EndDate >= StartDate);
Foreign Key: ALTER TABLE dbo.Table ADD CONSTRAINT fk_name FOREIGN KEY (column list) REFERENCES dbo.ReferencedTable (column list);
Primary Key: ALTER TABLE TestTable ADD CONSTRAINT PK_TestTable PRIMARY KEY (ID);
Throw Error (Error #, Message, State): THROW 50001, ‘@StartValue should be a positive number’, 1;
Create Index: CREATE INDEX idx_TestTable_ID ON TestTable (TestTable);
Reference a list of values as a table:
SELECT *
FROM (VALUES
(1, ‘Sally’),
(2, ‘Doug’)
) AS t(RecordID, FirstName);
SSMS Options: Options I like to set in SSMS
Tools – Options – Text Editor – Transact-SQL
Line Numbers (Check to enable)
Word Wrap (Check to enable)
SQL Server Configuration Manager:
Search for ‘Computer Management’ – Under ‘Services and Applications’
Links