Ihab
asked on
How to copy a row and past it in the same table with editing some records in SQL Server Management Studio
How to copy a row and past it in the same table with editing some records in SQL Server Management Studio 2008 , Please if you give me solution in commands give me an example
Thanks
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Kvwielink
The management studio is smart enough to allow you copy/paste of a row. it won't create duplicate rows, it recognizes the primary key(identity) and regenerates a new one. also allows to modify the copied row and then saves the changes.
The management studio is smart enough to allow you copy/paste of a row. it won't create duplicate rows, it recognizes the primary key(identity) and regenerates a new one. also allows to modify the copied row and then saves the changes.
Ok, I haven't really tried it before, but I've gotten stuck on duplicate rows in the past where the management studio did allow me to modify a record to match an existing record. Once that happens, you're pretty screwed.
When you say "regenerates a new one" I guess you're assuming there's an identity column in the table? If I try to copy a single row I'm indeed able to paste it, then edit whatever value I want to change, and then commit it. But if you copy multiple rows, it tries to commit them before they can be edited. If there is no auto PK generation on said table, the records are rejected (just tested it on a test table I have).
When you say "regenerates a new one" I guess you're assuming there's an identity column in the table? If I try to copy a single row I'm indeed able to paste it, then edit whatever value I want to change, and then commit it. But if you copy multiple rows, it tries to commit them before they can be edited. If there is no auto PK generation on said table, the records are rejected (just tested it on a test table I have).
You should write an insert statement instead, where in the select portion of the query you apply the changes required. This way the new record is inserted after the required changes have been made.
Since you did not post any sample data or explain exactly what you're trying to copy, we can't provide you with an accurate sample query.