Pages

Showing posts with label command prompt. Show all posts
Showing posts with label command prompt. Show all posts

Thursday, June 18, 2015

Bulk Copy Program (BCP)–A simple way to export data in a file TIP#101

 

Let’s consider a scenario where the end user require a CSV file of all the records in a table then BCP is one of the simplest way.

BCP stands for Bulk copy program. By the name you got the feeling of lots of data Smile.

Although, there are various options & parameters available with BCP but here we will talk about simple one Smile.

To understand it more clearly lets consider an example.

I have a database with name “IndiandotnetDB” and in this database I have a table with name tblStudentSource which having few records as shown in below figure

Indiandotnet_tbl_Student_Source

Now, the objective here is to export all the data which is in tblStudentSource table to a CSV file.

to achieve this we will use BCP command.  We are running BCP from command prompt as shown in below figure

Indiandotnet_BCP_1

Although there are various other options available with BCP command but for current post I choose simple one .

Now let me explain the command

BCP IndiandotnetDb.dbo.tblStudentSource OUT d:\File\output\sampleExport.csv –S . –T –c

so in above command “IndiandotnetDB” is my database

“dbo” is schema

“tblStudentSource” is  a table whose data need to be export

OUT – here out stands for export (export the table or query data)

“D:\File\output\” is folder where I want exported file

“sampleExport.csv” is file name which will be created by BCP and contains entire records after execution of BCP command

-S is stands for server I used “.” for localhost we can provide instance name as well

-T is for trusted connection (we can use – U for username – P for password)

-c is stands for character data type if you are not using this then you have to provide data type for each fields of output query result

Below is the output of the command which we run “ a sampleExport.csv file with all the records”

Indiandotnet_BCP_Export_Result

I hope this simple post will help you some where. I will share more details about BCP command in coming post.

Thanks

RJ!!

Thursday, July 3, 2014

How to open SQL Profiler from command prompt–TIP # 23

 

To open SQL Profiler (right now I am talking about SQL Server 2012) you need to write Profiler.exe on run command as shown in below figure

Profiler

for earlier version you can use profiler90.exe.

You can find various parameters option using Profiler.exe –? command

When you run this command you will find below screen.

Profiler_Options

Although It does not impact how you open profiler but it is good to know thing Smile

Enjoy !!!

Wednesday, June 25, 2014

How to open SQL Server Management studio from command prompt - TIP#21


It is just a simple tip nothing fancy.

On command prompt you just type SSMS and hit OK.






Your SQL server Management studio will be open.

You can get other option also by typing ssms/? .



You will get below options



Now if you want to login to particular SQL Server Instance you can choose option as mention in above screen.


For example to open SQL Express version on my machine, I wrote query as shown in below image


Enjoy!!!