473,666 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_MODIFI ER is either 'identityoverri de' or '' and
ROWCHANGETIMEST AMP_MODIFIER is either 'rowchangetimes tampoverride' or ''?

select
case
when exists (
select *
from syscat.columns
where tabschema = 'FRANK'
and tabname = 'INVOICE'
and identity = 'Y'
) then 'identityoverri de'
else ''
end as identity_modifi er
, case
when exists (
select *
from syscat.columns
where tabschema = 'FRANK'
and tabname = 'INVOICE'
and rowchangetimest amp = 'Y'
) then 'rowchangetimes tampoverride'
else ''
end as rowchangetimest amp_modifier
from sysibm.sysdummy 1;

Results:

IDENTITY_MODIFI ER ROWCHANGETIMEST AMP_MODIFIER
----------------- ---------------------------
identityoverrid e rowchangetimest ampoverride

1 record(s) selected.
Jun 27 '08 #1
3 2989
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_MODIFI ER is either 'identityoverri de' or '' and
ROWCHANGETIMEST AMP_MODIFIER is either 'rowchangetimes tampoverride' or ''?

select
case
when exists (
select *
from syscat.columns
where tabschema = 'FRANK'
and tabname = 'INVOICE'
and identity = 'Y'
) then 'identityoverri de'
else ''
end as identity_modifi er
, case
when exists (
select *
from syscat.columns
where tabschema = 'FRANK'
and tabname = 'INVOICE'
and rowchangetimest amp = 'Y'
) then 'rowchangetimes tampoverride'
else ''
end as rowchangetimest amp_modifier
from sysibm.sysdummy 1;

Results:

IDENTITY_MODIFI ER ROWCHANGETIMEST AMP_MODIFIER
----------------- ---------------------------
identityoverrid e rowchangetimest ampoverride

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.individua l.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_MODIF IER is either 'identityoverri de' or '' and
ROWCHANGETIMES TAMP_MODIFIER is either 'rowchangetimes tampoverride' or
''?
>>
select
case
when exists (
select *
from syscat.columns
where tabschema = 'FRANK'
and tabname = 'INVOICE'
and identity = 'Y'
) then 'identityoverri de'
else ''
end as identity_modifi er
, case
when exists (
select *
from syscat.columns
where tabschema = 'FRANK'
and tabname = 'INVOICE'
and rowchangetimest amp = 'Y'
) then 'rowchangetimes tampoverride'
else ''
end as rowchangetimest amp_modifier
from sysibm.sysdummy 1;

Results:

IDENTITY_MODIF IER ROWCHANGETIMEST AMP_MODIFIER
----------------- ---------------------------
identityoverri de rowchangetimest ampoverride

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 'identityoverri de' else '' end) as
identity_modifi er
, max(case when rowchangetimest amp = 'Y' then
'rowchangetimes tampoverride' else '' end) as rowchangetimest amp_modifier
from syscat.columns
group by tabschema, tabname
;

select identity_modifi er
, rowchangetimest amp_modifier
from load_modifiers
where tabschema = 'CUSTOMER'
and tabname = 'ACCOUNTS'
;

IDENTITY_MODIFI ER ROWCHANGETIMEST AMP_MODIFIER
----------------- ---------------------------
identityoverrid e rowchangetimest ampoverride

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.individua l.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_MODI FIER is either 'identityoverri de' or '' and
ROWCHANGETIME STAMP_MODIFIER is either 'rowchangetimes tampoverride' or
''?
>>select
case
when exists (
select *
from syscat.columns
where tabschema = 'FRANK'
and tabname = 'INVOICE'
and identity = 'Y'
) then 'identityoverri de'
else ''
end as identity_modifi er
, case
when exists (
select *
from syscat.columns
where tabschema = 'FRANK'
and tabname = 'INVOICE'
and rowchangetimest amp = 'Y'
) then 'rowchangetimes tampoverride'
else ''
end as rowchangetimest amp_modifier
from sysibm.sysdummy 1;

Results:

IDENTITY_MODI FIER ROWCHANGETIMEST AMP_MODIFIER
----------------- ---------------------------
identityoverr ide rowchangetimest ampoverride

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
3284
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, and stops the sql server from working. Whilst it's attempting the update, no one can access the database, the sqlservr.exe memory usage shoots up and enterprise manager reports a not responding status. Eventually after about 10 minutes, it...
7
1920
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
15819
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
9232
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 is entered, either from a form or from the table view of the table, when the record gets saved it immediately displays #DELETED# in all of the fields. However, if I close the form or table view and reopen the record has in fact been inserted. The...
22
6409
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 database. The original Update and Delete SP's all use a timestamp for concurreny checking. I am trying to use the same Update SP from my sqlDataSource but I keep getting the following error:
17
2692
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 can retrieve the autonum value for the new record. This doesn't occur with SQL Server, which of course causes an error (or at least in this code it does since there's an unhandled NULL value). Is there any way to retrieve this value when I add a...
6
3849
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 "Generations"), and it allows the user to add, edit and delete the various records of the table. "Generations" table has the following fields: "IDPerson", NamePerson", "AgePerson" and "IDParent". A record contains the information about a person (his name, his...
7
6979
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 into the GUI because it is hard to describe in text. First of all what is the purpose of ALTOBJ()? This procedure was created mostly for ISVs who need to do produce change scripts to upgrade application from release to release, but it can also
9
17014
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: NoJunkMailshah@xnet.com \ / --------------------- X against HTML mail TO REPLY, REMOVE NoJunkMail / \ and postings
0
8448
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8552
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8640
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7387
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2773
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.