Showing posts with label ssms. Show all posts
Showing posts with label ssms. Show all posts

Tuesday, 7 February 2012

Hiding System Objects in Object Explorer in SQL Server Management Studio

Hiding System Objects in Object Explorer in SQL Server Management Studio

 

Problem

While looking through the new features and improvements in SQL Server Management Studio (SSMS) we found a potentially interesting one to Hide System Objects in Object Explorer in SQL Server Management Studio. In this tip we will take a look at how to Hide System Objects in Object Explorer.

Solution

You may have noticed that once you are connected to a SQL Server Instance using SQL Server Management Studio, in the Databases node of Object Explorer you can see system objects such as the system databases as shown in the snippet below.
how to hide system objects in object explorer in ssms
You can hide system objects in Object Explorer by following the below mentioned steps:
1. In SQL Server Management Studio, under Tools menu, click Options as shown in the snippet below.
go to tools in ssms
2. In the Options dialog box, expand Environment and then select the General tab as shown in the snippet below. Select Hide system objects in Object Explorer and then click OK.
select the genral tab in ssms
3. In the Microsoft SQL Server Management Studio dialog box, click OK to acknowledge that the changes will come into effect once you restart SQL Server Management Studio.
you must restart sql server management studio
4. Next, go ahead and close SQL Server Management Studio. When you reopen SQL Server Management Studio once you are connected to SQL Server Instance you will not see the System Objects in Object Explorer in SQL Server Management Studio as shown in the snippet below.
when you reopen ssms  once you are connected to sql server instance it will look like the snippet below

 

SQL Server Management Studio customized startup options

SQL Server Management Studio customized startup options

 

ProblemSQL Server Management Studio (SSMS) is now the primary tool that we all use to manage SQL Server.  Whenever I open up SSMS I always go through the same steps to connect to a server and open certain query files.  Are there any shortcuts or alternative ways of starting SSMS?
Solution
SQLWB (sqlwb.exe) is the executable file that launches SQL Server Management Studio (SSMS). Most-likely the name corresponded to the original working name for Management Studio during the development phase of Yukon (the project title for what would eventually become SQL Server 2005): SQL Server Workbench. What many SQL Server professionals fail to realize is that the startup behavior of SSMS is customizable.  By simply passing parameter values along with the command to launch sqlwb, you can open default queries, projects, or connections.  You can also control whether to launch SSMS with the application's splash screen.  Let's take a look at the list of parameters available, courtesy of SQL Server Books Online:
sqlwb [scriptfile] [projectfile] [solutionfile]
[-S servername] [-d databasename] [-U username] [-P password]
[-E use Windows security]
[-nosplash]
[-?]
Arguments
The [scriptfile], [projectfile], and [solutionfile] parameters specify a file (or in the case of [scriptfile], the possibility of multiple files to open upon launch of SSMS.  If  you do not specify parameter values for servername, databasename, username, or password when you launch sqlwb and specify a script(s), project, or solution you will be prompted for the applicable security context for the file(s) you are opening.
Let's look at some examples of the behavior associated with the various options for launching SQL Server Management Studio from a Run command or Command Prompt:
Open a single script (.sql) file upon SSMS startup
sqlwb "C:\Temp\Config1.sql"
This command launches SQL Server Management Studio and prompts you for the connection information.  Note the query name in the background of this screen shot.
Open multiple sql query (.sql) files upon SSMS startup
The process for opening multiple SQL query files is only slightly different, simply list each of the full file paths for each query file you wish to open, separated by a space, after the call to sqlwb as shown in this screen image:
sqlwb "C:\Temp\Config1.sql" "C:\Temp\Config2.sql"
Without specifying the connection information in the run command for sqlwb you will be prompted for the SQL instance and security information upon launch of SSMS.  Note that once authenticated each of the queries connect using that same criteria.  This bears repeating: each .sql file will connect to the instance you specify, as the login you specify, when launching SSMS in this manner.
Open a SQL Server Management Studio Project (.ssmssqlproj) file upon SSMS startup
Microsoft provided an additional layer of project management with the release of SQL Server 2005.  The concept of a solution and project was nothing new to the developers out there.  This concept has been a component of the Visual Studio architecture for many previous releases.  However, in the continuing streamlining between SQL Server and Visual Studio interfaces, the concept finally was incorporated into the SQL Server management tools.  Simply put, a SQL Server Project file is a collection of various connections,  queries, and other objects that are organized to be utilized for a common purpose.  I personally use SSMS Projects for such purposes as Standard Installations, Daily Maintenance Checks, and Security Audits.  Just as SSMS Projects are a collection of multiple components, SSMS Solutions are a collection of multiple SSMS Projects.  The syntax for launching an SSMS Project or Solution is no different than launching a single .sql file from the command line or Run menu. 
Let's look at the following example; we will specify an existing .ssmssqlproj file, connecting with Integrated (Windows) security to the Sauron.Northwind database.
sqlwb "C:\Config\Config.ssmssproj" -S sauron -d Northwind -E
Additionally, you can open a SSMS Solution by providing a solution file path (...\*.ssmssln) as a parameter.  The following command opens the solution file Config.ssmssln, passing the connection information for the Foo login against the sauron instance of SQL Server:
sqlwb "C:\Temp\SSMS Projects\Configuration\Configuration.ssmssln"-S sauron -d Northwind -U Foo -P pwFoo  
Additional Parameters
Here are some additional options.
  • Launches SQL Server Management Studio without the splash screen
sqlwb -nosplash
  • At any time you are unsure about the parameters available for sqlwb, you can append the -? parameter to display the following help information.
sqlwb -?
 Don't feel that you're forced into launching SQL Server Management Studio with the default splash screen and an initial instance connection.  The parameters associated with sqlwb.exe allow you to specifically control your startup parameters for files and connections.

 

Monday, 6 February 2012

Custom Script Quickly with SSMS sql server 2008

Run Your Custom Script Quickly with SSMS


Suppose you have to do a task repeatedly with different objects of database, for example, you have to generate code or stored procs of table in the specific format, you created your custom SQL script which takes table name and generate the code. But each time, you have to execute query and pass table name.
What’ll happen If you right click on the table and select your script to execute. It’ll save bunch of time as well as stop you getting irritated icon smile Run Your Custom Script Quickly with SSMS Tools Pack Let’s see how to do using SSMS Tools Pack.

SSMS Tools Pack:

It is the best free Sql Server Management Studio(SSMS)’s add-in having lots of features like Execution Plan Analyzer, SQL Snippets, Execution History, Search Table, View or Database Data, Search Results in Grid Mode, Generate Insert statements from result sets, tables or database, Regions and Debug sections, CRUD stored procedure generation, New query template..etc.
Website Link

Download Link

Steps:

Suppose you want to see total number of records in different tables.
1. Click on SSMS Tools > “Run Custom Script” > Options
SSMS Tools Pack TechBrij 1 Run Your Custom Script Quickly with SSMS Tools Pack
2. Left side of dialog, Enter Shortcut ‘Total Records‘ and check Run checkbox
SSMS Tools Pack TechBrij 2 Run Your Custom Script Quickly with SSMS Tools Pack
3. Right Side, Click on ‘Enabled On..‘ option and select ‘table’. It means this will appear on each table.
4. Enter following script
Select Count(*) from |SchemaName|.|ObjectName|
Here |SchemaName| and |ObjectName| are replacement texts. You can see available replacements options on ‘Replacement Texts‘ click.
SSMS Tools Pack TechBrij 4 Run Your Custom Script Quickly with SSMS Tools Pack
Click on Save and OK button.
5. Now, Right click on any table > “Select SSMS Tools” > Run Custom Scripts > Total Records

SSMS Tools Pack TechBrij 5 Run Your Custom Script Quickly with SSMS Tools Pack
You will get Total Records in result and no need to pass table name in query again and again.


SSMS Tools Pack TechBrij 6 Run Your Custom Script Quickly with SSMS Tools Pack

Similarly, you can run your other custom scripts quickly. It is very helpful as a code generation tool. Let me know how you are using it.