Unix Technical Forum

how to identify whether duplicate identity column values existing on a table or not

This is a discussion on how to identify whether duplicate identity column values existing on a table or not within the DB2 forums, part of the Database Server Software category; --> how to identify whether duplicate identity column values existing on a table or not. i have four tables and ...


Go Back   Unix Technical Forum > Database Server Software > DB2

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 02:07 PM
srikirthi@gmail.com
 
Posts: n/a
Default how to identify whether duplicate identity column values existing on a table or not

how to identify whether duplicate identity column values existing on a
table or not.

i have four tables and all the table have row_sk defined a identity
column, the start and end values are different acroos all the tables.

i am creating a union all view on all the tables

i am getting this error SQL0415N

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 02:07 PM
jefftyzzer
 
Posts: n/a
Default Re: how to identify whether duplicate identity column values existing on a table or not

On Oct 11, 1:44 pm, srikir...@gmail.com wrote:
> how to identify whether duplicate identity column values existing on a
> table or not.
>
> i have four tables and all the table have row_sk defined a identity
> column, the start and end values are different acroos all the tables.
>
> i am creating a union all view on all the tables
>
> i am getting this error SQL0415N


Not sure which issue you're actually struggling with, SQL0415N or
trying to find duplicates....

Anyway, in a UNION, all result sets must be union-compatible (same
number of attributes and same datatypes). Ensure that you're not
trying, e.g., to stack an integer column on top of a character one. As
to finding duplicate values, there are several well-known techniques,
so if you are, in fact, struggling with that, I can forward some
queries to you that will do the trick.

--Jeff

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 02:07 PM
Serge Rielau
 
Posts: n/a
Default Re: how to identify whether duplicate identity column values existingon a table or not

srikirthi@gmail.com wrote:
> how to identify whether duplicate identity column values existing on a
> table or not.
>
> i have four tables and all the table have row_sk defined a identity
> column, the start and end values are different acroos all the tables.
>
> i am creating a union all view on all the tables
>
> i am getting this error SQL0415N
>

This should spit out all the dups and where they live (untested)
SELECT tabname, id FROM
(SELECT COUNT(1) OVER(PARTITION BY id) AS numids, id
FROM (SELECT id, 'T1' FROM T1 UNION ALL SELECT id, T2 FROM T2 ....)
AS X(id, tabname)) AS Y
WHERE numids > 1

Cheers
Serge


--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-27-2008, 02:07 PM
Ian
 
Posts: n/a
Default Re: how to identify whether duplicate identity column values existingon a table or not

Serge Rielau wrote:

> This should spit out all the dups and where they live (untested)
> SELECT tabname, id FROM
> (SELECT COUNT(1) OVER(PARTITION BY id) AS numids, id
> FROM (SELECT id, 'T1' FROM T1 UNION ALL SELECT id, T2 FROM T2 ....) AS
> X(id, tabname)) AS Y
> WHERE numids > 1
>


Will this be more efficient than the more traditional:

select id, count(*)
from (SELECT id, 'T1' FROM T1
UNION ALL
SELECT id, 'T2' FROM T2 ....) AS X(id, tabname)
group by id
having count(*) > 1


Thanks,



Ian

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-27-2008, 02:07 PM
Serge Rielau
 
Posts: n/a
Default Re: how to identify whether duplicate identity column values existingon a table or not

Ian wrote:
> Serge Rielau wrote:
>
>> This should spit out all the dups and where they live (untested)
>> SELECT tabname, id FROM
>> (SELECT COUNT(1) OVER(PARTITION BY id) AS numids, id
>> FROM (SELECT id, 'T1' FROM T1 UNION ALL SELECT id, T2 FROM T2 ....)
>> AS X(id, tabname)) AS Y
>> WHERE numids > 1
>>

>
> Will this be more efficient than the more traditional:
>
> select id, count(*)
> from (SELECT id, 'T1' FROM T1
> UNION ALL
> SELECT id, 'T2' FROM T2 ....) AS X(id, tabname)
> group by id
> having count(*) > 1

The "more traditional" won't give you the tables where the dups are... :-)

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
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 10:03 AM.


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