473,657 Members | 2,395 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to remove constraint

I have two tables as shown below (only relevant columns shown). The
second table is dependent on the first one.

CREATE TABLE PARENTTABLE (
...
SERIAL CHAR(12) NOT NULL,
ENDDATE TIMESTAMP NOT NULL,
PKLINK INTEGER GENERATED ALWAYS AS IDENTITY (START WITH -2147483648,
INCREMENT BY 1),
PRIMARY KEY (PKLINK),
CONSTRAINT CONSTRAINT1 UNIQUE (ENDDATE,SERIAL )
) DATA CAPTURE NONE IN USERSPACE1;

CREATE TABLE CHILDTABLE (
...
PKLINK INTEGER NOT NULL,
PACKET SMALLINT NOT NULL,
PRIMARY KEY (PKLINK,PACKET) ,
FOREIGN KEY(PKLINK) REFERENCES PARENTTABLE(PKL INK) ON DELETE CASCADE
) DATA CAPTURE NONE IN USERSPACE1;
My problem is that when I do a "SELECT * FROM PARENTTABLE WHERE
ENDDATE BETWEEN ...", the query is very slow. It seems that the
constraint on this table is not work. I would like to remove the
constraint and create a unique index instead. Questions:

(1) How do I remove the constraint in the first table? I can't do an
explicit DROP on the constraint.

(2) If I need to recreate the table, I would have to export out the
data first and later import back the data into the new table (without
the contraint). Will the identity column (PKLINK) prevent me from
importing the data? I still want the old values of the identity column
because the second table depends on it. What can I do to successful
import the data?

Thanks in advance.

Yong Sing
Nov 12 '05 #1
2 10124
"yongsing" <oh********@yah oo.com.sg> wrote in message
news:59******** *************** ***@posting.goo gle.com...
I have two tables as shown below (only relevant columns shown). The
second table is dependent on the first one.

CREATE TABLE PARENTTABLE (
...
SERIAL CHAR(12) NOT NULL,
ENDDATE TIMESTAMP NOT NULL,
PKLINK INTEGER GENERATED ALWAYS AS IDENTITY (START WITH -2147483648,
INCREMENT BY 1),
PRIMARY KEY (PKLINK),
CONSTRAINT CONSTRAINT1 UNIQUE (ENDDATE,SERIAL )
) DATA CAPTURE NONE IN USERSPACE1;

CREATE TABLE CHILDTABLE (
...
PKLINK INTEGER NOT NULL,
PACKET SMALLINT NOT NULL,
PRIMARY KEY (PKLINK,PACKET) ,
FOREIGN KEY(PKLINK) REFERENCES PARENTTABLE(PKL INK) ON DELETE CASCADE
) DATA CAPTURE NONE IN USERSPACE1;
My problem is that when I do a "SELECT * FROM PARENTTABLE WHERE
ENDDATE BETWEEN ...", the query is very slow. It seems that the
constraint on this table is not work. I would like to remove the
constraint and create a unique index instead. Questions:

(1) How do I remove the constraint in the first table? I can't do an
explicit DROP on the constraint.

(2) If I need to recreate the table, I would have to export out the
data first and later import back the data into the new table (without
the contraint). Will the identity column (PKLINK) prevent me from
importing the data? I still want the old values of the identity column
because the second table depends on it. What can I do to successful
import the data?

Thanks in advance.

Yong Sing


To drop constraints, see the ALTER TABLE statement in the SQL reference.
However, before you do that, read below.

When you create a unique constraint, DB2 automatically creates a unique
index on the column(s) in the constraints, unless a unique index already
exists. Therefore, dropping the constraint and creating a unique index on
(ENDDATE,SERIAL ) will not help you since there must already be a unique
index on these columns.

Please reorg the tables and indexes. Then execute the runstats command on
the table and the indexes and collect full statistics and column
distribution (see the Command Reference for details). Then try your query
again.

If that does not improve performance, there is something wrong (or unusual)
with your query. Please post the exact query you are having a problem with,
and be sure to include the entire WHERE clause next time.
Nov 12 '05 #2
AK
In addition to what MarkA has already posted,

in the range query

"SELECT * FROM PARENTTABLE WHERE
ENDDATE BETWEEN ...",

do you have parameter markers or do you specify exact values?

What is the cluster factor of the involved index (ENDDATE,SERIAL )?
For range queries like this it is essential to have detailed
statistics (cluster factor -1 indicates there are no detailed
statistics). Do you have them?
Nov 12 '05 #3

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

Similar topics

26
45408
by: Agoston Bejo | last post by:
I want to enforce such a constraint on a column that would ensure that the values be all unique, but this wouldn't apply to NULL values. (I.e. there may be more than one NULL value in the column.) How can I achieve this? I suppose I would get the most-hated "table/view is changing, trigger/function may not see it" error if I tried to write a trigger that checks the uniqueness of non-null values upon insert/update.
4
2912
by: wireless | last post by:
I've written code that dynamically builds an sql query based on various constraint possibilities. The problem is the code would have been very complex had I not come up with a dummy constraint as a kind of place holder in the statement. To avoid complex logic that determines if there was another constraint before any other constraint and hence the need to add, say, AND or not, I came up with a dummy constraint so that every subsequent...
2
26981
by: adammitchell | last post by:
How can you indicate that a FOREIGN KEY constraint references two columns in two different tables? "SQL Server Books Online" show an example of how to reference two columns in the SAME table: REFERENCES ref_table ) Here is the error and the 'bad' SQL code: Server: Msg 8148, Level 16, State 1, Line 4
6
5308
by: rabii | last post by:
Hello, I'm using Entreprise Manager (for Sql Server 2000) to generate my database's script. By mistake, i've changer FillFactor one time. And, now I can't remove this data from generated sql script. How to remove that ? Thank's a lot.
3
6316
by: ferg | last post by:
I have a Customer table. The table has two different CHECK constraints. Then there is the Customer details dialog, which provides the user with an UI for changing users. I have some UPDATE sql, which is called once the user clicks the OK button on this dialog. try { int rows = cmd.ExecuteNonQuery(); } catch(SqlException se)
3
15880
by: Jeff Kish | last post by:
Hi. I'm getting errors like this when I try to run an upgrade script I'm trying to write/test: altering labels to length 60 Server: Msg 5074, Level 16, State 4, Line 5 The object 'ALTPART_ANNOT_ANNOTID_FK' is dependent on column 'label'. I used this to bracket my script:
0
1305
by: Bob Weiner | last post by:
How do I remove the profilePath from a user with C#? The page, http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sds/sds/directory_object_properties.asp seems like a good reference but somehow forgot this. I have tried several variations of the following: de.Properties.Remove(de.Properties.Value); de.CommitChanges(); or
15
8559
by: Frank Swarbrick | last post by:
I have the following three tables DROP TABLE CALLTRAK.SERVICE_CODES @ CREATE TABLE CALLTRAK.SERVICE_CODES ( CODE CHAR(1) NOT NULL , CONSTRAINT SERVICE_CODES_PK PRIMARY KEY (CODE) , DESCRIPTION VARCHAR(50) NOT NULL )
2
15064
by: rorajoey | last post by:
Violation of UNIQUE KEY constraint 'IX_surveyQuestions'. Cannot insert duplicate key in object 'dbo.surveyQuestions'. This might seem like a simple matter of trying to insert a row with ID=20 when there's already one with that ID, but the problem is a bit more complicated. The table is supposed to auto-increment the value for the primary key when a new record is inserted. But no matter what I do, I can't seem to insert more than one record...
0
8310
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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
5632
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
4155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.