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:

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

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

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

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

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

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:

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

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:

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

2. Select SQL:

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

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
Update 25 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile