Superb option run same single query on multiple SQL Server instances

Dear Friends,
Sometimes you stuck in situation where you need to run same set of queries on different servers.
Sometimes it is a real pan when you need to fetch records from all the server then basic approach you follow run query on different instance once by one.

I would like to share here one important facility provided in SQL Server management studio which is

“Register Servers”

With the help of Register Servers option you can run same query for the entire servers which you have registered.
You can access the “Register Servers” option from View ==> Register servers OR by pressing “CTRL + ALT + G” keys.

As shown below fig

Register Servers

Once you press the menu or follow above keys then you will get Register Servers option screen as shown in below fig.

Regiser server screen

You can right click on Local Server Groups and can create your own group also

Create group

Once the group is created you can move your Registered servers on which you want to run query in that group with right click move option on Group Folder

As you did this job your database server will come in the particular group folder as shown in below fig

MylocalGroupRegisterServers

Now right click on your group folder and go for option New Query
As you go for option new query a new query window will be open there
Now write proper query which you want to run on same database at different servers and execute it with F5 option
You will find when you will execute the result will show in query result window which is just below the query with starting column server name.

SinglQueryMultipleResult

Now you have option whether you want merge result or Individual result.
To check that option you need to go Tool –> Option then Query Result option as shown below fig

MergeREsultOption

This trick will help you in many ways to get the results from different server as well as to find results from different servers.

Thanks & Regards,
Rajat Jaiswal
Keep Learning, Keep Sharing

Great option “SQLCMD” run DOS command in SQL Server Managment Studio

Dear All,
Today I am going to share one of the interesting options of SQL Server Management studio which may be unknown to most of us.
Now you are thinking what it is? So the cool feature is you can

run DOS command in your SQL Server Management studio

.
I know your next question is how?
My answer is just follow below step
Go To Tool –> Option
After option window open you need to select Query Execution tree and Select checkbox for

SQLCMD_Option

By default, Open new queries in SQLCMD Mode

Now open new Query window and write following command
!! Dir C:\
And hit F5
You will find below in the query result you have directory & files of your current C drive.
Just check below fig to understand.

SQLCMD_Result

In this way you can run various DOS commands.
!! SSMS
!! Dir C:\New Folder

Isn’t it cool feature.

I hope you enjoyed it.

SQLCMD Option

Rocks
Keep Learning, Keep Sharing
Your friend,
Rajat Jaiswal

How to open Profiler with command prompt , Various options?

Dear Friends,

In the last topic we got awareness like

How to open SQL server using command prompt.
In similar way we can

open profiler with command prompt

also.

So Let us start write following command on command prompt

1.  C:\>Profiler

The above command will open the profiler.

2. C:\>Profiler –E

When you write above command and press enter you will find profiler is open also a default trace started as shown in below fig

Profiler-With-Default-Trace

3. C:\> Profiler/?

When you hit enter after writing the above command you will find a popup windows which shows various option available with profiler command so just enjoy.

profiler-With-command-Various-options

Thanks & Best Regards

Rajat Jaiswal

How to open SQL Server with command prompt with various option?

Dear All,

Today I am going to share some small dos which will helpful to open SQL Server Management Studio.

I am sure you are curious about

how to open SQL Server Management studio with command prompt.

So Let us start Currently when you go through SQL Server Management studio you have to process 2 step means first click the SQL server Management studio by clicking icon then login to the server.

Now check this out write following command in dos command prompt and press enter

C:\> ssms –E

You will find your SQL Server Management studio open without any prompt of Login authentication because here E stands for windows Authentication mode.
Now go deeper write following command

C:\>ssms –E –NOSPLASH

Now you found that the splash screen also not coming ,So similarly you can find various options to open SQL SERVER Management Studio using command prompt.

SSMS-E-NOSPLASH
To know various options let us write following command

C:\ssms/?

You will get following screen and you can any option from below screen to proceed further.

ssms

I hope you enjoyed the trick.

Thanks & Bes Regards, Rajat Jaiswal

Facebook Graph API- Is it Simple to Fetch Facebook users information with simple URL (Y/N)?

Dear Friends,
Today I am going to share some small tips to

access Facebook account related detail using Graph API.

Facebook Graph API is one of the easy tools to access Facebook Information and incorporate in your application.

Suppose you know the Facebook name of the person and if you want to know First name, last name, Facebook Id and Facebook page of the person then you just need to write following URL in your browser.

http://graph.facebook.com/Facebookusername

(You just need to Replace Facebook Username by Facebook actual username Or Facebook ID)

Let us try with my Facebook username when I write below URL in browser and hit enter

https://graph.facebook.com/rajat.jaiswal.902

I get following screen

Facebook ID by Facebook Usename

Similarly if I know the ID then I can also get above screen. Now write following URL in browser you will get exact same screen

https://graph.facebook.com/771700761

Going further I know curiosity increased now you want see Facebook Picture also of the person then no issue we are going to show the image also with same Facebook Graph API

For this you just need to write following URL in your browser

 

https://graph.facebook.com/FacebookId/picture (You just need to replace Facebook ID)

For example let us run it with my Facebook ID

 

https://graph.facebook.com/771700761/picture

I hope you enjoyed this information.

Thanks & Regards,
Rajat Jaiswal
Keep Learning, Keep Sharing

ORDER BY Issue WITH Temporary table in SQL SERVER ?

Dear Friends,

Yesterday was a very good learning day for me. One of my colleagues stuck in a very interesting issue.
He was fetching records from database with an ORDER BY clause on a VARCHAR field.
Couple of records of his table containing “-“hyphen symbol in the field on which he applied Sorting.

So after facing that problem I am sharing how to use collation in ORDER BY CLAUSE with your select statement.

Let’s consider below example

DECLARE @tblSubjects TABLE(
Subjects VARCHAR(100)
)

INSERT INTO @tblSubjects VALUES (‘HINDIBALBHARTI’)
INSERT INTO @tblSubjects VALUES (‘HINDI-BALBHARTI’)

SELECT Subjects AS Default_Collation_Sort_Order FROM @tblSubjects ORDER BY Subjects ;
SELECT Subjects AS Explicit_Changed_Collation_Sort_Order FROM @tblSubjects ORDER BY Subjects COLLATE Latin1_General_CI_AI ;

When you run above statement you will get different order in result set.

ORDER BY ISSUE in temp Table
Generally this problem occurs when you use temp tables and your sort order and it is not as per your expectation.

So if you found this type of ORDER BY issue than you can explicitly use COLLATION

Enjoy learning.

Your host
Rajat Jaiswal

Compare records of each tables of Source & Target database

Dear Friends,
In last post we have seen how easy to find the database changes and generate script for the changes that will help you in deployment.

Similarly sometimes you need to know

row by row data difference in two databases

so don’t worry about that because visual studio 2010 provided

data comparison

option also. Just follow below steps and you are good to go for database changes also
Step 1:-

Go to following menu in Visual Studio as shown in below Fig
Data ==> Data Compare ==> New Data Comparison

dataCompareOption
Step 2:- When you click the above provided menu then you will get following screen. Just configure the

source and Destination databases

.
Check record comparison options which you want like different records only, only in source, only in destination, identity records etc. Now press NEXT button.

DataComparision

Step 3:- As you press the next button you will find the screen where you can select all or particular table or view for comparison as shown in below fig.

Datacomparison_Table_Selection

Step 4:- Once you have selected the particular table(s) and view (s) you will get following screen where you can find table wise comparison like, How many identical records in both tables ?, How many records exists only in source table?, How many records exists only in destination table ?

And below the comparison grid you will find different tabs also for different result sets you just need to select the tab to see the records associated with those particular criteria.

DataComparision_ResultSet

Step 5:- Now with show data update script menu option you can generate script.

Database_Comparison_Result_Set

script_After_Data_Comparison

Now just copy & paste and you are good to go.
So I hope you understand the essence of this utility also.

Enjoy .NET
Enjoy learning.
Keep Sharing 🙂

Your host
Rajat Jaiswal

Make SQL Server Database Changes deployment easy with “Schema comparison”

Dear friends,

“Database Changes deployment”

, hmm little bit scary topic. But don’t’ worry
Today I am going to give a brief introduction on

Schema Comparison feature of Visual Studio 2010.

I think most of the people are not aware of this. This tool is one of the best helping tools for your deployment process.
Suppose you have made all the changes in your local database which are related to stored procedure, database schema and by mistake you are not aware what changes you have made so far which are not exists in your staging or production server.
Your first thought is to compare both the database and generate script for changes and just deploy on target database.

So Visual Studio 2010 makes your life easy with a new Feature which is called “Schema Compare”.
Just follow the steps as show below and you are good to go for any database changes deployment :).
Step 1:- Open Visual Studio 2010 Go to Data Menu Schema compare then New Schema Comparison and click it. You will get following screen.

Schema Comparision
Step 2:- Just define the Source and target database connection string in the above screen and then press OK button. Once you press OK button the Visual Studio compare the source and target database each object like tables, columns, store procedures etc.

You will get following screen which shows difference in source and target database in “Update Action” column.

Schema comparision detail
Step 3:- With Update Action column you can choose whether you want to keep these changes in the final script or not as show in below fig

Schema compare action
Step 4:- Now when you are assure that you want selected changes on target server also then you can on “Export To Editor” or “Export To File” option as shown below

Export to File
Step 5:- Now you are ready to run the changes because you have all the changes script like I have in below fig.

Generate Script output

I hope you enjoyed this.
Enjoy learning & Sharing.
Thanks & Regards,
Rajat Jaiswal