You can comment and uncomment portions of your text by using the Comment button on the toolbar. Text that is commented out isn't executed.
Open SQL Server Management Studio.
Connect to your SQL Server instance.
Open a New Query window.
Paste the following Transact-SQL code in your text window.
SQL
USEmaster;
GO
--Drop the database if it already exists
IF EXISTS (SELECTnameFROM sys.databases
WHEREname = N'TutorialDB')
DROPDATABASE TutorialDB;
GO
CREATEDATABASE TutorialDB;
GO
ALTERDATABASE [TutorialDB]
SET QUERY_STORE = ON;
GO
Highlight the Alter Database portion of the text, and then select the Comment button on the toolbar:
Select Execute to run the uncommented portion of the text.
Highlight everything except for the Alter Database command, and then select the Comment button:
Note
The keyboard shortcut to comment text is CTRL + K, CTRL + C.
Highlight the Alter Database portion of the text, and then select the Uncomment button to uncomment it:
Note
The keyboard shortcut to uncomment text is CTRL + K, CTRL + U.
Select Execute to run the uncommented portion of the text.
Indent your text
You can use the indentation buttons on the toolbar to increase or decrease the indent of your text.
Open a New Query window.
Paste the following Transact-SQL code in your text window:
SQL
USEmaster;
GO
--Drop the database if it already exists
IF EXISTS (SELECTnameFROM sys.databases
WHEREname = N'TutorialDB')
DROPDATABASE TutorialDB;
GO
CREATEDATABASE TutorialDB;
GO
ALTERDATABASE [TutorialDB]
SET QUERY_STORE = ON;
GO
Highlight the Alter Database portion of the text, and then select the Increase Indent button on the toolbar to move the highlighted text forward:
Highlight the Alter Database portion of the text again, and then select the Decrease Indent button to move the highlighted text back.
Filter objects in Object Explorer
In databases that have many objects, you can use filtering to search for specific tables, views, etc. This section describes how to filter tables, but you can use the following steps in any other nodes in Object Explorer:
Connect to your SQL Server instance.
Expand Databases > AdventureWorks > Tables. All the tables in the database appear.
Right-click Tables, and then select Filter > Filter Settings:
In the Filter Settings window, you can modify some of the following filter settings:
Filter by name:
Filter by schema:
To clear the filter, right-click Tables, and then select Remove Filter.
Access your SQL Server error log
The error log is a file that contains details about things that occur in your SQL Server instance. You can browse and query the error login SSMS. The error log is a .log file that exists in your file system.
Open the error log in SSMS
Connect to your SQL Server instance.
Expand Management > SQL Server Logs.
Right-click the Current error log, and then select View SQL Server Log:
Query the error log in SSMS
Connect to your SQL Server instance.
Open a New Query window.
Paste the following Transact-SQL code in your query window:
SQL
EXECUTE sp_readerrorlog 0, 1,'Server process ID'
Modify the text in the single quotes to text you want to search for.
Execute the query, and then review the results:
Find the error log location if you're connected to SQL Server
Connect to your SQL Server instance.
Open a New Query window.
Paste the following Transact-SQL code in your query window, and then select Execute:
The results show the location of the error log in the file system:
Find the error log location if you can't connect to SQL Server
The path for your SQL Server error log can vary depending on your configuration settings. The path for the error log location can be found in the SQL Server startup parameters within the SQL Server Configuration Manager.
Follow these steps to locate the relevant startup parameter that identifies the location of your SQL Server error log. Your path might vary from the path indicated in the example.
Open SQL Server Configuration Manager.
Expand Services.
Right-click your SQL Server instance, and then select Properties:
Select the Startup Parameters tab.
In the Existing Parameters area, the path after -e is the location of the error log:
There are several error log files in this location. The file name that ends with *log is the current error log file. File names that end with numbers are previous log files. A new log is created every time the SQL Server restarts.
Open the errorlog.log file in your preferred text editor.
Find SQL Server instance name
You have a few options to find the name of your SQL Server instance before and after you connect to SQL Server.
The text listed in the single quotes is the name of the SQL Server instance to use in the connection:
The format of the name is HOSTNAME\INSTANCENAME. If you see only the host name, then you've installed the default instance and your instance name is MSSQLSERVER. When you connect to a default instance, the host name is all you need to enter to connect to your SQL Server. Your path might vary from the path in the sample image.
When you're connected to SQL Server
When you're connected to SQL Server, you can find the server name in three locations:
The name of the server is listed in Object Explorer:
The name of the server is listed in the Query window:
The name of the server is listed in Properties.
In the View menu, select Properties Window:
If you're connected to an alias or availability group listener
If you're connected to an alias or to an availability group listener, that information appears in Object Explorer and Properties. In this case, the SQL Server instance name might not be readily apparent, and must be queried:
Connect to your SQL Server instance.
Open a New Query window.
Paste the following Transact-SQL code in the window:
SQL
SELECT @@Servername;
View the results of the query to identify the name of the SQL Server instance you're connected to:
Administer an SQL Server database infrastructure for cloud, on-premises and hybrid relational databases using the Microsoft PaaS relational database offerings.