Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search Memberlist Usergroups Profile Log in to check your private messages Log in
 
Is it possible to disable CHECK CONSTRAINTs?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
Author Message
mohan_eluri

New User


Joined: 14 Mar 2006
Posts: 13
Location: Hyderabad

PostPosted: Fri May 30, 2008 11:32 am    Post subject: Is it possible to disable CHECK CONSTRAINTs?
Reply with quote

I have a table with below declaration

CREATE TABLE t1 (c1 CHAR(1) )

six rows are inserted with values of : A, B, C, D, E, and F

Now I altered the table t1 by

ALTER TABLE t1 ADD CONSTRAINT con1 CHECK (C1=’A’)

Will the alter statement succeed? If so what will happen to values already present in the table?

Is it possible to disable CHECK CONSTRAINTs?

Do we have any excpetion handling machanisam in DB2 to handle these situatiions?
Back to top
View user's profile Send private message
References
am_ne

New User


Joined: 24 Mar 2007
Posts: 25
Location: Bangalore

PostPosted: Fri May 30, 2008 3:05 pm    Post subject:
Reply with quote

Will the alter statement succeed? If so what will happen to values already present in the table?

YES, It'll succeed. It will put the tablespace in check pending restrictive state and you have to execute check utility to clear the state.

Is it possible to disable CHECK CONSTRAINTs?

The constraint can be dropped.

Do we have any excpetion handling machanisam in DB2 to handle these situatiions?

To clear the check pending state, you have to run check utility.
You can delete the unqualified records or copy them to exception table.

Thanks
Amit
Back to top
View user's profile Send private message
mohan_eluri

New User


Joined: 14 Mar 2006
Posts: 13
Location: Hyderabad

PostPosted: Fri May 30, 2008 5:39 pm    Post subject: Reply to: Is it possible to disable CHECK CONSTRAINTs?
Reply with quote

Thanks Amit for your reply..

What will happen to the values already in the table and violating the check constrait condition, are they deleted from table?
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 989
Location: Virginia, USA

PostPosted: Fri May 30, 2008 5:51 pm    Post subject:
Reply with quote

Quote:
ALTER TABLE t1 ADD CONSTRAINT con1 CHECK (C1=’A’)



You could also use a TRIGGER to prevent the insertion of any rows that do not have an 'A' in c1 or to prevent updates that would change the value to anything other than 'A'. The trigger would not affect current rows.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 989
Location: Virginia, USA

PostPosted: Fri May 30, 2008 5:54 pm    Post subject: Re: Reply to: Is it possible to disable CHECK CONSTRAINTs?
Reply with quote

mohan_eluri wrote:
Thanks Amit for your reply..

What will happen to the values already in the table and violating the check constrait condition, are they deleted from table?


They would have to be deleted to clear the check pending state.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1