Eduardo Fuerte
asked on
Coul you point a way to automatically repicate an insertion on a table to another table by using MS-SQLServer?
Hi Experts
Coul you point a way to automatically repicate an insertion on a table to another table by using MS-SQLServer?
Accordingly to:
The table tb_individuo receives an insertion sent by an web-service.
Imediatelly after some columns values must to be replicated to the table assistido.
Could you suggest a way to do that?
Thanks in advance.
Coul you point a way to automatically repicate an insertion on a table to another table by using MS-SQLServer?
Accordingly to:
The table tb_individuo receives an insertion sent by an web-service.
Imediatelly after some columns values must to be replicated to the table assistido.
Could you suggest a way to do that?
Thanks in advance.
You can run a stored procedure as well to do this operation for you.
ASKER
Well.
The insertion must to be automatic, as soon the line is inserted at tb_individuo.
Maybe an insetion trigger could do the job better.
Any suggestion code on it?
The insertion must to be automatic, as soon the line is inserted at tb_individuo.
Maybe an insetion trigger could do the job better.
Any suggestion code on it?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Just one thing.
The line to be inserted on Table2 must to be just the last line inserted on Table.
The line to be inserted on Table2 must to be just the last line inserted on Table.
Then you can add a RowAddDate column in Table 1 and 2 and in trigger you can add a WHERE condition as:
WHERE Col4 = (SELECT MAX(RowAddDate) from Table1)
You can try this.
Do you want only 1 record insertion? or all the records from table 1 to table 2?
WHERE Col4 = (SELECT MAX(RowAddDate) from Table1)
You can try this.
Do you want only 1 record insertion? or all the records from table 1 to table 2?
ASKER
Yes, just the last record...
Then you can definitely filter the last record by the date column.
Or else, you can have an IDENTITY column named as RowId in your table and then use the following logic to get the last record:
SELECT TOP 1 * FROM Table1 ORDER BY RowId DESC
(Potentially silly answer) If both tables are in the same database then create a view that selects all from the first table.
That avoids all the concurrency issues you'll have with two tables where if rows change in one then you'd always have to pull off changing it in the other.
That avoids all the concurrency issues you'll have with two tables where if rows change in one then you'd always have to pull off changing it in the other.
ASKER
@Pratik Somaiya answer is pratically running well.... testing...
ASKER
Hi @Pratik Somaiya
The job is done, thank you very much!
@Jim
I couldn't even try your suggestion... in a hurry...
The job is done, thank you very much!
@Jim
I couldn't even try your suggestion... in a hurry...
Open in new window