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:
2. Select the code you want to use and it will create the T-SQL script. For example, select sqlCreateTable:
3. Update the fields marked with your specific values. For example, replace TableName and Schema with values for your database:
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:
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:
2. Select SQL:
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:
- Find Login in SQL Server
- DROP LOGIN command in SQL Server
- ALTER LOGIN command in SQL Server
You should read it
- Learn about Microsoft Operations Studio from Microsoft
- Manage servers and databases with detailed utilities in SQL Operations Studio (preview)
- Integrated terminal in SQL Operations Studio (preview)
- Shortcuts in Camtasia Studio
- 9 extension Visual Studio Code for easier programming
- Visual Studio Code review: Microsoft's cross-platform code editor
- Is Thonny or Visual Studio Code better for Raspberry Pi users?
- Roblox Studio
- Windows App Studio update introduces many new additions
- 10 tips for Microsoft's cross-platform code editing tool - Visual Studio Code
- How to create a file to install Visual Studio offline
- How to install Visual Studio Code on Windows 10
Maybe you are interested
The way to sum the same codes in Excel Fix 'Something went wrong' error on Office 2013 What is the standard Twitter image size? How to use multiple chat applications on the same window The following 5 inventions can 'save' Earth and humanity Discover the secret of 2,100 years old 'astronomical computer'