473,395 Members | 2,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

SQL to find if table has identity and/or row change timestamp columns

How can I fix this so that it doesn't do essentially the same scan
twice, but it gives the same results (a single row where
IDENTITY_MODIFIER is either 'identityoverride' or '' and
ROWCHANGETIMESTAMP_MODIFIER is either 'rowchangetimestampoverride' or ''?

select
case
when exists (
select *
from syscat.columns
where tabschema = 'FRANK'
and tabname = 'INVOICE'
and identity = 'Y'
) then 'identityoverride'
else ''
end as identity_modifier
, case
when exists (
select *
from syscat.columns
where tabschema = 'FRANK'
and tabname = 'INVOICE'
and rowchangetimestamp = 'Y'
) then 'rowchangetimestampoverride'
else ''
end as rowchangetimestamp_modifier
from sysibm.sysdummy1;

Results:

IDENTITY_MODIFIER ROWCHANGETIMESTAMP_MODIFIER
----------------- ---------------------------
identityoverride rowchangetimestampoverride

1 record(s) selected.
Jun 27 '08 #1
3 2975
Frank Swarbrick wrote:
How can I fix this so that it doesn't do essentially the same scan
twice, but it gives the same results (a single row where
IDENTITY_MODIFIER is either 'identityoverride' or '' and
ROWCHANGETIMESTAMP_MODIFIER is either 'rowchangetimestampoverride' or ''?

select
case
when exists (
select *
from syscat.columns
where tabschema = 'FRANK'
and tabname = 'INVOICE'
and identity = 'Y'
) then 'identityoverride'
else ''
end as identity_modifier
, case
when exists (
select *
from syscat.columns
where tabschema = 'FRANK'
and tabname = 'INVOICE'
and rowchangetimestamp = 'Y'
) then 'rowchangetimestampoverride'
else ''
end as rowchangetimestamp_modifier
from sysibm.sysdummy1;

Results:

IDENTITY_MODIFIER ROWCHANGETIMESTAMP_MODIFIER
----------------- ---------------------------
identityoverride rowchangetimestampoverride

1 record(s) selected.
You need to select straight from syscat.columns and then use GROUP BY to
pivot the two rows into columns.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Jun 27 '08 #2
>>On 6/22/2008 at 6:58 PM, in message
<6c*************@mid.individual.net>,
Serge Rielau<sr*****@ca.ibm.comwrote:
Frank Swarbrick wrote:
>How can I fix this so that it doesn't do essentially the same scan
twice, but it gives the same results (a single row where
IDENTITY_MODIFIER is either 'identityoverride' or '' and
ROWCHANGETIMESTAMP_MODIFIER is either 'rowchangetimestampoverride' or
''?
>>
select
case
when exists (
select *
from syscat.columns
where tabschema = 'FRANK'
and tabname = 'INVOICE'
and identity = 'Y'
) then 'identityoverride'
else ''
end as identity_modifier
, case
when exists (
select *
from syscat.columns
where tabschema = 'FRANK'
and tabname = 'INVOICE'
and rowchangetimestamp = 'Y'
) then 'rowchangetimestampoverride'
else ''
end as rowchangetimestamp_modifier
from sysibm.sysdummy1;

Results:

IDENTITY_MODIFIER ROWCHANGETIMESTAMP_MODIFIER
----------------- ---------------------------
identityoverride rowchangetimestampoverride

1 record(s) selected.
You need to select straight from syscat.columns and then use GROUP BY to

pivot the two rows into columns.
Thanks, Serge! You made me work a bit <g>, but here's what I now have
(placed into a VIEW):

create view load_modifiers
as
select tabschema
, tabname
, max(case when identity = 'Y' then 'identityoverride' else '' end) as
identity_modifier
, max(case when rowchangetimestamp = 'Y' then
'rowchangetimestampoverride' else '' end) as rowchangetimestamp_modifier
from syscat.columns
group by tabschema, tabname
;

select identity_modifier
, rowchangetimestamp_modifier
from load_modifiers
where tabschema = 'CUSTOMER'
and tabname = 'ACCOUNTS'
;

IDENTITY_MODIFIER ROWCHANGETIMESTAMP_MODIFIER
----------------- ---------------------------
identityoverride rowchangetimestampoverride

1 record(s) selected.

Also gets good results when table does not include one or the other (or
both) types of columns.

Good stuff!

Frank

Jun 27 '08 #3
Frank Swarbrick wrote:
>>>On 6/22/2008 at 6:58 PM, in message
<6c*************@mid.individual.net>,
Serge Rielau<sr*****@ca.ibm.comwrote:
>Frank Swarbrick wrote:
>>How can I fix this so that it doesn't do essentially the same scan
twice, but it gives the same results (a single row where
IDENTITY_MODIFIER is either 'identityoverride' or '' and
ROWCHANGETIMESTAMP_MODIFIER is either 'rowchangetimestampoverride' or
''?
>>select
case
when exists (
select *
from syscat.columns
where tabschema = 'FRANK'
and tabname = 'INVOICE'
and identity = 'Y'
) then 'identityoverride'
else ''
end as identity_modifier
, case
when exists (
select *
from syscat.columns
where tabschema = 'FRANK'
and tabname = 'INVOICE'
and rowchangetimestamp = 'Y'
) then 'rowchangetimestampoverride'
else ''
end as rowchangetimestamp_modifier
from sysibm.sysdummy1;

Results:

IDENTITY_MODIFIER ROWCHANGETIMESTAMP_MODIFIER
----------------- ---------------------------
identityoverride rowchangetimestampoverride

1 record(s) selected.
You need to select straight from syscat.columns and then use GROUP BY to

pivot the two rows into columns.

Thanks, Serge! You made me work a bit <g>, but here's what I now have
(placed into a VIEW):
You got it right.

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dan Williams | last post by:
I'm trying to do a simple alteration to the table design of one of our SQL 2k tables, simply changing an identity row so that its not 'not for replication', and its taking absolutely ages to do so,...
7
by: laurenq uantrell | last post by:
Is there any reason to have a row that is the PK/Identity and a row that is datatype Timestamp in the same table? Does this in any way help speeding up row updates? Thanks, lq
4
by: maricel | last post by:
I have the following base table structure - DDL: CREATE TABLE "ADMINISTRATOR"."T1" ( "C1" INTEGER NOT NULL ) IN "TEST_TS" ; ALTER TABLE "ADMINISTRATOR"."T1" ADD PRIMARY KEY
8
by: Bri | last post by:
Greetings, I'm having a very strange problem in an AC97 MDB with ODBC Linked tables to SQL Server 7. The table has an Identity field and a Timestamp field. The problem is that when a new record...
22
by: Mal Ball | last post by:
I hope I have the right forum for this question. I have an existing Windows application which uses a SQL Server database and stored procedures. I am now developing a web application to use the same...
17
by: Rico | last post by:
Hello, I am in the midst of converting an Access back end to SQL Server Express. The front end program (converted to Access 2003) uses DAO throughout. In Access, when I use recordset.AddNew I...
6
by: polocar | last post by:
Hi, I'm writing a program in Visual C# 2005 Professional Edition. This program connects to a SQL Server 2005 database called "Generations" (in which there is only one table, called...
7
by: Serge Rielau | last post by:
Hi all, Following Ian's passionate postings on problems with ALTOBJ and the alter table wizard in the control center I'll try to explain how to use ALTOBJ with this thread. I'm not going to get...
9
by: Hemant Shah | last post by:
How do I find out when the table was modified? When I look at syscat.tables it only lists creation time. -- Hemant Shah /"\ ASCII ribbon campaign E-mail:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.