0

I'm trying to import an SQL Server database to mylittleadmin but for some reason, it not showing me all it options like import backup or any kind of importing method maybe it's due to permissions of my web hosting (GoDaddy).

So now am trying to insert all the data using SQL queries I already converted all my database to script but almost all tables have an identity primary key so when I tried to execute the script.

I got this error:

Cannot insert explicit value for identity column in table 'Adversaire' when IDENTITY_INSERT is set to OFF.

Suraj Kumar
  • 5,547
  • 8
  • 20
  • 42

1 Answers1

1

This is a three-step process:

  1. Turn IDENTITY_INSERT on for the table you want to insert data into. ex:

SET IDENTITY_INSERT Adversaire ON

  1. Insert your data into that table, explicitly providing values to the identity field.

INSERT INTO Adversaire (name_of_your_identity_field, other_field1, other_field2...) etc...

  1. When you're done inserting that data, be sure to turn IDENTITY_INSERT back OFF.

SET IDENTITY_INSERT Adversaire OFF

because according to the docs: At any time, only one table in a session can have the IDENTITY_INSERT property set to ON.

If the field is a Primary Key or otherwise has uniqueness constraints on it, turning on IDENTITY_INSERT still won't let you slip in duplicates. If you need to replace records that were already assigned a given ID value, you will either need to delete the old ones before inserting, or update the old records, whichever makes more sense in your application.

sql_knievel
  • 1,199
  • 1
  • 13
  • 26