Hello, my question here in reference to SQL 2016...
Here's my example to simplify.
I have two tables within same DB as follows.
Parent table:
CREATE TABLE [dbo].Machine ON [PRIMARY]
GO
Child table:
CREATE TABLE [dbo].MachineContacts ON [PRIMARY]
GO
ALTER TABLE [dbo].[MachineContacts] WITH CHECK ADD CONSTRAINT [FK_MachineID] FOREIGN KEY([MachineID])
REFERENCES [dbo].[Machine] ([MachineID])
GO
ALTER TABLE [dbo].[MachineContacts] CHECK CONSTRAINT [FK_MachineID]
GO
Here are all of the records in Parent table:
select * from [dbo].[Machine]
MachineId MachineName MachineStatus
1 Server1 Active
2 Server1 Inactive
Here are all of the records in it's Child table (just one for now):
select * from [dbo].[MachineContacts]
MachineContactsID ContactName ContactEmail MachineID
1 Peter Peter@ssss .com 1
What is/are the SQL statement(s) required to make a duplicate copy of existing one record within Child table but with the latest MachineID?
The goal is for Child table to have two records as follows:
MachineContactsID ContactName ContactEmail MachineID
1 Peter Peter@ssss .com 1
2 Peter Peter@ssss .com 2
Both tables actually have many more records but trying to simplify examples above and trying to figure out the logic of the SQL statement(s) needed.
Looks like Join(s) will be needed perhaps. If necessary to run multiple SQL Inserts/Updates statements instead of just one am open ears.
Thanks in advance.