MS SQL - Synchronize 2 tables definition

Hi,
Is there any stored procedure that can help to synchronize 2 tables definitions?
Let say I have table A and I want fields in table B (not existing in table A) to be added to table A.
And if any datatype change is picked up on common fields, adjust fields in table A
Only at table definition.
Omer-PitouAsked:
Who is Participating?
 
Scott PletcherConnect With a Mentor Senior DBACommented:
No, there's no system procedure that comes with SQL Server that would do that for you.  It would have to be custom code.
0
 
PortletPaulfreelancerCommented:
and good luck with automating "And if any datatype change is picked up on common fields, adjust fields in table A"

How broad is that requirement.

e.g. From varchar to datetime? From varchar(250) to varchar(4)? (both are likely to have exceptions in the data)
0
 
Omer-PitouAuthor Commented:
It can be done. In this case you can force the column to be truncated. It is just a lot of coding.
0
 
Vitor MontalvãoConnect With a Mentor MSSQL Senior EngineerCommented:
It can be done. In this case you can force the column to be truncated. It is just a lot of coding.
Yes it can be done and maybe with less coding that you think. Check for DDL triggers. Here's a starting point for you:
CREATE TRIGGER TableChanges
ON DATABASE 
FOR ALTER_TABLE 
AS 
   (...)

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.