How to connect SQL Server Database using “sqlcmd”

Connecting to one particular database of a SQL Server default instance.Using sqlcmd command.

go to command prompt  {  how to open command : start–>run–>cmd }

How to get sqlcmd help

sqlcmd -?   —> It displays all options of sqlcmd commandsqlcmd-help

  • sqlcmd  -H  <hostname or computer name>  -S  <SQLServer Name > -d <database-name>

For Example:

How to connect  SQL Server default instance .

sqlcmd  -H  srpv-pc   -S  .  -d mydb1    

 // srpv-pc –> host name

// . (dot) —> default SQL Server instance.

// mydb1   —> database name

sqlcmd1

  • sqlcmd  -H  <hostname or computer name>  -S  <SQLServer Name > -d <database-name>

For Example:

How to connect  SQL Server named  instance

sqlcmd  -H  srpv-pc   -S  srpv-pc\srpv  -d db1   

 // srpv-pc –> host name

// srpv-pc\srpv —> Named SQL Server instance (srpv).

// db1   —> database namesqlcmd2

How to connect particular database of a default instance with out specifying hostname and server name.

sqlcmd  -d <database-name>

For Example:

How to connect  particular database directly with out host and server name.

sqlcmd    -d db1    

// db1   —> database name

 

sqlcmd-1

 

 

 

 

Advertisements

One thought on “How to connect SQL Server Database using “sqlcmd”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s