question

JinalContractor-2125 avatar image
0 Votes"
JinalContractor-2125 asked EchoLiu-msft commented

How to copy one record from different table in SQL

Hello,
How to copy one record from sourcetable.sourceDB to Destinationtable.DestinationDb in sql
By mistaken I deleted the record from destination table and I need to bring back that one record from source table>sourceDB.

sql-server-transact-sql
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Could you please validate all the answers so far and provide any update?
If all of them are not working or helpful, please provide more sample data or details about your issue.
Please remember to accept the answers if they helped. Your action would be helpful to other users who encounter the same issue and read this thread.

Thank you for understanding!

0 Votes 0 ·
EchoLiu-msft avatar image
0 Votes"
EchoLiu-msft answered EchoLiu-msft edited

Hi @JinalContractor-2125,

If there is no auto-increment column in your target, you can refer to the code of RyanAbbey-0701. If there are auto-increment columns in your target table, please refer to:

 INSERT INTO Destinationtable(Non-incremental1,Non-incremental2,Non-incrementaln)
 SELECT Non-incremental1,Non-incremental2,Non-incrementaln 
 FROM sourcetable
 WHERE <rule to identify that one record>

If you have any question, please feel free to let me know.


Regards
Echo


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RyanAbbey-0701 avatar image
0 Votes"
RyanAbbey-0701 answered

do they have the same schema? Are they on the same server?

If so,
insert into <destination>
select * from <source>
where <rule to identify that one record>

Alternatively, in the likes of SSMS, run the select statement in your source database, on the results pane, right click and copy (can't remember exactly the steps to walk through), a window should open in which you can choose to copy as an insert statement. Take the copy then go to your destination server and paste the statement, change to destination table and any other fields that need to change

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.