Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL -Import records into table with auto ID field

Posted on 2010-08-23
5
Medium Priority
?
448 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 2000 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

664 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