Solved

SQLServer Merge Statement when new column is added

Posted on 2016-07-22
2
45 Views
Last Modified: 2016-07-23
Hi,

  I'm planning on implementing a Change Data Capture on one of the files, we get. We get this file every week.
This file is a fixed length file and it gets loaded into our database. Since the volume of the file is large, we are planning on doing a full load for the first time, and the following load on wards, use the incremental load. We have analyzed the Merge statement for the Type-2 changes and wanted to implement it.

Now, the issue i got is that, this fixed length file may get new fields every month.
How can we utilize the merge command with respect to the schema changes and not loose any of the CDC data captured till then?

Please advise.
0
Comment
Question by:pvsbandi
2 Comments
 
LVL 16

Accepted Solution

by:
DcpKing earned 500 total points
ID: 41725983
CDC and the Merge command are different things. CDC creates a history of what has happened to the data in your table, whereas the Merge command is your choice of how to achieve the changes to that data.

The CDC works on tables, and should adapt automatically if you make changes by adding fields to those tables - which it sounds like you'll be doing.

The Merge command works down at the field level, so if you get new fields in your incoming data you'll not only have to add them to your (CDC-aware and other) tables but also you'll have to change the resultant commands that your code obeys as a result of a match condition in a Merge statement.

You may be able to write the Merge statement as dynamic SQL, but you'll still have to change table structures for the tables the data ends up in. It sounds like you'll have a monthly release schedule!!

Just a couple of refs for you about CDC - Intro and Overview and Other Features. The first is a great intro.

Hope this helps

Mike
0
 

Author Closing Comment

by:pvsbandi
ID: 41726131
Clear now. Thank you!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now