?
Solved

TURNING OFF IDENTITY TEMPORARILY

Posted on 2008-02-06
7
Medium Priority
?
685 Views
Last Modified: 2008-03-06
I need to transfer a copy of one database into the other.

the database hasnt got that much in it at the moment but to re-enter all the data would be too big a pain.

I only have sql server 2005 express so cannot export the data into a file(or can i?)

so i can create a load of insert statements easily enough using sql....

but i need to maintain all my primary keys etc but im getting:
Cannot insert explicit value for identity column in table 'FIXTURES' when IDENTITY_INSERT is set to OFF.

when i try....

rather than have to change this setting on each table is their a gloabl setting i can change temporairly on my database using sql and then switch it back in once i have run all my inerst statements?

thanks in advance

0
Comment
Question by:scm0sml
  • 5
  • 2
7 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 20834539
SET IDENTITY_INSERT ON
Go
--ur insert Statements
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 20834545
I forgot to mention the tablke name

SET IDENTITY_INSERT Fixtures  ON

0
 

Author Comment

by:scm0sml
ID: 20834554
yeah but can this not be done for the database as one setting so i dont have to do it for each table, then turn it back off for each table?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 20834625
No, you have to do this manually for each table
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 total points
ID: 20834641
SELECT 'SET IDENTITY_INSERT '+TABLE_NAME+' on '
from INformation_schema.Tables

the above will create a list which can be copied and run before you run the insert statement
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 20834724
Thanks for the points, with this I crossed 5,000,000 Expert points  :)
0
 

Author Comment

by:scm0sml
ID: 20834742
congrats!!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses

600 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