Clone/Duplicate Records in SQL Server with automatic increment of ids -


i want duplicate rows registry_id = 1 , id's of cloned rows should automatically incremented.

when execute

insert [zac2].[dbo].[rubrics]    ([reference]   ,[name_de]   ,[name_fr]   ,[name_en]   ,[name_es]   ,[registry_id]   ,[registry_type]   ,[parent_id]   ,[created_at]   ,[updated_at]   ,[creator_id]   ,[updater_id]   ,[level]   ,[inherited_rating]   ,[has_children]) select ([reference]   ,[name_de]   ,[name_fr]   ,[name_en]   ,[name_es]   ,[registry_id]   ,[registry_type]   ,[parent_id]   ,[created_at]   ,[updated_at]   ,[creator_id]   ,[updater_id]   ,[level]   ,[inherited_rating]   ,[has_children] [zac2].[dbo].[rubrics]    registry_id=1 

i error message:

cannot insert duplicate key row in object 'dbo.rubrics' unique index 'idx_rubrics_reference_registry'. duplicate key value (0, 1, registryplan).

with script keys > create > new query editor window get:

alter table [dbo].[rubrics]  add primary key clustered ([id] asc)     (pad_index  = off, statistics_norecompute  = off, sort_in_tempdb = off,            ignore_dup_key = off, online = off, allow_row_locks  = on,            allow_page_locks  = on, fillfactor = 80 ) on [primary] 

with script table > insert > new query editor window get:

(<reference, varchar(255),>            ,<rating, varchar(1),>            ,<name_de, varchar(255),>            ,<name_fr, varchar(255),>            ,<name_en, varchar(255),>            ,<name_es, varchar(255),>            ,<registry_id, int,>            ,<registry_type, varchar(255),>            ,<parent_id, int,>            ,<created_at, datetime,>            ,<updated_at, datetime,>            ,<creator_id, int,>            ,<updater_id, int,>            ,<level, int,>            ,<inherited_rating, varchar(1),>            ,<has_children, bit,>) 

@marc_s absolutely right, didn't read error messages correctly. idx_rubrics_reference_registry has unique constraint , therefor not duplicate rows. changed (in fact insert method id reference registry) , works. lot!


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -