Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MS SQL - Synchronize 2 tables definition

Posted on 2015-02-09
4
Medium Priority
?
84 Views
Last Modified: 2015-02-13
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.
0
Comment
Question by:Omer-Pitou
4 Comments
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 750 total points
ID: 40599562
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
 
LVL 49

Expert Comment

by:PortletPaul
ID: 40600029
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
 

Author Comment

by:Omer-Pitou
ID: 40600043
It can be done. In this case you can force the column to be truncated. It is just a lot of coding.
0
 
LVL 52

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 750 total points
ID: 40600943
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

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how the fundamental information of how to create a table.

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question