mel150
asked on
SET IDENTITY_INSERT PRODUCTS ON not working
Hi,
First I'm a real beginner, so be very basic with me, ok? I deleted a row I needed, and I have been successful in inserting a new row with all the variables. However I would like the id column value to be 384. I understand that I can re-insert the whole row if I SET IDENTITY_INSERT PRODUCTS ON, (where my table name is products), and then insert the row, with the value for id being 384:
Insert into products ("id", "code", "name")
VALUES (' 384', 'CTG', 'Heat and Eat!')
Then I should SET IDENTITY_INSERT PRODUCTS OFF.
However, if I try this, I still get an error:
"Cannot insert explicit value for identity column in table products when IDENTITY_INSERT is set to OFF."
Can anyone help? Thanks!
First I'm a real beginner, so be very basic with me, ok? I deleted a row I needed, and I have been successful in inserting a new row with all the variables. However I would like the id column value to be 384. I understand that I can re-insert the whole row if I SET IDENTITY_INSERT PRODUCTS ON, (where my table name is products), and then insert the row, with the value for id being 384:
Insert into products ("id", "code", "name")
VALUES (' 384', 'CTG', 'Heat and Eat!')
Then I should SET IDENTITY_INSERT PRODUCTS OFF.
However, if I try this, I still get an error:
"Cannot insert explicit value for identity column in table products when IDENTITY_INSERT is set to OFF."
Can anyone help? Thanks!
ASKER
Hi- thanks for this, unfortunately I am getting the same result. I copied and pasted your script. SET IDENTITY_INSERT PRODUCTS ON hit run, then
Insert into products ([id], [code], [name])
VALUES (384, 'CTG', 'Heat and Eat!')
when I hit run, I get the same error as before..
Insert into products ([id], [code], [name])
VALUES (384, 'CTG', 'Heat and Eat!')
when I hit run, I get the same error as before..
Unfortunately on this one, schema for the table is going to be necessary to know which column is being seen as an IDENTITY column.
Ben.
Ben.
ASKER
Sure thing-I hope this is what you need, I ran:
select * from information_schema.columns where table_name = 'products':
It's pretty big, if you only want certain columns please let me know:
A4989|dbo|products|id|1||N o |int|||10|10|0||||||||||
A4989|dbo|products|code|2| |YES|varch ar|100|100 |||||||iso _1|||SQL_L atin1_Gene ral_CP1_CI _AS|||
A4989|dbo|products|sale_pr ice_apply| 27|(0)|YES |tinyint|| |3|10|0||| |||||||
A4989|dbo|products|price_d isplay|28| |YES|varch ar|50|50|| |||||iso_1 |||SQL_Lat in1_Genera l_CP1_CI_A S|||
A4989|dbo|products|large_p icture|29| |YES|varch ar|100|100 |||||||iso _1|||SQL_L atin1_Gene ral_CP1_CI _AS|||
A4989|dbo|products|model_n umber|30|| YES|varcha r|100|100| ||||||iso_ 1|||SQL_La tin1_Gener al_CP1_CI_ AS|||
A4989|dbo|products|basepro d_charge|3 1|(0)|YES| float|||53 |10||||||| ||||
A4989|dbo|products|product _type|32|( 2)|YES|int |||10|10|0 ||||||||||
A4989|dbo|products|classDa te|33||YES |datetime| ||23||3|3| ||||||||
A4989|dbo|products|Prod_sh ortname|34 ||YES|varc har|50|50| ||||||iso_ 1|||SQL_La tin1_Gener al_CP1_CI_ AS|||
A4989|dbo|products|special _session|3 5|(0)|YES| bit|||1||0 ||||||||||
A4989|dbo|products|custom_ session|36 |(0)|YES|b it|||1||0| |||||||||
A4989|dbo|products|special _email|37| |YES|text| 2147483647 |214748364 7|||||||is o_1|||SQL_ Latin1_Gen eral_CP1_C I_AS|||
A4989|dbo|products|send_em ail|38|(0) |YES|bit|| |1||0||||| |||||
A4989|dbo|products|require d_items|39 ||YES|int| ||10|10|0| |||||||||
A4989|dbo|products|custom_ cat|40|(0) |YES|bit|| |1||0||||| |||||
A4989|dbo|products|custom_ image_defa ult|41||YE S|varchar| 50|50||||| ||iso_1||| SQL_Latin1 _General_C P1_CI_AS|| |
A4989|dbo|products|custom_ image_addi tional|42| |YES|varch ar|50|50|| |||||iso_1 |||SQL_Lat in1_Genera l_CP1_CI_A S|||
A4989|dbo|products|custom_ path|43|(0 )|YES|bit| ||1||0|||| ||||||
A4989|dbo|products|alt_add ition_Cat_ short_desc ription|44 ||YES|text |214748364 7|21474836 47|||||||i so_1|||SQL _Latin1_Ge neral_CP1_ CI_AS|||
A4989|dbo|products|nutriti on_flag|45 |(0)|YES|b it|||1||0| |||||||||
A4989|dbo|products|reheati ng_flag|46 |(0)|YES|b it|||1||0| |||||||||
A4989|dbo|products|reheati ng_text|47 ||YES|text |214748364 7|21474836 47|||||||i so_1|||SQL _Latin1_Ge neral_CP1_ CI_AS|||
A4989|dbo|products|wine_fl ag|48|(0)| YES|bit||| 1||0|||||| ||||
A4989|dbo|products|primary _choice|49 ||YES|text |214748364 7|21474836 47|||||||i so_1|||SQL _Latin1_Ge neral_CP1_ CI_AS|||
A4989|dbo|products|seconda ry_choice| 50||YES|te xt|2147483 647|214748 3647|||||| |iso_1|||S QL_Latin1_ General_CP 1_CI_AS|||
A4989|dbo|products|display _name|51|( 0)|YES|bit |||1||0||| |||||||
A4989|dbo|products|to_go|5 2|(0)|YES| bit|||1||0 ||||||||||
A4989|dbo|products|maximum _item|53|( 0)|YES|int |||10|10|0 ||||||||||
A4989|dbo|products|persona l_chef|54| (0)|YES|bi t|||1||0|| ||||||||
A4989|dbo|products|sp_deli very|55|(0 )|YES|bit| ||1||0|||| ||||||
A4989|dbo|products|weight| 56|(0)|YES |float|||5 3|10|||||| |||||
A4989|dbo|products|charge_ tax|57|(0) |YES|bit|| |1||0||||| |||||
A4989|dbo|products|heart|5 8||YES|tex t|21474836 47|2147483 647||||||| iso_1|||SQ L_Latin1_G eneral_CP1 _CI_AS|||
A4989|dbo|products|dsp_sho rt_desc|59 |(0)|YES|b it|||1||0| |||||||||
A4989|dbo|products|oversiz e|60|(0)|Y ES|smallin t|||5|10|0 ||||||||||
A4989|dbo|products|specifi c_product_ type_id|61 ||YES|int| ||10|10|0| |||||||||
A4989|dbo|products|high_co st|62|(0.0 000)|No |money|||19|10|4||||||||||
A4989|dbo|products|reporti ng_categor y|63||YES| varchar|50 |50||||||| iso_1|||SQ L_Latin1_G eneral_CP1 _CI_AS|||
A4989|dbo|products|ingredi ents|64||Y ES|varchar |1000|1000 |||||||iso _1|||SQL_L atin1_Gene ral_CP1_CI _AS|||
A4989|dbo|products|class_d ay_time|65 ||YES|varc har|50|50| ||||||iso_ 1|||SQL_La tin1_Gener al_CP1_CI_ AS|||
A4989|dbo|products|max_sea ts_in_clas s|66||YES| int|||10|1 0|0||||||| |||
A4989|dbo|products|product ion_time|6 7|(0)|No |int|||10|10|0||||||||||
A4989|dbo|products|batch_s ize|68|(0) |No |int|||10|10|0||||||||||
A4989|dbo|products|weekly_ average|69 |(0)|No |float|||53|10|||||||||||
A4989|dbo|products|activat ion_date|7 0|(getdate ())|No |datetime|||23||3|3||||||| ||
A4989|dbo|products|deactiv ation_date |71|(getda te())|YES| datetime|| |23||3|3|| |||||||
A4989|dbo|products|decreme nt_invento ry|72|(1)| No |tinyint|||3|10|0||||||||| |
A4989|dbo|products|packagi ng_time|73 |(0)|No |int|||10|10|0||||||||||
A4989|dbo|products|name|3| |YES|varch ar|256|256 |||||||iso _1|||SQL_L atin1_Gene ral_CP1_CI _AS|||
A4989|dbo|products|descrip tion|4||YE S|text|214 7483647|21 47483647|| |||||iso_1 |||SQL_Lat in1_Genera l_CP1_CI_A S|||
A4989|dbo|products|short_d escription |5||YES|te xt|2147483 647|214748 3647|||||| |iso_1|||S QL_Latin1_ General_CP 1_CI_AS|||
A4989|dbo|products|keyword s|6||YES|t ext|214748 3647|21474 83647||||| ||iso_1||| SQL_Latin1 _General_C P1_CI_AS|| |
A4989|dbo|products|ship_no te|7||YES| text|21474 83647|2147 483647|||| |||iso_1|| |SQL_Latin 1_General_ CP1_CI_AS| ||
A4989|dbo|products|image_f ile_name|8 ||YES|varc har|100|10 0|||||||is o_1|||SQL_ Latin1_Gen eral_CP1_C I_AS|||
A4989|dbo|products|active| 9|(1)|No |tinyint|||3|10|0||||||||| |
A4989|dbo|products|visible _web_only| 10|(0)|YES |tinyint|| |3|10|0||| |||||||
A4989|dbo|products|new|11| |YES|tinyi nt|||3|10| 0||||||||| |
A4989|dbo|products|special |12|(0)|YE S|tinyint| ||3|10|0|| ||||||||
A4989|dbo|products|discoun t|13|(0)|Y ES|tinyint |||3|10|0| |||||||||
A4989|dbo|products|taxable |14|(1)|YE S|tinyint| ||3|10|0|| ||||||||
A4989|dbo|products|price|1 5|(0)|YES| money|||19 |10|4||||| |||||
A4989|dbo|products|sale_pr ice|16|(0) |YES|money |||19|10|4 ||||||||||
A4989|dbo|products|cost|17 |(0)|No |money|||19|10|4||||||||||
A4989|dbo|products|unit|18 ||YES|varc har|50|50| ||||||iso_ 1|||SQL_La tin1_Gener al_CP1_CI_ AS|||
A4989|dbo|products|manufac turer_id|1 9||YES|int |||10|10|0 ||||||||||
A4989|dbo|products|stock|2 0|(0)|YES| int|||10|1 0|0||||||| |||
A4989|dbo|products|us_only |21|(0)|YE S|tinyint| ||3|10|0|| ||||||||
A4989|dbo|products|gift_ce rt|22|(0)| YES|bit||| 1||0|||||| ||||
A4989|dbo|products|gift_ce rt_force_v alue|23|(0 )|YES|bit| ||1||0|||| ||||||
A4989|dbo|products|sizes|2 4|(0)|YES| tinyint||| 3|10|0|||| ||||||
A4989|dbo|products|invento ry_control |25|(0)|YE S|int|||10 |10|0||||| |||||
A4989|dbo|products|thumbna il|26||YES |varchar|5 0|50|||||| |iso_1|||S QL_Latin1_ General_CP 1_CI_AS|||
Thanks so much!
select * from information_schema.columns
It's pretty big, if you only want certain columns please let me know:
A4989|dbo|products|id|1||N
A4989|dbo|products|code|2|
A4989|dbo|products|sale_pr
A4989|dbo|products|price_d
A4989|dbo|products|large_p
A4989|dbo|products|model_n
A4989|dbo|products|basepro
A4989|dbo|products|product
A4989|dbo|products|classDa
A4989|dbo|products|Prod_sh
A4989|dbo|products|special
A4989|dbo|products|custom_
A4989|dbo|products|special
A4989|dbo|products|send_em
A4989|dbo|products|require
A4989|dbo|products|custom_
A4989|dbo|products|custom_
A4989|dbo|products|custom_
A4989|dbo|products|custom_
A4989|dbo|products|alt_add
A4989|dbo|products|nutriti
A4989|dbo|products|reheati
A4989|dbo|products|reheati
A4989|dbo|products|wine_fl
A4989|dbo|products|primary
A4989|dbo|products|seconda
A4989|dbo|products|display
A4989|dbo|products|to_go|5
A4989|dbo|products|maximum
A4989|dbo|products|persona
A4989|dbo|products|sp_deli
A4989|dbo|products|weight|
A4989|dbo|products|charge_
A4989|dbo|products|heart|5
A4989|dbo|products|dsp_sho
A4989|dbo|products|oversiz
A4989|dbo|products|specifi
A4989|dbo|products|high_co
A4989|dbo|products|reporti
A4989|dbo|products|ingredi
A4989|dbo|products|class_d
A4989|dbo|products|max_sea
A4989|dbo|products|product
A4989|dbo|products|batch_s
A4989|dbo|products|weekly_
A4989|dbo|products|activat
A4989|dbo|products|deactiv
A4989|dbo|products|decreme
A4989|dbo|products|packagi
A4989|dbo|products|name|3|
A4989|dbo|products|descrip
A4989|dbo|products|short_d
A4989|dbo|products|keyword
A4989|dbo|products|ship_no
A4989|dbo|products|image_f
A4989|dbo|products|active|
A4989|dbo|products|visible
A4989|dbo|products|new|11|
A4989|dbo|products|special
A4989|dbo|products|discoun
A4989|dbo|products|taxable
A4989|dbo|products|price|1
A4989|dbo|products|sale_pr
A4989|dbo|products|cost|17
A4989|dbo|products|unit|18
A4989|dbo|products|manufac
A4989|dbo|products|stock|2
A4989|dbo|products|us_only
A4989|dbo|products|gift_ce
A4989|dbo|products|gift_ce
A4989|dbo|products|sizes|2
A4989|dbo|products|invento
A4989|dbo|products|thumbna
Thanks so much!
Cn you check whetther there exists, more than one table with the name 'products' with different owners...
you can use enterprise manger or the following Query
select * from INFORMATION_SCHEMA.TABLES
WHERE table_name = 'products'
you can use enterprise manger or the following Query
select * from INFORMATION_SCHEMA.TABLES
WHERE table_name = 'products'
ASKER
No, only the one table products:
select * from INFORMATION_SCHEMA.TABLES
WHERE table_name = 'products'
select * from INFORMATION_SCHEMA.TABLES
WHERE table_name = 'products'
However, I have a development website, and I know that the product id 384 shows up in various tables in various guises, for instance it may be in product_table_group_member where product_id=384
Could that be the issue here?
select * from INFORMATION_SCHEMA.TABLES
WHERE table_name = 'products'
select * from INFORMATION_SCHEMA.TABLES
WHERE table_name = 'products'
However, I have a development website, and I know that the product id 384 shows up in various tables in various guises, for instance it may be in product_table_group_member
Could that be the issue here?
ASKER
sorry, I meant to show you the results of the select:
A4989|dbo|products|BASE TABLE
A4989|dbo|products|BASE TABLE
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Oh, boy, this should be fun, since the SQlL server is at our web-host. Thanks a lot, though, I am pretty sure I'll give you the points on this, just give me till tomorrow to do a little investigation. Thanks again!
oh sure..
you can use the following command to get the SQL server details
SELECT SERVERPROPERTY('productver sion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')
you can use the following command to get the SQL server details
SELECT SERVERPROPERTY('productver
ASKER
Sorry, sorry!! Forgot this was open.
SET IDENTITY_INSERT PRODUCTS ON
Insert into products ("id", "code", "name")
VALUES (' 384', 'CTG', 'Heat and Eat!')
SET IDENTITY_INSERT PRODUCTS OFF
If id truly is an identity column then you should be inserting a number not a string - see script below and note that 384 is nor surrounded by quotes.
Also note I have surrounded column names with square brackets. This is the default syntax for SQL Server. This may or may not have been causing you problems also. Normally you need to set Quote_Identifiers on to do it in your original syntax.
SET IDENTITY_INSERT PRODUCTS ON
Insert into products ([id], [code], [name])
VALUES (384, 'CTG', 'Heat and Eat!')
SET IDENTITY_INSERT PRODUCTS OFF