Showing posts with label structure. Show all posts
Showing posts with label structure. Show all posts

Thursday, March 29, 2012

Comparing two sets of data

I have the following situation. One set of data has 274 rows (set2)
and anther has 264 (set1). Both data sets are similar in structure as
well as values for both of them were extracts from the same parent
table. Hope the info would substitute DDL. I need to find the "gap"
rows between these two sets.
Attempted to run a query like
select count(*)
from set2
where not exists
(select *
from set1)
did not yield what I desired. What else to try?

TIA.NickName wrote:
> I have the following situation. One set of data has 274 rows (set2)
> and anther has 264 (set1). Both data sets are similar in structure as
> well as values for both of them were extracts from the same parent
> table.
> Hope the info would substitute DDL.

It doesn't.

> I need to find the "gap"
> rows between these two sets.
> Attempted to run a query like
> select count(*)
> from set2
> where not exists
> (select *
> from set1)
> did not yield what I desired. What else to try?

Try posting your DDL. We at least need column names and keys to help you
here.

Zach|||OK,

I've proven that the "EXISTS" keyword/function can't solve this
problem. But then what?

-- test equality between two data sets
-- desired resultset: return "gap" rows

-- DDL and DML
create table #tmp1 (col1 int, col2 char(1));

insert into #tmp1
values(1,'a')
insert into #tmp1
values(2,'b')
insert into #tmp1
values(3,'c')
insert into #tmp1
values(4,'d')
insert into #tmp1
values(5,'e');

select * into #tmp2
from #tmp1
where col1 < 5;
select *
from #tmp1
where not exists
(select *
from #tmp2)|||NickName (dadada@.rock.com) writes:
> I've proven that the "EXISTS" keyword/function can't solve this
> problem. But then what?

It certainly can, but you must specify how the NOT EXISTS is to work.
SQL is not about telepathy.

For your repro, you could do

select *
from #tmp1 t1
where not exists (Select *
from #tmp2 t2
WHERE t1.col1 = t2.col1)

or

select *
from #tmp1 t1
where not exists (Select *
from #tmp2 t
WHERE t1.col1 = t2.col1
AND t1.col2 = t2.col2)

depending on what you are looking for. The first just lists missing key
values, the second list all mismatches.

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

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Thanks, Erland.
*) laziness is an enemy, I thought about that but the table has a large
number of columns, so, was wondering if there's another approach. Will
try it tomorrow when the db is available.
*) btw, I like the word, "telepathy".

Erland Sommarskog wrote:
> NickName (dadada@.rock.com) writes:
> > I've proven that the "EXISTS" keyword/function can't solve this
> > problem. But then what?
> It certainly can, but you must specify how the NOT EXISTS is to work.
> SQL is not about telepathy.
> For your repro, you could do
> select *
> from #tmp1 t1
> where not exists (Select *
> from #tmp2 t2
> WHERE t1.col1 = t2.col1)
> or
> select *
> from #tmp1 t1
> where not exists (Select *
> from #tmp2 t
> WHERE t1.col1 = t2.col1
> AND t1.col2 = t2.col2)
> depending on what you are looking for. The first just lists missing
key
> values, the second list all mismatches.
>
> --
> Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
> Books Online for SQL Server SP3 at
> http://www.microsoft.com/sql/techin.../2000/books.asp|||NickName (dadada@.rock.com) writes:
> Thanks, Erland.
> *) laziness is an enemy, I thought about that but the table has a large
> number of columns, so, was wondering if there's another approach. Will
> try it tomorrow when the db is available.

If your aim is to find differences in any column, you will indeed have
to write code that has all column. There is no shortcut. What you can
do, if you have many tables and columns, is to generate code by reading
metadata. But this requires that you have a clear understanding for which
columns you want to compare, and which you do not.

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

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Erland,

Something seems odd. Here's two test cases. Both are successful.
-- test equality between two data sets (with exact meta data)
-- desired resultset: return "gap" rows

-- DDL and DML
create table #tmp1 (col1 int, col2 char(1));

insert into #tmp1
values(1,'a')
insert into #tmp1
values(2,'b')
insert into #tmp1
values(3,'c')
insert into #tmp1
values(4,'d')
insert into #tmp1
values(5,'e');

select * into #tmp2
from #tmp1
where col1 < 5;

select *
from #tmp1 t1
where not exists
(select *
from #tmp2 t2
where t1.col1 = t2.col1
and t1.col2 = t2.col2)

-- outcome = success

-- test equality between two data sets
-- with minor meta data difference (one table has 3 attributes while
the other has 2)
-- note: comparison seems still successful
-- desired resultset: return "gap" rows

drop table #tmp1
drop table #tmp2;

-- DDL and DML
create table #tmp1 (col1 int, col2 char(1),col3 int);

insert into #tmp1
values(1,'a',11)
insert into #tmp1
values(2,'b',22)
insert into #tmp1
values(3,'c',33)
insert into #tmp1
values(4,'d',44)
insert into #tmp1
values(5,'e',55);

select col1,col2 into #tmp2
from #tmp1
where col1 < 5;

select *
from #tmp1 t1
where not exists
(select *
from #tmp2 t2
where t1.col1 = t2.col1
and t1.col2 = t2.col2)

-- outcome = success

HOWEVER, when I applied the above to my tables (sorry I can't post
exact structure nor data here, PARENT table has 13 columns and the
derived table has 12 of them, comparison is between them), sql still
failed to find the "gap". What could possibly stands in the way?
Many thanks.|||Ahe, I think I've found the problem. In "my" tables, both has
duplicate rows, however, the number of duplicate rows are not the same,
(distinct rows are sure the same).|||NickName (dadada@.rock.com) writes:
> Ahe, I think I've found the problem. In "my" tables, both has
> duplicate rows, however, the number of duplicate rows are not the same,
> (distinct rows are sure the same).

I'm not sure how this should be addressed. Are you saying that in
one table you have two rows with the same value, but in another you
only have one?

If there are no disctinct keys in the data, all relational operations will
be problematic, that's for sure.

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

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||You might find it easier to export the table contents as ordered data and
then use a text file compare utility. Command-prompt example:

BCP "SELECT * FROM MyDatabase..Table1 ORDER BY MyPK" queryout
"C:\temp\Table1.txt" /T /c /SMyServer

BCP "SELECT * FROM MyDatabase..Table2 ORDER BY MyPK" queryout
"C:\temp\Table2.txt" /T /c /SMyServer

WINDIFF "C:\temp\Table1.txt" "C:\temp\Table2.txt"

--
Happy Holidays

Dan Guzman
SQL Server MVP

"NickName" <dadada@.rock.com> wrote in message
news:1104161334.766126.171470@.f14g2000cwb.googlegr oups.com...
> Ahe, I think I've found the problem. In "my" tables, both has
> duplicate rows, however, the number of duplicate rows are not the same,
> (distinct rows are sure the same).|||Dan Guzman (guzmanda@.nospam-online.sbcglobal.net) writes:
> You might find it easier to export the table contents as ordered data and
> then use a text file compare utility. Command-prompt example:
> BCP "SELECT * FROM MyDatabase..Table1 ORDER BY MyPK" queryout
> "C:\temp\Table1.txt" /T /c /SMyServer
> BCP "SELECT * FROM MyDatabase..Table2 ORDER BY MyPK" queryout
> "C:\temp\Table2.txt" /T /c /SMyServer
> WINDIFF "C:\temp\Table1.txt" "C:\temp\Table2.txt"

However, the use of windiff will break down if there is a column which is
permitted to be different in the tables. But there is a better alternative:
Beyond Compare, from http://www.scootersoftware.com. Beyond Compare
offers comparison on character level.

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

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Erland,

You're exactly right. Maybe they did that to test my analytic skill,
who knows :)|||Dan,

Thanks. It seems a good way to try. Will do tomorrow.

Erland, no columns are supposed to contain different data sets though
one table may have an extra column, that is supposedly the only
difference. OK, I'll try the recommended software as well when get a
chance. I appreciate it.

Donsqlsql

Comparing two databases

Are there any tools that allow you to compare two sql server databases to
find out what is different between them (the database structure, including
tables, relationships etc)? Thanks,
- Gabe
http://www.red-gate.com/sql/summary.htm
AMB
"Gabe Matteson" wrote:

> Are there any tools that allow you to compare two sql server databases to
> find out what is different between them (the database structure, including
> tables, relationships etc)? Thanks,
> - Gabe
>
>
|||Gabe Matteson wrote:
> Are there any tools that allow you to compare two sql server
> databases to find out what is different between them (the database
> structure, including tables, relationships etc)? Thanks,
> - Gabe
There are numerous schema comparison tools available. Change Manager
from Imceda/Quest Software available at www.imceda.com.
David Gugick
Quest Software
www.imceda.com
www.quest.com
|||Seconding this one...I've been using Red-gate SQL and Data compare for 2
years...fantastic products...
Kevin Hill
President
3NF Consulting
www.3nf-inc.com/NewsGroups.htm
www.DallasDBAs.com/forum - new DB forum for Dallas/Ft. Worth area DBAs.
www.experts-exchange.com - experts compete for points to answer your
questions
"Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com> wrote in message
news:E8C28859-7C90-4FD6-A40B-3490F7172846@.microsoft.com...[vbcol=seagreen]
> http://www.red-gate.com/sql/summary.htm
>
> AMB
> "Gabe Matteson" wrote:
|||Thanks!
"Gabe Matteson" <gmatteson@.inquery.biz.nospam> wrote in message
news:OdFamzndFHA.1456@.TK2MSFTNGP15.phx.gbl...
> Are there any tools that allow you to compare two sql server databases to
> find out what is different between them (the database structure, including
> tables, relationships etc)? Thanks,
> - Gabe
>
|||ErWin and ER-Studio do this as well.
Greg Jackson
PDX, Oregon
|||I agree. SQL Compare from Red Gate is brilliant.
"Kevin3NF" wrote:

> Seconding this one...I've been using Red-gate SQL and Data compare for 2
> years...fantastic products...
> --
> Kevin Hill
> President
> 3NF Consulting
> www.3nf-inc.com/NewsGroups.htm
> www.DallasDBAs.com/forum - new DB forum for Dallas/Ft. Worth area DBAs.
> www.experts-exchange.com - experts compete for points to answer your
> questions
>
> "Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com> wrote in message
> news:E8C28859-7C90-4FD6-A40B-3490F7172846@.microsoft.com...
>
>
|||you may want to look at a complete approach to change management, from your
favourite source control to your target database - DB Ghost
http://www.dbghost.com & the scripts produced always work - it's all in the
way they're produced.
regards,
Mark Baekdal
http://www.dbghost.com
http://www.innovartis.co.uk
+44 (0)208 241 1762
Build, Comparison and Synchronization from Source Control = Database change
management for SQL Server
"Gabe Matteson" wrote:

> Are there any tools that allow you to compare two sql server databases to
> find out what is different between them (the database structure, including
> tables, relationships etc)? Thanks,
> - Gabe
>
>
|||I use red-gate
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Gabe Matteson" <gmatteson@.inquery.biz.nospam> wrote in message
news:OdFamzndFHA.1456@.TK2MSFTNGP15.phx.gbl...
> Are there any tools that allow you to compare two sql server databases to
> find out what is different between them (the database structure, including
> tables, relationships etc)? Thanks,
> - Gabe
>
|||when red-gate fails (script out put has errors), DB Ghost succeeds which is
why most of our customers used to be red-gate customers.
free for MVP's, educational and non-profit organizations.
regards,
Mark Baekdal
http://www.dbghost.com
http://www.innovartis.co.uk
+44 (0)208 241 1762
Build, Comparison and Synchronization from Source Control = Database change
management for SQL Server
"Wayne Snyder" wrote:

> I use red-gate
> --
> Wayne Snyder, MCDBA, SQL Server MVP
> Mariner, Charlotte, NC
> www.mariner-usa.com
> (Please respond only to the newsgroups.)
> I support the Professional Association of SQL Server (PASS) and it's
> community of SQL Server professionals.
> www.sqlpass.org
> "Gabe Matteson" <gmatteson@.inquery.biz.nospam> wrote in message
> news:OdFamzndFHA.1456@.TK2MSFTNGP15.phx.gbl...
>
>

Comparing two databases

Are there any tools that allow you to compare two sql server databases to
find out what is different between them (the database structure, including
tables, relationships etc)? Thanks,
- Gabehttp://www.red-gate.com/sql/summary.htm
AMB
"Gabe Matteson" wrote:

> Are there any tools that allow you to compare two sql server databases to
> find out what is different between them (the database structure, including
> tables, relationships etc)? Thanks,
> - Gabe
>
>|||Gabe Matteson wrote:
> Are there any tools that allow you to compare two sql server
> databases to find out what is different between them (the database
> structure, including tables, relationships etc)? Thanks,
> - Gabe
There are numerous schema comparison tools available. Change Manager
from Imceda/Quest Software available at www.imceda.com.
David Gugick
Quest Software
www.imceda.com
www.quest.com|||Seconding this one...I've been using Red-gate SQL and Data compare for 2
years...fantastic products...
Kevin Hill
President
3NF Consulting
www.3nf-inc.com/NewsGroups.htm
www.DallasDBAs.com/forum - new DB forum for Dallas/Ft. Worth area DBAs.
www.experts-exchange.com - experts compete for points to answer your
questions
"Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com> wrote in message
news:E8C28859-7C90-4FD6-A40B-3490F7172846@.microsoft.com...[vbcol=seagreen]
> http://www.red-gate.com/sql/summary.htm
>
> AMB
> "Gabe Matteson" wrote:
>|||Thanks!
"Gabe Matteson" <gmatteson@.inquery.biz.nospam> wrote in message
news:OdFamzndFHA.1456@.TK2MSFTNGP15.phx.gbl...
> Are there any tools that allow you to compare two sql server databases to
> find out what is different between them (the database structure, including
> tables, relationships etc)? Thanks,
> - Gabe
>|||ErWin and ER-Studio do this as well.
Greg Jackson
PDX, Oregon|||I agree. SQL Compare from Red Gate is brilliant.
"Kevin3NF" wrote:

> Seconding this one...I've been using Red-gate SQL and Data compare for 2
> years...fantastic products...
> --
> Kevin Hill
> President
> 3NF Consulting
> www.3nf-inc.com/NewsGroups.htm
> www.DallasDBAs.com/forum - new DB forum for Dallas/Ft. Worth area DBAs.
> www.experts-exchange.com - experts compete for points to answer your
> questions
>
> "Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com> wrote in messag
e
> news:E8C28859-7C90-4FD6-A40B-3490F7172846@.microsoft.com...
>
>|||you may want to look at a complete approach to change management, from your
favourite source control to your target database - DB Ghost
http://www.dbghost.com & the scripts produced always work - it's all in the
way they're produced.
regards,
Mark Baekdal
http://www.dbghost.com
http://www.innovartis.co.uk
+44 (0)208 241 1762
Build, Comparison and Synchronization from Source Control = Database change
management for SQL Server
"Gabe Matteson" wrote:

> Are there any tools that allow you to compare two sql server databases to
> find out what is different between them (the database structure, including
> tables, relationships etc)? Thanks,
> - Gabe
>
>|||I use red-gate
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Gabe Matteson" <gmatteson@.inquery.biz.nospam> wrote in message
news:OdFamzndFHA.1456@.TK2MSFTNGP15.phx.gbl...
> Are there any tools that allow you to compare two sql server databases to
> find out what is different between them (the database structure, including
> tables, relationships etc)? Thanks,
> - Gabe
>|||when red-gate fails (script out put has errors), DB Ghost succeeds which is
why most of our customers used to be red-gate customers.
free for MVP's, educational and non-profit organizations.
regards,
Mark Baekdal
http://www.dbghost.com
http://www.innovartis.co.uk
+44 (0)208 241 1762
Build, Comparison and Synchronization from Source Control = Database change
management for SQL Server
"Wayne Snyder" wrote:

> I use red-gate
> --
> Wayne Snyder, MCDBA, SQL Server MVP
> Mariner, Charlotte, NC
> www.mariner-usa.com
> (Please respond only to the newsgroups.)
> I support the Professional Association of SQL Server (PASS) and it's
> community of SQL Server professionals.
> www.sqlpass.org
> "Gabe Matteson" <gmatteson@.inquery.biz.nospam> wrote in message
> news:OdFamzndFHA.1456@.TK2MSFTNGP15.phx.gbl...
>
>sqlsql

Comparing two databases

Are there any tools that allow you to compare two sql server databases to
find out what is different between them (the database structure, including
tables, relationships etc)? Thanks,
- Gabe
http://www.red-gate.com/sql/summary.htm
AMB
"Gabe Matteson" wrote:

> Are there any tools that allow you to compare two sql server databases to
> find out what is different between them (the database structure, including
> tables, relationships etc)? Thanks,
> - Gabe
>
>
|||Gabe Matteson wrote:
> Are there any tools that allow you to compare two sql server
> databases to find out what is different between them (the database
> structure, including tables, relationships etc)? Thanks,
> - Gabe
There are numerous schema comparison tools available. Change Manager
from Imceda/Quest Software available at www.imceda.com.
David Gugick
Quest Software
www.imceda.com
www.quest.com
|||Seconding this one...I've been using Red-gate SQL and Data compare for 2
years...fantastic products...
Kevin Hill
President
3NF Consulting
www.3nf-inc.com/NewsGroups.htm
www.DallasDBAs.com/forum - new DB forum for Dallas/Ft. Worth area DBAs.
www.experts-exchange.com - experts compete for points to answer your
questions
"Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com> wrote in message
news:E8C28859-7C90-4FD6-A40B-3490F7172846@.microsoft.com...[vbcol=seagreen]
> http://www.red-gate.com/sql/summary.htm
>
> AMB
> "Gabe Matteson" wrote:
|||Thanks!
"Gabe Matteson" <gmatteson@.inquery.biz.nospam> wrote in message
news:OdFamzndFHA.1456@.TK2MSFTNGP15.phx.gbl...
> Are there any tools that allow you to compare two sql server databases to
> find out what is different between them (the database structure, including
> tables, relationships etc)? Thanks,
> - Gabe
>
|||ErWin and ER-Studio do this as well.
Greg Jackson
PDX, Oregon
|||I agree. SQL Compare from Red Gate is brilliant.
"Kevin3NF" wrote:

> Seconding this one...I've been using Red-gate SQL and Data compare for 2
> years...fantastic products...
> --
> Kevin Hill
> President
> 3NF Consulting
> www.3nf-inc.com/NewsGroups.htm
> www.DallasDBAs.com/forum - new DB forum for Dallas/Ft. Worth area DBAs.
> www.experts-exchange.com - experts compete for points to answer your
> questions
>
> "Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com> wrote in message
> news:E8C28859-7C90-4FD6-A40B-3490F7172846@.microsoft.com...
>
>
|||you may want to look at a complete approach to change management, from your
favourite source control to your target database - DB Ghost
http://www.dbghost.com & the scripts produced always work - it's all in the
way they're produced.
regards,
Mark Baekdal
http://www.dbghost.com
http://www.innovartis.co.uk
+44 (0)208 241 1762
Build, Comparison and Synchronization from Source Control = Database change
management for SQL Server
"Gabe Matteson" wrote:

> Are there any tools that allow you to compare two sql server databases to
> find out what is different between them (the database structure, including
> tables, relationships etc)? Thanks,
> - Gabe
>
>
|||I use red-gate
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Gabe Matteson" <gmatteson@.inquery.biz.nospam> wrote in message
news:OdFamzndFHA.1456@.TK2MSFTNGP15.phx.gbl...
> Are there any tools that allow you to compare two sql server databases to
> find out what is different between them (the database structure, including
> tables, relationships etc)? Thanks,
> - Gabe
>
|||when red-gate fails (script out put has errors), DB Ghost succeeds which is
why most of our customers used to be red-gate customers.
free for MVP's, educational and non-profit organizations.
regards,
Mark Baekdal
http://www.dbghost.com
http://www.innovartis.co.uk
+44 (0)208 241 1762
Build, Comparison and Synchronization from Source Control = Database change
management for SQL Server
"Wayne Snyder" wrote:

> I use red-gate
> --
> Wayne Snyder, MCDBA, SQL Server MVP
> Mariner, Charlotte, NC
> www.mariner-usa.com
> (Please respond only to the newsgroups.)
> I support the Professional Association of SQL Server (PASS) and it's
> community of SQL Server professionals.
> www.sqlpass.org
> "Gabe Matteson" <gmatteson@.inquery.biz.nospam> wrote in message
> news:OdFamzndFHA.1456@.TK2MSFTNGP15.phx.gbl...
>
>

Comparing two databases

Are there any tools that allow you to compare two sql server databases to
find out what is different between them (the database structure, including
tables, relationships etc)? Thanks,
- Gabehttp://www.red-gate.com/sql/summary.htm
AMB
"Gabe Matteson" wrote:
> Are there any tools that allow you to compare two sql server databases to
> find out what is different between them (the database structure, including
> tables, relationships etc)? Thanks,
> - Gabe
>
>|||Gabe Matteson wrote:
> Are there any tools that allow you to compare two sql server
> databases to find out what is different between them (the database
> structure, including tables, relationships etc)? Thanks,
> - Gabe
There are numerous schema comparison tools available. Change Manager
from Imceda/Quest Software available at www.imceda.com.
--
David Gugick
Quest Software
www.imceda.com
www.quest.com|||Seconding this one...I've been using Red-gate SQL and Data compare for 2
years...fantastic products...
--
Kevin Hill
President
3NF Consulting
www.3nf-inc.com/NewsGroups.htm
www.DallasDBAs.com/forum - new DB forum for Dallas/Ft. Worth area DBAs.
www.experts-exchange.com - experts compete for points to answer your
questions
"Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com> wrote in message
news:E8C28859-7C90-4FD6-A40B-3490F7172846@.microsoft.com...
> http://www.red-gate.com/sql/summary.htm
>
> AMB
> "Gabe Matteson" wrote:
>> Are there any tools that allow you to compare two sql server databases to
>> find out what is different between them (the database structure,
>> including
>> tables, relationships etc)? Thanks,
>> - Gabe
>>|||Thanks!
"Gabe Matteson" <gmatteson@.inquery.biz.nospam> wrote in message
news:OdFamzndFHA.1456@.TK2MSFTNGP15.phx.gbl...
> Are there any tools that allow you to compare two sql server databases to
> find out what is different between them (the database structure, including
> tables, relationships etc)? Thanks,
> - Gabe
>|||ErWin and ER-Studio do this as well.
Greg Jackson
PDX, Oregon|||I agree. SQL Compare from Red Gate is brilliant.
"Kevin3NF" wrote:
> Seconding this one...I've been using Red-gate SQL and Data compare for 2
> years...fantastic products...
> --
> Kevin Hill
> President
> 3NF Consulting
> www.3nf-inc.com/NewsGroups.htm
> www.DallasDBAs.com/forum - new DB forum for Dallas/Ft. Worth area DBAs.
> www.experts-exchange.com - experts compete for points to answer your
> questions
>
> "Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com> wrote in message
> news:E8C28859-7C90-4FD6-A40B-3490F7172846@.microsoft.com...
> > http://www.red-gate.com/sql/summary.htm
> >
> >
> > AMB
> >
> > "Gabe Matteson" wrote:
> >
> >> Are there any tools that allow you to compare two sql server databases to
> >> find out what is different between them (the database structure,
> >> including
> >> tables, relationships etc)? Thanks,
> >> - Gabe
> >>
> >>
> >>
>
>|||you may want to look at a complete approach to change management, from your
favourite source control to your target database - DB Ghost
http://www.dbghost.com & the scripts produced always work - it's all in the
way they're produced.
regards,
Mark Baekdal
http://www.dbghost.com
http://www.innovartis.co.uk
+44 (0)208 241 1762
Build, Comparison and Synchronization from Source Control = Database change
management for SQL Server
"Gabe Matteson" wrote:
> Are there any tools that allow you to compare two sql server databases to
> find out what is different between them (the database structure, including
> tables, relationships etc)? Thanks,
> - Gabe
>
>|||I use red-gate
--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Gabe Matteson" <gmatteson@.inquery.biz.nospam> wrote in message
news:OdFamzndFHA.1456@.TK2MSFTNGP15.phx.gbl...
> Are there any tools that allow you to compare two sql server databases to
> find out what is different between them (the database structure, including
> tables, relationships etc)? Thanks,
> - Gabe
>|||when red-gate fails (script out put has errors), DB Ghost succeeds which is
why most of our customers used to be red-gate customers.
free for MVP's, educational and non-profit organizations.
regards,
Mark Baekdal
http://www.dbghost.com
http://www.innovartis.co.uk
+44 (0)208 241 1762
Build, Comparison and Synchronization from Source Control = Database change
management for SQL Server
"Wayne Snyder" wrote:
> I use red-gate
> --
> Wayne Snyder, MCDBA, SQL Server MVP
> Mariner, Charlotte, NC
> www.mariner-usa.com
> (Please respond only to the newsgroups.)
> I support the Professional Association of SQL Server (PASS) and it's
> community of SQL Server professionals.
> www.sqlpass.org
> "Gabe Matteson" <gmatteson@.inquery.biz.nospam> wrote in message
> news:OdFamzndFHA.1456@.TK2MSFTNGP15.phx.gbl...
> > Are there any tools that allow you to compare two sql server databases to
> > find out what is different between them (the database structure, including
> > tables, relationships etc)? Thanks,
> > - Gabe
> >
>
>|||'www.red-gate.com' (http://www.red-gate.com) or 'www.dbghost.com
(http://www.dbghost.com) are two software use to compare the databas
--
gheman
----
ghemant's Profile: http://www.msusenet.com/member.php?userid=234
View this thread: http://www.msusenet.com/t-187055366|||I use http://www.adeptsql.com SQL Diff Tool because it was so much
faster than red-gate.
Tim S|||Ive seen people script DBs and use "Beyond Compare" as well.
Greg Jackson
PDX, Oregon|||I use SQL Effects Clarity from http://www.sqleffects.com mostly because
of the side by side twin views of the schemas that lets you drill down
to the most minute differences.
Gabe Matteson wrote:
> Are there any tools that allow you to compare two sql server databases to
> find out what is different between them (the database structure, including
> tables, relationships etc)? Thanks,
> - Gabe
>

Tuesday, March 27, 2012

Comparing table structures between databases

What is the easiest way to compare the table structure of two databases?
I have inherited a project and have found a couple of undocumented
inconsistencies between the development and production databases.
Is there an in-built function or a utility that can help with this?
Thanks,
MikeUnfortunatly no there isn't an easy way.
If you have connection to the internet log on to the site
http://www.adeptsql.com/download.htm and download AdeptSQL
Diff ver 1.6.
We have used that for all our server and works very well.
N.B. You can program it yourself in SQL but will take a
bit of time, and this will hi-light every difference.
Peter
"What makes him think a middle aged actor [Clint
Eastwood], who's played with a chimp, could have a future
in politics?"
Ronald Reagan
>--Original Message--
>What is the easiest way to compare the table structure of
two databases?
>I have inherited a project and have found a couple of
undocumented
>inconsistencies between the development and production
databases.
>Is there an in-built function or a utility that can help
with this?
>Thanks,
>Mike
>
>.
>|||Thanks, Peter.
That looks like it will do all I need and more.
Regards,
Mike
"Peter The Spate" <anonymous@.discussions.microsoft.com> wrote in message
news:4bbe01c490da$17ef8560$a601280a@.phx.gbl...
> Unfortunatly no there isn't an easy way.
> If you have connection to the internet log on to the site
> http://www.adeptsql.com/download.htm and download AdeptSQL
> Diff ver 1.6.
> We have used that for all our server and works very well.
> N.B. You can program it yourself in SQL but will take a
> bit of time, and this will hi-light every difference.
> Peter
> "What makes him think a middle aged actor [Clint
> Eastwood], who's played with a chimp, could have a future
> in politics?"
> Ronald Reagan
>
> >--Original Message--
> >What is the easiest way to compare the table structure of
> two databases?
> >
> >I have inherited a project and have found a couple of
> undocumented
> >inconsistencies between the development and production
> databases.
> >
> >Is there an in-built function or a utility that can help
> with this?
> >
> >Thanks,
> >
> >Mike
> >
> >
> >.
> >

Comparing table structures between databases

What is the easiest way to compare the table structure of two databases?
I have inherited a project and have found a couple of undocumented
inconsistencies between the development and production databases.
Is there an in-built function or a utility that can help with this?
Thanks,
MikeThanks, Peter.
That looks like it will do all I need and more.
Regards,
Mike
"Peter The Spate" <anonymous@.discussions.microsoft.com> wrote in message
news:4bbe01c490da$17ef8560$a601280a@.phx.gbl...[vbcol=seagreen]
> Unfortunatly no there isn't an easy way.
> If you have connection to the internet log on to the site
> http://www.adeptsql.com/download.htm and download AdeptSQL
> Diff ver 1.6.
> We have used that for all our server and works very well.
> N.B. You can program it yourself in SQL but will take a
> bit of time, and this will hi-light every difference.
> Peter
> "What makes him think a middle aged actor [Clint
> Eastwood], who's played with a chimp, could have a future
> in politics?"
> Ronald Reagan
>
> two databases?
> undocumented
> databases.
> with this?

Comparing table structure

Is there any tool to compare table structures between two databases?
For example: When comparing Table_A and Table_B, which fields are
missing, which relations are missing, etc.
Thanks,
GasparHello,
SQLCompare from Redgate software is a good DB structure and Data compare
software.
http://www.red-gate.com/products/SQL_Compare/index.htm
Thanks
Hari
"Gaspar" <gaspar@.no-reply.com> wrote in message
news:egp9yfLYHHA.3984@.TK2MSFTNGP02.phx.gbl...
> Is there any tool to compare table structures between two databases?
> For example: When comparing Table_A and Table_B, which fields are missing,
> which relations are missing, etc.
> Thanks,
> Gaspar

Comparing table structure

Is there any tool to compare table structures between two databases?
For example: When comparing Table_A and Table_B, which fields are
missing, which relations are missing, etc.
Thanks,
Gaspar
Hello,
SQLCompare from Redgate software is a good DB structure and Data compare
software.
http://www.red-gate.com/products/SQL_Compare/index.htm
Thanks
Hari
"Gaspar" <gaspar@.no-reply.com> wrote in message
news:egp9yfLYHHA.3984@.TK2MSFTNGP02.phx.gbl...
> Is there any tool to compare table structures between two databases?
> For example: When comparing Table_A and Table_B, which fields are missing,
> which relations are missing, etc.
> Thanks,
> Gaspar
sqlsql

Comparing table structure

Is there any tool to compare table structures between two databases?
For example: When comparing Table_A and Table_B, which fields are
missing, which relations are missing, etc.
Thanks,
Gaspar
Hello,
SQLCompare from Redgate software is a good DB structure and Data compare
software.
http://www.red-gate.com/products/SQL_Compare/index.htm
Thanks
Hari
"Gaspar" <gaspar@.no-reply.com> wrote in message
news:egp9yfLYHHA.3984@.TK2MSFTNGP02.phx.gbl...
> Is there any tool to compare table structures between two databases?
> For example: When comparing Table_A and Table_B, which fields are missing,
> which relations are missing, etc.
> Thanks,
> Gaspar

Comparing table structure

Is there any tool to compare table structures between two databases?
For example: When comparing Table_A and Table_B, which fields are
missing, which relations are missing, etc.
Thanks,
GasparHello,
SQLCompare from Redgate software is a good DB structure and Data compare
software.
http://www.red-gate.com/products/SQL_Compare/index.htm
Thanks
Hari
"Gaspar" <gaspar@.no-reply.com> wrote in message
news:egp9yfLYHHA.3984@.TK2MSFTNGP02.phx.gbl...
> Is there any tool to compare table structures between two databases?
> For example: When comparing Table_A and Table_B, which fields are missing,
> which relations are missing, etc.
> Thanks,
> Gaspar

Sunday, March 25, 2012

Comparing order of fields in two copies of sql server database

I have a need to look at 2 copies of the same database structure and
check certain tables to make sure the fields are in the same order.
IE, if someone adds a field to table A in Database 1 in position 5,
and then adds the same field to Table A in Database 2 in position 10,
the two databases have all the same fields, but not in the same order.
Is there a way to check for this and change the order of the fields
in one database so it is the same as the other?
Thanks in advance for your help.
Carol
carol.cooper@.comcast.netthis is just an idea. If the 2 tables are from 2 DBs then you might need to
get the actual object ID of the table in that DB to replace object_id
select name from DB1..syscolumns where id = object_id('table A') order by
colid
join
select name from DB2..syscolumns where id = object_id('table B') order by
colid
"Carol Cooper" <carol.cooper@.comcast.net> wrote in message
news:9b2ed4c6.0307291339.30f3b6b2@.posting.google.com...
> I have a need to look at 2 copies of the same database structure and
> check certain tables to make sure the fields are in the same order.
> IE, if someone adds a field to table A in Database 1 in position 5,
> and then adds the same field to Table A in Database 2 in position 10,
> the two databases have all the same fields, but not in the same order.
> Is there a way to check for this and change the order of the fields
> in one database so it is the same as the other?
> Thanks in advance for your help.
> Carol
> carol.cooper@.comcast.net|||Carol,
You can compare the two tables by querying the information schema views on
each database, assuming they are on the same server. You could use a full
outer join and filter out matches. Here's an example:
SELECT
c1.table_name
, c1.column_name
, c1.ordinal_position
, c2.table_name
, c2.column_name
, c2.ordinal_position
FROM Database1.INFORMATION_SCHEMA.COLUMNS c1
FULL JOIN Database2.INFORMATION_SCHEMA.COLUMNS c2
ON c1.TABLE_NAME = c2.TABLE_NAME
AND c1.COLUMN_NAME = c2.COLUMN_NAME
AND c1.ORDINAL_POSITION = c2.ORDINAL_POSITION
WHERE
(
c1.TABLE_NAME IS NULL
OR
c2.TABLE_NAME IS NULL
OR
c1.COLUMN_NAME IS NULL
OR
c2.COLUMN_NAME IS NULL
OR
c1.ORDINAL_POSITION IS NULL
OR
c2.ORDINAL_POSITION IS NULL
)
When you find a difference, you'll need to fix the table using ALTER TABLE
commands. If you decide to use the scripts from Enterprise Manager's Design
Table dialog, make sure you read them carefully first. No matter what you
do, back up youir data first and figure out a rollback plan just in case.
Ron
--
Ron Talmage
SQL Server MVP
"Carol Cooper" <carol.cooper@.comcast.net> wrote in message
news:9b2ed4c6.0307291339.30f3b6b2@.posting.google.com...
> I have a need to look at 2 copies of the same database structure and
> check certain tables to make sure the fields are in the same order.
> IE, if someone adds a field to table A in Database 1 in position 5,
> and then adds the same field to Table A in Database 2 in position 10,
> the two databases have all the same fields, but not in the same order.
> Is there a way to check for this and change the order of the fields
> in one database so it is the same as the other?
> Thanks in advance for your help.
> Carol
> carol.cooper@.comcast.net

Comparing differences in database structure between databases

I am trying to find a way to easily compare the difference in table/column structure between two SQL server databases.

I am doing this since I need to document the foreign key relationships between a database schema that is currently under development. The foreign keys are not defined as constraints in the database, but are controlled through the application.

The current naming conventions make it easy to see what the relationships are (primary keys are "tablename_seq" and foreign keys use the same names, only tables that have foreign keys that reference themselves break this rule, with a suffix added to the primary key name like "tablename_seq_parent").

In order to document what these relationships are, I have created a copy of the database and set up the foreign key restraints so that I can use the database digram tools in SQL Server Management Studio, or Visio. It took quite a bit of manual work to create all these relationships.

Now the developers have added new tables, or made changes to tables and I need to keep the document up to date. Manually keeping track of all the changes will probably be an issue so I am looking for either:

a way of automatically generating an update script for my database when comparing to the development database, so that I can update to the latest version (then manually create the new constraints OR a way of automatically reading in information on the tables from a database and creating foreign key relationships for any primary key that is a column of another table (ie. has the same name)

The closest thing I have found that might help solve the first option is the tablediff utility. I thought perhaps I could write a script (it has been a while!!) that:

    Lists all tables in the developer database For each table check if it exists in my database If it does exist then use tablediff to check for new or changed columns and generate a script to change the table using -f. If it doesn't exist then create table using script If tables exist in the destination database but not in the main one then flag them for followup manually.

Does anyone know of a simpler way that I have missed?

Regards

Jo

Hi all

Does anyone have any ideas on this? Or have I posted to the wrong forum?

Regards

Jo

|||

Hi,

Easiest thing to do is to get a third-party tool for this. I personally use the SQL Tools from Red-Gate.

For what you want , its SQL Compare. Its 295 USD, and a total bargain. There are others, from ApexSQL, and DB Ghost...

However, I use all Red-Gate tools regularly and wouldn't be without them and for me, I plumped for the SQL Bundle Pro (990 USD).

Cheers.

Paul

|||

I use a product called AdeptSQL Diff, it's pretty quick to scan my databases (6500 procs and 1100 tables in about a minute) and easy to use. www.adeptsql.com

The comparison tool is 240 USD and if you want to compare your data as well, it's 320 USD.

Jarret

|||If nothing else, version your DB objects as scripts within VSS, and do a compare between script versions.

Thursday, March 22, 2012

Comparing data structure

Hi,
The task: we have to two databases. Both evolved from one root in ancient
times. Right now they differ quite a lot. We want to take them both back to
one. To prepare it we have to make some kind of report (no matter what kind

standalone program, excel sheet, Visio diagram) to aid “uniformization”.
One
DB is Oracle, other SQL Server. Both have hundreds of tables with tenths of
fields. Any ideas?
PS. Is it the right Group for this question? ;)
Regards,
MaKcheck out this link..
http://www.dbbalance.com/download.htm
I haven't tested this tool by myself. Is this what u wanted?
hope this helps
--
"MaK" wrote:

> Hi,
> The task: we have to two databases. Both evolved from one root in ancient
> times. Right now they differ quite a lot. We want to take them both back t
o
> one. To prepare it we have to make some kind of report (no matter what kin
d –
> standalone program, excel sheet, Visio diagram) to aid “uniformization
. One
> DB is Oracle, other SQL Server. Both have hundreds of tables with tenths o
f
> fields. Any ideas?
> PS. Is it the right Group for this question? ;)
> Regards,
> MaK

Sunday, March 11, 2012

Compare fields-two flat files-load data

Hi All,

I am totally new to SSIS and im in the learing phase. I have a requirement as below,

I have two flat files (mainframe files), the structure i have given below,

File1:

070113

12345johnk

23456james

1st row is header record which has got date in YYMMDD format and remaining rows have emp no and emp name

File2:

070113

070113

070113

070113

contains 4 records which are dates.

The requirement is to compare the header date in file1 with the 4 dates in file2, if they are equal then it should load all the records in file1 except the header into a table and if they donot match then it should log an err msg. Please could someone provide a lead on this.

The files have same record length and fixed field delimited.

Thanks in advance

raj

Dear SSISQuest,

1. Add 2 flatFile Source

2. Add 2 Sort transform for each FlatFile Source

3. Add Inner Join Transform and do a LEFT JOIN

4. Add SQL Destination or other!

Helped?

regards!

Thursday, March 8, 2012

Compare data in two tables

Is there an easy way (using SQL) to compare two tables
with the same structure? Basically if one piece of data
is different than the other (based on the primary key),
print the row.See http://www.red-gate.com/. Their SQL Data Compare is an excellent tool.
If you are a business, it's decently priced. For an individual, it may be a
little pricy ($195+).
Another way is to write a query that joins the two tables by the primary key
(use FULL OUTER JOIN) and then has a REALLY big WHERE clause that compares
each of the fields.
For example,
create table data (and data2)
(
pk int not null constraint primary key,
str varchar(50),
num int
)
select
data.pk as data_pk,
data.str as data_str,
data.num as data_num,
data2.pk as data2_pk,
data2.str as data2_str,
data2.num as data2_num,
from
-- full outer join will get records on either side even when join
condition fails
data full outer join data2 on data.pk = data2.pk
where
-- if either PK is null, the records are different (i.e. the join failed
thus no matching record)
data.pk is null
or
data2.pk is null
or
-- check each field...can be tedious;
-- the ISNULL stuff is a cheesy way to deal with possible NULLs in fields
and still have them compare
-- a better way for comparing NULLs is:
-- ((fielda is null and fieldb is not null) or (fielda is not null and
fieldb is null) or (fielda <> fieldb))
isnull(data.str, '###BOGUS###') <> isnull(data2.str, '###BOGUS###')
or
isnull(data.num, -999999999) <> isnull(data.num, -999999999)
This can be very tedious is you are comparing many tables. If you wanted
something more dynamic, you could create a stored procedure that dynamically
created the above SQL for any two tables using the metadata in SYSOBJECTS
and SYSCOLUMNS.
"Amy" <anonymous@.discussions.microsoft.com> wrote in message
news:16d101c536c5$69fb47e0$a601280a@.phx.gbl...
> Is there an easy way (using SQL) to compare two tables
> with the same structure? Basically if one piece of data
> is different than the other (based on the primary key),
> print the row.|||a UNION of the tables would tell of you if the two tables are the same.
Also, you could use NOT EXISTS clause to print those records that do not
match or you could use
LEFT JOIN and select only those columns that have a NULL value.
Gopi
"Mike Jansen" <mjansen_nntp@.mail.com> wrote in message
news:Ob8xdlsNFHA.204@.TK2MSFTNGP15.phx.gbl...
> See http://www.red-gate.com/. Their SQL Data Compare is an excellent
> tool.
> If you are a business, it's decently priced. For an individual, it may be
> a
> little pricy ($195+).
> Another way is to write a query that joins the two tables by the primary
> key
> (use FULL OUTER JOIN) and then has a REALLY big WHERE clause that compares
> each of the fields.
> For example,
> create table data (and data2)
> (
> pk int not null constraint primary key,
> str varchar(50),
> num int
> )
> select
> data.pk as data_pk,
> data.str as data_str,
> data.num as data_num,
> data2.pk as data2_pk,
> data2.str as data2_str,
> data2.num as data2_num,
> from
> -- full outer join will get records on either side even when join
> condition fails
> data full outer join data2 on data.pk = data2.pk
> where
> -- if either PK is null, the records are different (i.e. the join failed
> thus no matching record)
> data.pk is null
> or
> data2.pk is null
> or
> -- check each field...can be tedious;
> -- the ISNULL stuff is a cheesy way to deal with possible NULLs in fields
> and still have them compare
> -- a better way for comparing NULLs is:
> -- ((fielda is null and fieldb is not null) or (fielda is not null and
> fieldb is null) or (fielda <> fieldb))
> isnull(data.str, '###BOGUS###') <> isnull(data2.str, '###BOGUS###')
> or
> isnull(data.num, -999999999) <> isnull(data.num, -999999999)
> This can be very tedious is you are comparing many tables. If you wanted
> something more dynamic, you could create a stored procedure that
> dynamically
> created the above SQL for any two tables using the metadata in SYSOBJECTS
> and SYSCOLUMNS.
> "Amy" <anonymous@.discussions.microsoft.com> wrote in message
> news:16d101c536c5$69fb47e0$a601280a@.phx.gbl...
>|||On Fri, 1 Apr 2005 09:48:36 -0500, Mike Jansen wrote:
(snip)
> -- the ISNULL stuff is a cheesy way to deal with possible NULLs in fields
>and still have them compare
> -- a better way for comparing NULLs is:
> -- ((fielda is null and fieldb is not null) or (fielda is not null and
>fieldb is null) or (fielda <> fieldb))
> isnull(data.str, '###BOGUS###') <> isnull(data2.str, '###BOGUS###')
> or
> isnull(data.num, -999999999) <> isnull(data.num, -999999999)
Hi Mike,
Here's another way to compare two columns that might contain NULLS - one
that can be used if there is no reliable bogus value:
WHERE NULLIF(column1, column2) IS NULL
AND NULLIF(column2, column1) IS NULL
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||I just tested that now and it seems like NULLIF blows chunks if the first
parameter is NULL, making it not usable if the data can contain NULLs.
"Hugo Kornelis" <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message
news:fbbr41lqgaurdc00m07gvn5ufi6kr6qvmk@.
4ax.com...
> On Fri, 1 Apr 2005 09:48:36 -0500, Mike Jansen wrote:
> (snip)
fields
and
> Hi Mike,
> Here's another way to compare two columns that might contain NULLS - one
> that can be used if there is no reliable bogus value:
> WHERE NULLIF(column1, column2) IS NULL
> AND NULLIF(column2, column1) IS NULL
> Best, Hugo
> --
> (Remove _NO_ and _SPAM_ to get my e-mail address)|||On Fri, 1 Apr 2005 15:45:33 -0500, Mike Jansen wrote:

>I just tested that now and it seems like NULLIF blows chunks if the first
>parameter is NULL, making it not usable if the data can contain NULLs.
Hi Mike,
That's why you have to use both lines:
The first NULLIF expression will return NULL if column1 and column2 are
not NULL and equal, or when column1 is NULL.
The first NULLIF expression will return NULL if column1 and column2 are
not NULL and equal, or when column2 is NULL.
If both NULLIF expressions return NULL, then either column1 and column2
are not NULL and equal, or column1 and column2 are both NULL.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||No, I mean it BLOWS CHUNKS. It errors out. You can't use it. Try this in
SQL Query Analyzer
SELECT NULLIF(null, 1)
"Hugo Kornelis" <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message
news:rpdr41tnjn71e03kvqatc5o96lo85aetft@.
4ax.com...
> On Fri, 1 Apr 2005 15:45:33 -0500, Mike Jansen wrote:
>
> Hi Mike,
> That's why you have to use both lines:
>
> The first NULLIF expression will return NULL if column1 and column2 are
> not NULL and equal, or when column1 is NULL.
> The first NULLIF expression will return NULL if column1 and column2 are
> not NULL and equal, or when column2 is NULL.
> If both NULLIF expressions return NULL, then either column1 and column2
> are not NULL and equal, or column1 and column2 are both NULL.
> Best, Hugo
> --
> (Remove _NO_ and _SPAM_ to get my e-mail address)|||On Fri, 1 Apr 2005 16:13:13 -0500, Mike Jansen wrote:

>No, I mean it BLOWS CHUNKS. It errors out. You can't use it. Try this in
>SQL Query Analyzer
>SELECT NULLIF(null, 1)
Hi Mike,
I''ve never tried that until now - you're right, you can't use the
literal NULL in a NULLIF expression.
However, this works:
declare @.a int, @.b int
set @.a = null
set @.b = 1
SELECT NULLIF(@.a, @.b)
And this works as well
select
data.pk as data_pk,
data.str as data_str,
data.num as data_num,
data2.pk as data2_pk,
data2.str as data2_str,
data2.num as data2_num,
from
-- full outer join will get records on either side even when join
condition fails
data full outer join data2 on data.pk = data2.pk
where
-- if either PK is null, the records are different (i.e. the join
failed thus no matching record)
data.pk is null
or
data2.pk is null
or
-- check each field...can be tedious;
(NULLIF (data.str, data2.str) IS NULL
AND NULLIF (data2.str, data.str) IS NULL))
or
(NULLIF (data.num, data2.num) IS NULL
AND NULLIF (data2.num, data.num) IS NULL))
(Which brings us back on topic)
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Guess I didn't do thorough enough testing :) Since in this case a literal
NULL would never be the issue, it would work.
Thanks for info.
"Hugo Kornelis" <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message
news:55fr415hebp87nk87qg96bfv2dcmvlqugd@.
4ax.com...
> On Fri, 1 Apr 2005 16:13:13 -0500, Mike Jansen wrote:
>
in
> Hi Mike,
> I''ve never tried that until now - you're right, you can't use the
> literal NULL in a NULLIF expression.
> However, this works:
> declare @.a int, @.b int
> set @.a = null
> set @.b = 1
> SELECT NULLIF(@.a, @.b)
> And this works as well
> select
> data.pk as data_pk,
> data.str as data_str,
> data.num as data_num,
> data2.pk as data2_pk,
> data2.str as data2_str,
> data2.num as data2_num,
> from
> -- full outer join will get records on either side even when join
> condition fails
> data full outer join data2 on data.pk = data2.pk
> where
> -- if either PK is null, the records are different (i.e. the join
> failed thus no matching record)
> data.pk is null
> or
> data2.pk is null
> or
> -- check each field...can be tedious;
> (NULLIF (data.str, data2.str) IS NULL
> AND NULLIF (data2.str, data.str) IS NULL))
> or
> (NULLIF (data.num, data2.num) IS NULL
> AND NULLIF (data2.num, data.num) IS NULL))
> (Which brings us back on topic)
> Best, Hugo
> --
> (Remove _NO_ and _SPAM_ to get my e-mail address)|||This works:
SELECT NULLIF(1, null)
"Hugo Kornelis" <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message
news:55fr415hebp87nk87qg96bfv2dcmvlqugd@.
4ax.com...
> On Fri, 1 Apr 2005 16:13:13 -0500, Mike Jansen wrote:
>
> Hi Mike,
> I''ve never tried that until now - you're right, you can't use the
> literal NULL in a NULLIF expression.
> However, this works:
> declare @.a int, @.b int
> set @.a = null
> set @.b = 1
> SELECT NULLIF(@.a, @.b)
> And this works as well
> select
> data.pk as data_pk,
> data.str as data_str,
> data.num as data_num,
> data2.pk as data2_pk,
> data2.str as data2_str,
> data2.num as data2_num,
> from
> -- full outer join will get records on either side even when join
> condition fails
> data full outer join data2 on data.pk = data2.pk
> where
> -- if either PK is null, the records are different (i.e. the join
> failed thus no matching record)
> data.pk is null
> or
> data2.pk is null
> or
> -- check each field...can be tedious;
> (NULLIF (data.str, data2.str) IS NULL
> AND NULLIF (data2.str, data.str) IS NULL))
> or
> (NULLIF (data.num, data2.num) IS NULL
> AND NULLIF (data2.num, data.num) IS NULL))
> (Which brings us back on topic)
> Best, Hugo
> --
> (Remove _NO_ and _SPAM_ to get my e-mail address)

Compare data between 2 tables

I have 2 tables in SQL server. They have the same data structure. Table A
has more records than Table B. I would like to know how I should write a
sql statement to find out the missing records from Table B compare to Table
A. Thanks!
ChrisChris,
> I have 2 tables in SQL server. They have the same data
> structure. Table A has more records than Table B. I would like
> to know how I should write a sql statement to find out the
> missing records from Table B compare to Table A. Thanks!
select * fom TableA
where not exists (select * from TableB
where TableA.keycol = TableB.keycol)
Linda|||Assume the two tables under considerations are
Table 1 => A (col1,col2,col3
Table 2 => B (col1,col2,col3
A has more records than
select * from TABLE
WHERE col1 not exists (select col1 from table B|||you could use an Application and then you can do it
quickly any time for any table you want. Check out
www.dbghost.com
>--Original Message--
>I have 2 tables in SQL server. They have the same data
structure. Table A
>has more records than Table B. I would like to know how
I should write a
>sql statement to find out the missing records from Table
B compare to Table
>A. Thanks!
>Chris
>
>.
>