4

I am developing an asp.net mvc application. I have a very large data set in a CSV file that I want to import into a SQL Server Express database.

What is the simplest way to go about this task? Ideally I just want to import the data and the table will be created automatically with the columns defined and the data.

RickAndMSFT
  • 20,912
  • 8
  • 60
  • 78
General_9
  • 2,249
  • 4
  • 28
  • 46
  • 2
    IF you have a full version of SQL Server Management Studio somewhere - just connect to your Express instance, find your database in the Object Explorer, right-click on it, select `Tasks > Import Data` and follow that wizard through - it allows you to map columns, skip rows, rename columns - whatever you dream of. At the end - run the package, and your data is loaded into your SQL Server table. – marc_s Feb 22 '12 at 17:06
  • retag-remove MVC, this question has nothing to do with MVC. Marc gives the right answer. – RickAndMSFT Feb 22 '12 at 19:28
  • Duplicate of http://stackoverflow.com/questions/10418461/how-to-create-and-populate-a-table-in-a-single-step-as-part-of-a-csv-import-oper http://stackoverflow.com/questions/15655380/import-csv-into-sql-server-including-automatic-table-creation ? – Robert Cutajar Feb 13 '15 at 09:34

2 Answers2

3

Marc is right, just download Microsoft SQL Server 2008 R2 RTM - Management Studio Express and import the data

RickAndMSFT
  • 20,912
  • 8
  • 60
  • 78
  • I'm on Debian 11 so SSMS will not work for me. Also, the Import Flat File Wizard for Visual Studio Code is hanging without an error message. – Shawn Eary Jan 23 '23 at 20:54
0

I know this is an old thread but I figured out a way to do this by accident. From a 2008 R2 full version of SQL I created a script from a Database table by using the script wizzard and scripting the data with the script. All you would need to do is add a few columns to your spreadsheet like insert table name etc.. all this wizard does is create a CSV type file using commas and N for the escape character. see example here. hope this helps someone... BTW save it as a .sql file and open it in a query window and execute it!

USE [databaseName]
GO
/****** Object:  Table [dbo].[DrNames]    Script Date: 02/06/2014 22:44:44 ******/
SET IDENTITY_INSERT [dbo].[DrNames] ON
INSERT [dbo].[DrNames] ([ID], [DrName], [PreFix], [EmailAddress]) VALUES (1, N'test1 Dr Name', N'Psy.D.', N'TestDrNAme1@DrPlace.com')
INSERT [dbo].[DrNames] ([ID], [DrName], [PreFix], [EmailAddress]) VALUES (2, N'test2 Dr Name', N'Psy.D.', N'TestDrNAme2@DrPlace.com')
INSERT [dbo].[DrNames] ([ID], [DrName], [PreFix], [EmailAddress]) VALUES (3, N'test3 Dr Name', N'Ph.D.', N'TestDrNAme3@DrPlace.com')
INSERT [dbo].[DrNames] ([ID], [DrName], [PreFix], [EmailAddress]) VALUES (4, N'test4 Dr Name', N'MD', N'TestDrNAme4@DrPlace.com')
Robert Cutajar
  • 3,181
  • 1
  • 30
  • 42
tmac
  • 37
  • 7