| | |
Importing csv to MS SQL
Please support our MS SQL advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2009
Posts: 3
Reputation:
Solved Threads: 0
Hi everyone.
I'm relatively new to MS SQL but one of my clients has a site based entirely around it so I am having to get to know it a bit better.
While trying to clean out some of the fake emails from the mail list table they all got deleted.
I have CSV backups of the table, is there any way of importing the CSV into the table with out destroying any new entries into the table?
The table consists of 2 fields, one auto incrementing number and the email address.
The database is on a thirdparty host server and I use SQL Management Studio Express 2005 to manage the database.
Any help at all would be greatly appreciated.
Thanks
Jim
I'm relatively new to MS SQL but one of my clients has a site based entirely around it so I am having to get to know it a bit better.
While trying to clean out some of the fake emails from the mail list table they all got deleted.
I have CSV backups of the table, is there any way of importing the CSV into the table with out destroying any new entries into the table?
The table consists of 2 fields, one auto incrementing number and the email address.
The database is on a thirdparty host server and I use SQL Management Studio Express 2005 to manage the database.
Any help at all would be greatly appreciated.
Thanks
Jim
Sure you can. What I would is import the .CSV file to another table then:
You can use that to match identities but more than likely depending on if you had activity before/after the delete and whether or not your table was truncated (which would reset the identity seed value) you may have overlapping identity values with different email data. In this case you could use the same query but test to see if the email exists, and not the identity.
I hope this helps and good luck, data recovery is never fun.
sql Syntax (Toggle Plain Text)
SET IDENTITY_INSERT dbo.Email ON INSERT INTO Email (IdentityColumn, EmailColumn) SELECT IdentityColumn, EmailColumn FROM NewEmailTable WHERE NOT EXISTS ( SELECT * FROM Email (NOLOCK) WHERE Email.IdentityColumn = NewEmailTable.IdentityColumn ) SET IDENTITY_INSERT dbo.Email OFF
You can use that to match identities but more than likely depending on if you had activity before/after the delete and whether or not your table was truncated (which would reset the identity seed value) you may have overlapping identity values with different email data. In this case you could use the same query but test to see if the email exists, and not the identity.
I hope this helps and good luck, data recovery is never fun.
Last edited by sknake; Jun 16th, 2009 at 4:02 pm. Reason: typo
Open Microsoft SQL Server Management Studio, expand the server, expand database, Right click on the database --- Tasks --- Import Data, Click next, for choose data source pick "Flat File", navigate to the file, and away you go
•
•
Join Date: Jun 2009
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
Open Microsoft SQL Server Management Studio, expand the server, expand database, Right click on the database --- Tasks --- Import Data, Click next, for choose data source pick "Flat File", navigate to the file, and away you go
Any other suggestions?
•
•
•
•
Sure you can. What I would is import the .CSV file to another table then:
sql Syntax (Toggle Plain Text)
SET IDENTITY_INSERT dbo.Email ON INSERT INTO Email (IdentityColumn, EmailColumn) SELECT IdentityColumn, EmailColumn FROM NewEmailTable WHERE NOT EXISTS ( SELECT * FROM Email (NOLOCK) WHERE Email.IdentityColumn = NewEmailTable.IdentityColumn ) SET IDENTITY_INSERT dbo.Email OFF
You can use that to match identities but more than likely depending on if you had activity before/after the delete and whether or not your table was truncated (which would reset the identity seed value) you may have overlapping identity values with different email data. In this case you could use the same query but test to see if the email exists, and not the identity.
I hope this helps and good luck, data recovery is never fun.
You're right, SQL Express does not have an import option. Google on "bcp" or bulk copy and you should be able to import with that. Check out this thread:
http://social.msdn.microsoft.com/For...3-e6f0ba39a9d1
http://social.msdn.microsoft.com/For...3-e6f0ba39a9d1
•
•
Join Date: Aug 2009
Posts: 9
Reputation:
Solved Threads: 0
In the object explorer click the (+) beside the "<Server name>" then the (+) beside the "Databases" then right click the "<name of your database>" select "tasks" then select "Import Data". That's how you do it. I also use SQL Server Management Studio 2005.
![]() |
Similar Threads
- Importing csv file to SQL Server Using VB.Net (VB.NET)
- Problems with exporting from a mysql database to a .csv (PHP)
- sql into php variable (PHP)
- database or csv (Java)
- Remove quotation marks from a CSV file (C#)
Other Threads in the MS SQL Forum
- Previous Thread: Stored procedure and datatype TEXT (ASP)
- Next Thread: Can a table variable be used as an arg. for a stored procedure..?
| Thread Tools | Search this Thread |






