View previous topic :: View next topic
|
Author |
Message |
mjshaheed
New User
Joined: 09 Apr 2007 Posts: 25 Location: Chennai,India
|
|
|
|
Hi All,
I want to modify an existing field by adding a NOT NULL and UNIQUE KEY to an existing field. Can you please give me the syntax?
For example, suppose if the field is ENO CHAR(03) and i want to add both NOT NULL and UNIQUE KEY to it.
Thanks,
Shahul |
|
Back to top |
|
|
Srihari Gonugunta
Active User
Joined: 14 Sep 2007 Posts: 295 Location: Singapore
|
|
|
|
Hi,
You can use the following statements.
Alter table your_table add unique (ENO);
Alter table your_table alter column ENO SET NOT NULL; |
|
Back to top |
|
|
mjshaheed
New User
Joined: 09 Apr 2007 Posts: 25 Location: Chennai,India
|
|
|
|
Hi,
I tried the above two statements in QMF as well as SPUFI. But it is throwing some error. Please find the error status i got from SPUFI.
And the coulumn ENO is already existing in the table.
********************************* Top of Data **********************************
---------+---------+---------+---------+---------+---------+---------+---------+
ALTER TABLE EMPLLL ALTER COLUMN ENO SET NOT NULL; 00000200
---------+---------+---------+---------+---------+---------+---------+---------+
DSNT408I SQLCODE = -104, ERROR: ILLEGAL SYMBOL "NOT". SOME SYMBOLS THAT MIGHT
BE LEGAL ARE: CYCLE, NOCYCLE, ORDER, NOCACHE, NOORDER, NOMINVALUE,
NOMAXVALUE
Thanks,
shahul |
|
Back to top |
|
|
Srihari Gonugunta
Active User
Joined: 14 Sep 2007 Posts: 295 Location: Singapore
|
|
|
|
Shahul,
I suppose you are working on DB2 version 8 or less than that. only version 9 supports that syntax. Sorry for not mentioning the same.
You can probably add a check constraint to acheive the same effect in V8. |
|
Back to top |
|
|
Srihari Gonugunta
Active User
Joined: 14 Sep 2007 Posts: 295 Location: Singapore
|
|
|
|
you can try this out.
ALTER TABLE EMPLLL
ADD CONSTRAINT C1 CHECK (ENO IS NOT NULL) |
|
Back to top |
|
|
mjshaheed
New User
Joined: 09 Apr 2007 Posts: 25 Location: Chennai,India
|
|
|
|
Thank You Friend,
It worked great. Btw can you please tell me how to find out the DB2 version?
Regards,
Shahul |
|
Back to top |
|
|
Srihari Gonugunta
Active User
Joined: 14 Sep 2007 Posts: 295 Location: Singapore
|
|
|
|
Fine Shahul.
Issue the DB2 command
-DIS GROUP
Code: |
DB2 DB2 SYSTEM IRLM,
MEMBER ID SUBSYS CMDPREF STATUS LVL NAME SUBSYS IRLMPROC,
-------- --- ---- -------- -------- --- -------- ---- --------,
........ 0 DSN -DSNDEV ACTIVE 810 NANA IRLM DSNIRLM,
--------------------------------------------------------------------, |
you will get the above information, in which you can find the version. |
|
Back to top |
|
|
|