Skip to content

Commit 9fec320

Browse files
Merge pull request #4 from DigitalDuquette/general-improvements
Solves open issues...
2 parents b571775 + 1067b1e commit 9fec320

File tree

3 files changed

+72
-24
lines changed

3 files changed

+72
-24
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# Azure Data Studio Code Snippets
22

3-
Code snippets, one of my top favorite features in Azure Data Studio. This is why I dev in ADS and not SSMS. This sums up my feelings at least a half dozen times every day I'm doing any T-SQL development:
3+
Code snippets in Azure Data Studio: repetition is no guarantee for memorization.
44

55
![syntax-emotions](miscellany/img/what_was_that_syntax.png)
66

7-
There's relief! It's simple to add any frequently used syntax to ADS! This repo contains my frequently used code building blocks.
7+
ADS snips are a core part of developing with t-sql and I use this batch of snippets daily.
88

99
## Install your snippets
1010

11-
To update your code snippets, open the command pallet and paste in the contents of the .json file in this repo. This file is saved below:
11+
To update your code snippets, open the command pallet and paste in the contents of the .json file in this repo.
12+
13+
![how to install](miscellany/install-snippet.gif)
1214

1315
Local (macOS) file repository:
1416
> /Users/digitalduquette/Library/Application Support/azuredatastudio/User/snippets/sql.json

miscellany/install-snippet.gif

1.43 MB
Loading

sql.json

Lines changed: 67 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,48 @@
2323
],
2424
"description": "Provides standard view comment block"
2525
},
26+
"Stored Proc Header Comment": {
27+
"prefix": "sqlCommentProcHeader",
28+
"body": [
29+
"/***************************************************************************************************",
30+
"Procedure: dbo.usp_DoSomeStuff",
31+
"GitHub Repo: PADNOS/Salesforce_Extensibility ",
32+
"Create Date: 2018-01-25",
33+
"Author: Joe Expert",
34+
"Description: Verbose description of what the query does goes here. Be specific and don't be",
35+
"\t\t\t\t\tafraid to say too much. More is better, than less, every single time. Think about",
36+
"\t\t\t\t\t``what, when, where, how and why`` when authoring a description.",
37+
"Call by: [schema.usp_ProcThatCallsThis]",
38+
"\t\t\t\t\t[Application Name]",
39+
"\t\t\t\t\t[Job]",
40+
"\t\t\t\t\t[PLC/Interface]",
41+
"Affected table(s): [schema.TableModifiedByProc1]",
42+
"\t\t\t\t\t[schema.TableModifiedByProc2]",
43+
"Used By: Functional Area this is use in, for example, Payroll, Accounting, Finance",
44+
"Parameter(s): @param1 - description and usage",
45+
"\t\t\t\t\t@param2 - description and usage",
46+
"Usage: EXEC dbo.usp_DoSomeStuff",
47+
"\t\t\t\t\t@param1 = 1,",
48+
"\t\t\t\t\t@param2 = 3,",
49+
"\t\t\t\t\t@param3 = 2",
50+
"\t\t\t\t\tAdditional notes or caveats about this object, like where is can and cannot be run, or",
51+
"\t\t\t\t\tgotchas to watch for when using it.",
52+
"****************************************************************************************************",
53+
"SUMMARY OF CHANGES",
54+
"Date(yyyy-mm-dd) Author Comments",
55+
"------------------- ------------------- ------------------------------------------------------------",
56+
"2012-04-27 John Usdaworkhur Move Z <-> X was done in a single step. Warehouse does not",
57+
"\t\t\t\t\tallow this. Converted to two step process.",
58+
"\t\t\t\t\tZ <-> 7 <-> X",
59+
"\t\t\t\t\t1) move class Z to class 7",
60+
"\t\t\t\t\t2) move class 7 to class X",
61+
"",
62+
"2018-03-22 Maan Widaplan General formatting and added header information.",
63+
"2018-03-22 Maan Widaplan Added logic to automatically Move G <-> H after 12 months.",
64+
"***************************************************************************************************/"
65+
],
66+
"description": "Header comment block for stored procs"
67+
},
2668
"Recent Query": {
2769
"prefix": "sqlRecentQuery",
2870
"body": [
@@ -65,8 +107,7 @@
65107
"Create db schema": {
66108
"prefix": "sqlCreateSchema",
67109
"body": [
68-
"CREATE SCHEMA [schemaNameHere]",
69-
"GO",
110+
"CREATE SCHEMA [schemaNameHere];",
70111
"",
71112
"-- Run this query to see schema",
72113
"-- SELECT * FROM sys.schemas;"
@@ -77,13 +118,13 @@
77118
"prefix": "sqlDataTypeInfo",
78119
"body": [
79120
"SELECT",
80-
"column_name, data_type, CHARACTER_MAXIMUM_LENGTH, COLLATION_NAME",
81-
"-- distinct TABLE_SCHEMA, TABLE_NAME",
121+
"\tCOLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, COLLATION_NAME",
122+
"\t-- distinct TABLE_SCHEMA, TABLE_NAME",
82123
"FROM INFORMATION_SCHEMA.COLUMNS",
83124
"WHERE",
84-
"TABLE_SCHEMA IN ('')",
85-
"AND TABLE_NAME IN ('')",
86-
"AND COLUMN_NAME IN ('')"
125+
"\tTABLE_SCHEMA IN ('')",
126+
"\tAND TABLE_NAME IN ('')",
127+
"\tAND COLUMN_NAME IN ('')"
87128
],
88129
"description": "What is the collation/data type length for a column?"
89130
},
@@ -104,18 +145,22 @@
104145
"prefix": "sqlMERGE",
105146
"body": [
106147
"MERGE target_schema.target_table AS tgt ",
107-
"USING source_schema.staging AS srs ON ( ",
108-
"\tsrs.id = tgt.id ",
109-
")",
110-
"WHEN MATCHED THEN UPDATE SET ",
111-
"\ttgt.column_name = srs.column_name",
112-
"WHEN NOT MATCHED BY TARGET THEN INSERT ( ",
113-
"\tcolumn_name ",
114-
")",
115-
"VALUES ( ",
116-
"\tsrs.column_name ",
117-
")",
118-
"WHEN NOT MATCHED BY SOURCE THEN DELETE;"
148+
"\tUSING source_schema.staging AS srs ON ( ",
149+
"\t\tsrs.id = tgt.id ",
150+
"\t)",
151+
"\tWHEN MATCHED THEN UPDATE ",
152+
"\t\tSET ",
153+
"\t\t\ttgt.column_name = srs.column_name",
154+
"\tWHEN NOT MATCHED BY TARGET THEN ",
155+
"\t\tINSERT ( ",
156+
"\t\t\tcolumn_name ",
157+
"\t\t)",
158+
"\t\tVALUES ( ",
159+
"\t\t\tsrs.column_name ",
160+
"\t\t)",
161+
"\tWHEN NOT MATCHED BY SOURCE THEN ",
162+
"\t\tDELETE",
163+
";"
119164
],
120165
"description": "MERGE statement syntax"
121166
},
@@ -156,9 +201,10 @@
156201
"prefix": "sqlGrantEXEC",
157202
"body": [
158203
"USE database_name;",
204+
"",
159205
"GRANT EXECUTE ON OBJECT::schema.usp_proc_name ",
160-
"\tTO user_name; ",
161-
"GO "
206+
"\tTO user_name ",
207+
"; "
162208
],
163209
"description": "Grant execute on object to user via t-sql."
164210
},

0 commit comments

Comments
 (0)