|
|
| Author |
Message |
mohan_eluri
New User
Joined: 14 Mar 2006 Posts: 13 Location: Hyderabad
|
|
|
|
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 |
|
 |
References
|
|
 |
am_ne
New User
Joined: 24 Mar 2007 Posts: 25 Location: Bangalore
|
|
|
|
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 |
|
 |
mohan_eluri
New User
Joined: 14 Mar 2006 Posts: 13 Location: Hyderabad
|
|
|
|
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 |
|
 |
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 989 Location: Virginia, USA
|
|
|
|
| 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 |
|
 |
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 989 Location: Virginia, USA
|
|
|
|
| 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 |
|
 |
|
|