Use code to quickly create T-SQL scripts in SQL Operations Studio (preview)

The code in SQL Operations Studio (preview) is the template that makes it easier to create databases and database objects.

The code in SQL Operations Studio (preview) is the template that makes it easier to create databases and database objects. SQL Operations Studio (preview) provides some T-SQL code to help users quickly create appropriate syntax. User-defined code snippets can also be created.

Use the built-in T-SQL code

1. To access the available code, enter sql in the query editor to open the list:

Use code to quickly create T-SQL scripts in SQL Operations Studio (preview) Picture 1Use code to quickly create T-SQL scripts in SQL Operations Studio (preview) Picture 1

2. Select the code you want to use and it will create the T-SQL script. For example, select sqlCreateTable:

Use code to quickly create T-SQL scripts in SQL Operations Studio (preview) Picture 2Use code to quickly create T-SQL scripts in SQL Operations Studio (preview) Picture 2

3. Update the fields marked with your specific values. For example, replace TableName and Schema with values ​​for your database:

Use code to quickly create T-SQL scripts in SQL Operations Studio (preview) Picture 3Use code to quickly create T-SQL scripts in SQL Operations Studio (preview) Picture 3

If the field you want to change is no longer marked (this happens when moving the cursor around the editor), right-click the word you want to change and select Change all occurrences:

Use code to quickly create T-SQL scripts in SQL Operations Studio (preview) Picture 4Use code to quickly create T-SQL scripts in SQL Operations Studio (preview) Picture 4

4. Update or add any additional T-SQL you need for the selected code. For example, update Column1, Column2 and add other columns.

Create SQL code

You can define your own code. To open the file containing the SQL code to edit:

1. Open Command Palette (Shift + Ctrl + P) , and type snip, then select Preferences: Open User Snippets:

Use code to quickly create T-SQL scripts in SQL Operations Studio (preview) Picture 5Use code to quickly create T-SQL scripts in SQL Operations Studio (preview) Picture 5

2. Select SQL:

Use code to quickly create T-SQL scripts in SQL Operations Studio (preview) Picture 6Use code to quickly create T-SQL scripts in SQL Operations Studio (preview) Picture 6

3. Paste the following code into sql.json:

 "Select top 5": { 
"prefix": "sqlSelectTop5",
"body": "SELECT TOP 5 * FROM $ {1: TableName}",
"description": "User-defined snippet example 1"
},
"Create Table snippet": {
"prefix": "sqlCreateTable2",
"body": [
"- Create a new table called '$ {1: TableName}' in schema '$ {2: SchemaName}'",
"- Drop the table if nó đã có",
"IF OBJECT_ID ('$ 2. $ 1', 'U') IS NOT NULL",
"DROP TABLE $ 2. $ 1",
"GO",
"- Create the table in the specified schema",
"CREATE TABLE $ 2. $ 1",
"(",
"$ 1Id INT NOT NULL PRIMARY KEY, - the primary key column",
"Column1 [NVARCHAR] (50) NOT NULL,",
"Column2 [NVARCHAR] (50) NOT NULL",
"- specify more columns here",
");",
"GO"
],
"description": "User-defined snippet example 2"
}

4. Save the sql.json file .

5. Open the new query editor window by clicking Ctrl + N.

6. Enter sql and you will see two user code sections that you just added: sqlCreateTable2 and sqlSelectTop5.

Choose one of the new code and run the test!

See more:

  1. Find Login in SQL Server
  2. DROP LOGIN command in SQL Server
  3. ALTER LOGIN command in SQL Server
5 ★ | 1 Vote