How to ignore duplicate Primary Key in SQL? -
i have excel sheet several values imported sql (book1$) , want transfer values processlist. several rows have same primary keys processid because rows contain original , modified values, both of want keep. how make sql ignore duplicate primary keys?
i tried ignore_dup_key = on rows duplicated primary key, 1 latest row shows up.
create table dbo.processlist ( edited varchar(1), processid int not null primary key (ignore_dup_key = on), name varchar(30) not null, amount smallmoney not null, creationdate datetime not null, modificationdate datetime ) insert processlist select edited, processid, name, amount, creationdate, modificationdate book1$ select * processlist
also, if have row , update values of row, there way keep original values of row , insert clone of row below, updated values , creation/modification date updated automatically?
how make sql ignore duplicate primary keys?
under no circumstances can transaction committed results in table containing 2 distinct rows same primary key. fundamental nature of primary key. sql server's ignore_dup_key
option not change -- merely affects how sql server handles problem. (with option turned on silently refuses insert rows having same primary key existing row; otherwise, such insertion attempt causes error.)
you can address situation either dropping primary key constraint or adding 1 or more columns primary key yield composite key collective value not duplicated. don't see candidate columns expanded pk among described, though. if drop pk might make sense add synthetic, autogenerated pk column.
also, if have row , update values of row, there way keep original values of row , insert clone of row below, updated values , creation/modification date updated automatically?
if want ensure happens automatically, row happens updated, triggers. if want way automate it, you're willing make user ask behavior, consider stored procedure.
Comments
Post a Comment