TURNING OFF IDENTITY

if i want to be able to manually insert the value of a primary key do i want IDENTITY_INSERT to be on or off?

scm0smlAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

scm0smlAuthor Commented:
if i try and do the following:
INSERT INTO CLUBTEAMS(PK_CLUBTEAMID, TEAMDESCRIPTION) VALUES (1, '1st Team')

i get:
Cannot insert explicit value for identity column in table 'CLUBTEAMS' when IDENTITY_INSERT is set to OFF.

so if i do:
SET IDENTITY_INSERT CLUBTEAMS on

i get:
IDENTITY_INSERT is already ON for table 'TaffsWellAFC.dbo.TEAMS'. Cannot perform SET operation for table 'dbo.CLUBTEAMS'.

whats going on?
0
scm0smlAuthor Commented:
there is something very strange going on here.

look at the table names....why are they changing. i do have a table called teams but i am definately running the script that i have included in this post.
0
erikTsomikSystem Architect, CF programmer Commented:
You better keep the identity off because of all the integrities
0
scm0smlAuthor Commented:
i only want to do it temp so that i can import a load of data from another db and need to keep all my f'keys etc. then it will be going back on.

i only have sql server 2005 express so have to do the import like this
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you have to first turn off the IDENTITY_INSERT on the other table, and for the future, always turn off the identity_insert once you did complete the insert
SET IDENTITY_INSERT TEAMS OFF
SET IDENTITY_INSERT CLUBTEAMS ON
INSERT INTO CLUBTEAMS(PK_CLUBTEAMID, TEAMDESCRIPTION) VALUES (1, '1st Team')  
SET IDENTITY_INSERT CLUBTEAMS OFF

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.