Unix Technical Forum

Compairing updated data base.

This is a discussion on Compairing updated data base. within the SQL Server forums, part of the Microsoft SQL Server category; --> I do not know SQL but learning fast and furious. I am programming an agent and working with a ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 06:47 AM
Andre Arpin
 
Posts: n/a
Default Compairing updated data base.

I do not know SQL but learning fast and furious.

I am programming an agent and working with a group of existing databases.
I would like to able to compare the database before and after an update.
The testing databases are relatively small.
I have no problem programming some compare but how do I go about it.

Should I do this in SQL duplicating the database.
I would be happy to write some SQL and dump the databases and do the compare
externally.

I would appreciate any suggestion.

Andre


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 06:47 AM
David Portas
 
Posts: n/a
Default Re: Compairing updated data base.

If you just want to compare data between similar tables you can do so
with a JOIN:

SELECT COALESCE(A.key_col, B.key_col),
COALESCE(A.col1, B.col1), COALESCE(A.col2, B.col2), ...
FROM TableA AS A
FULL JOIN TableB AS B
ON A.key_col = B.key_col
WHERE COALESCE(A.col1,'')<>COALESCE(A.col1,'')
AND COALESCE(A.col2,'')<>COALESCE(A.col2,'')

assuming key_col is the primary key in both tables.

--
David Portas
SQL Server MVP
--

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 06:47 AM
Andre Arpin
 
Posts: n/a
Default Re: Compairing updated data base.

What I would like to do is probably
1) back up the data base
2) restore it under a different name
--- run my agent
3) create a difference database ( a new database with any table which is
different)

Step 1 and 2 are easy so can be ignored
now step 3
I can create a new temporary database but how can I fill the tables in this
database using SQL



"David Portas" <REMOVE_BEFORE_REPLYING_dportas@acm.org> wrote in message
news:1111586542.235632.69940@o13g2000cwo.googlegro ups.com...
> If you just want to compare data between similar tables you can do so
> with a JOIN:
>
> SELECT COALESCE(A.key_col, B.key_col),
> COALESCE(A.col1, B.col1), COALESCE(A.col2, B.col2), ...
> FROM TableA AS A
> FULL JOIN TableB AS B
> ON A.key_col = B.key_col
> WHERE COALESCE(A.col1,'')<>COALESCE(A.col1,'')
> AND COALESCE(A.col2,'')<>COALESCE(A.col2,'')
>
> assuming key_col is the primary key in both tables.
>
> --
> David Portas
> SQL Server MVP
> --
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-29-2008, 06:47 AM
Erland Sommarskog
 
Posts: n/a
Default Re: Compairing updated data base.

Andre Arpin (arpin@kingston.net) writes:
> What I would like to do is probably
> 1) back up the data base
> 2) restore it under a different name
> --- run my agent
> 3) create a difference database ( a new database with any table which is
> different)
>
> Step 1 and 2 are easy so can be ignored
> now step 3
> I can create a new temporary database but how can I fill the tables in
> this database using SQL


Red Gate has products for this, check out http://www.red-gate.com/.

If you would like to roll your own, you would have to write a query
like the one that David showed you for each table.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-29-2008, 06:48 AM
David Portas
 
Posts: n/a
Default Re: Compairing updated data base.

You can easily populate a table from another in a different database:

INSERT INTO DatabaseA.dbo.TableA (col1, col2, ...)
SELECT col1, col2, ...
FROM DatabaseB.dbo.TableB
WHERE ... ?

--
David Portas
SQL Server MVP
--

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:36 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com