Solved

SQL -Import records into table with auto ID field

Posted on 2010-08-23
5
440 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
  • 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now