Solved

SQL -Import records into table with auto ID field

Posted on 2010-08-23
5
445 Views
Last Modified: 2012-05-10
I have a list of emails that I want to import into an table that already has records  with a auto ID field.  I just want the auto ID field to assign a number just like it does when one email is added through the form.  What syntax to I add to the SQL INSERT INTO statement to do that without messing up the data in the table.  The fields are ID, email and date and the table can be called table.

Any help is appreciated,
Thanks
0
Comment
Question by:JohnMac328
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
valkyrie_nc earned 500 total points
ID: 33501410
When you get ready to import the data, run this for the table:

SET IDENTITY INSERT [TableName] ON
GO

When you're done and ready for the identity to start again,

SET IDENTITY INSERT [TableName] OFF
GO

hth

valkyrie_nc
0
 

Author Closing Comment

by:JohnMac328
ID: 33501460
Thanks
0
 

Author Comment

by:JohnMac328
ID: 33501583
Is it possible to set that value in the table manually?  I tried running the statement in a query and I got an error.
0
 
LVL 9

Expert Comment

by:valkyrie_nc
ID: 33502615
You can only do it prior to an INSERT statement of some kind (whether T-SQL or SSIS or whatever doesn't matter AFAIK).

Post your code and error message and I'll see if I can help.
0
 

Author Comment

by:JohnMac328
ID: 33502623
No problem, I got it.

Thanks for writing back.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question