Blue Theme Orange Theme Green Theme Red Theme
 
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Discover the top 5 tips for understanding .NET Interop
Search :       Advanced Search »
Home » SQL Server 2012 » Format files in SQL Server

Format files in SQL Server

How to create a Format file????? Let's see an example to understand it.

Page Views : 2289
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
Discover the top 5 tips for understanding .NET Interop
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


For many years, I used to think about writing an article on Format files. I got shocked on seeing a procedure which is using format file and I am not aware of this area. Anyway, Learning starts or goes only if we don't know something right!!!! 

Come one........Let's learn something...........

BCP - Bulk copy program 
  1. It's a utility to copy the data in bulk.
  2. Data from files (or) to files in a specific format can be achieved using this BCP.
Format file:
  1. If we want to read a file, it's very hard for SQL Server to read the file and store it in the database. Yes, we can store it but it will varchar field in the database.
  2. To inform SQL Server about the datatype in the files. We use the Format file.
  3. The Format file will tell you that, the file holds integer value, datetime field value with length 10 etc..,
How to create a Format file????? Let's see the below example to understand it.

Am having a table named Venkat_table

1.gif 

Below is the command to get the Format file,

       bcp Venkat_Table format nul -S servername -T -n -f C:\Venkat_TableFormat.fmt 

The Syntax is like, BCP DatabaseName.Ownername.ObjectName format nul -S servername -T -n -f formatfilename 

nul - If there is no data file name to load. Here, we are fetching data from the table.
-T - Indicates trusted authentication or else -U and -P should come (SQL Server authentication)
-n - Indicates native data type. We will discuss more below.
-f - Informing the format file

2.gif

We should go to the Windows command prompt and execute the above command, a file will be generated in the desired location. 

3.gif

On opening the Format file, you will get the below details. 

4.gif  

Here is a generic details to understand the format file.

5.gif

 
  bcp Venkat_Table format nul -S servername -T -c -f C:\Venkat_TableFormat.fmt 
 
-C indicates the type of columns to be assumed. C indicates the char type. In the below pic, you can see the datatypes were located as character datatype. If it's -n, then the datatype is native datatype.

6.gif

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Venkatesan Jayakantham

I am Venkatesan Prabu Jayakantham(SQL Server DBA and Dotnet developer) from India (Tamil Nadu). A Microsoft SQL Server MVP,MCITP,MCTS,MCAD,CCNA,QAI certified Expert. 

I am a Mindcracker MVP for the year 2010.

 Check my technical blog => http://venkattechnicalblog.blogspot.com/

 Check my social blog ->  http://venkatsocialblog.blogspot.com/

you can reach me @ jvprabhusanthi@gmail.com

Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the Top 5 .NET Memory Management Fundamentals
To write the best .NET code, you need to know exactly how the .NET framework really manages memory. Ricky Leeks presents the Top 5 fundamental facts of .NET memory management. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
DevExpress Free UI Controls
Become a Sponsor
 Comments
DevExpress Free UI Controls
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.