Skip to main content

Import CSV File Into SQL Server [solved]

CSV stands for Comma Separated Values, sometimes also called Comma Delimited Values.
Create TestTable
USE TestData
GO
CREATE TABLE CSVTest(ID INT,FirstName VARCHAR(40),LastName VARCHAR(40),BirthDate SMALLDATETIME)GO
Create CSV file in drive C: with name sweetest. text with the following content. The location of the file is C:\csvtest.txt
1,James,Smith,19750101
2,Meggie,Smith,19790122
3,Robert,Smith,20071101
4,Alex,Smith,20040202
Now run following script to load all the data from CSV to database table. If there is any error in any row it will be not inserted but other rows will be inserted.
BULK
INSERT 
CSVTestFROM 'c:\csvtest.txt'WITH(FIELDTERMINATOR = ',',ROWTERMINATOR = '\n')GO--Check the content of the table.SELECT *FROM CSVTest
GO
--Drop the table to clean up database.DROP TABLE CSVTest
GO

Comments

Popular posts from this blog

Contact us Forms Links

Hi Friends This is my second post to blogger.com. and this time I am going to share my few useful resource links with you all. This post is regarding to “How to create contact us form to the html page” So please go to the following sites 1) http://wufoo.com/gallery/templates/forms/contact-form/ Thats it

By pass single quote or special character in ck editor or fck editor in any language

By pass single quote or special character in ck editor or fck editor in any language like asp.net , php etc   whenever we are using ckeditor or fckeditor we are able to pass the data successfully but if single quote  '  or symbols like '|>|<|\\+ is present in our content then it will not save the data I search a lot for the solution of this topic.  Every post is provide some rumors but finally after using ck editor for long time, i found the solution. so friends now you can pass any type of data in fckeditor or ck editor  ------------------------------------------------------------------------------------------------------------------------ AdditionalNumericEntities With this setting, you can define a set of characters which will be translated to their relative numeric entities in the output HTML. This is quite useful if you don't want single quotes (') to be inserted in the text (being transformed to ′):...
10 must read SQL Server A buddy of mine Ted Krueger writes some really interesting SQL Server posts. Most of these posts focus more on administration than on developer stuff but still stuff that is useful to a developer. Here are 10 of my favorites, I liked these and you will too! 6 ways to import data into SQL Server Recover a database without the ldf file Dynamic column names and fields in SSRS (Custom Matrix) Rebuild master and restore system databases from complete disk failure Do not truncate your ldf files! Proactive Deadlock Notifications Troubleshooting Blocking 101 on SQL Server Not a fan of the Report Manager in SSRS? Using SSRS procedures to get the job done Dynamic Data Sources in SSRS Quick Data Model creation off SSAS Data Source in SSRS