Hello All,
I am having problems finding the correct syntax for changing a column from NULL to NOT NULL.
We are using DB2 on z/OS.
I have tried:
ALTER TABLE TEST_CB ALTER COLUMN TEST_CHAR NOT NULL;
ALTER TABLE TEST_CB ALTER COLUMN TEST_CHAR SET NOT NULL;
And a couple others, but no luck.
Thanks,
Craigbert
9 91062
Does the silence mean that there is not a way to do this w/o dropping and recreating the table?
What do you mean by change a column from null to not null? The only thing that would make sense is if you're trying to put a validation on the column in which they can not leave the column blank. In which case, you're trying to add a check constraint. If that is the case, you need to look up the syntax for that. If that is not the case, I have no idea what you're trying to do.
Rabbit,
Thanks for the reply.
Your initial guess is correct.
When I look at the IBM DB2 v9 manual online this is the syntax I see: - ALTER TABLE bar ALTER COLUMN C1 SET NOT NULL
But when I use that syntax I get the following error: - Category Timestamp Duration Message Line Position
-
Error 1/13/2011 10:49:33 AM 0:00:00.171 <link> - DB2 Database Error: ERROR [42601] [IBM][DB2] SQL0104N An unexpected token "NOT" was found following "". Expected tokens may include: "CYCLE, NOCYCLE, ORDER, NOCACHE, NOORDER, NOMINVALUE, NOMAXVALUE". SQLSTATE=42601
-
3 0
-
What am I doing wrong????
Thanks,
Craigbert
Here's what I was able to find in the documentation.
NOT NULL
Prevents the column from containing null values. The default-clause must also be specified (SQLSTATE 42601).
NULL
Specifies NULL as the default for the column. If NOT NULL was specified, DEFAULT NULL must not be specified within the same column definition.
Or, there's the option of - ALTER TABLE tableName
-
ADD CONSTRAINT constraintName (fieldName IS NOT NULL)
Or you could alter the column data type with a not null after the data type.
alter table <table_name> alter column <column_name> drop not null
JUKe & Rabbit,
Here is what I have tried w/o any luck:
ALTER TABLE DEPT ALTER COLUMN LD2_IN DROP NOT NULL;
returns the following error:
ERROR [42601] [IBM][DB2] SQL0104N An unexpected token "DROP" was found following "". Expected tokens may include: "RESTART". SQLSTATE=42601
ALTER TABLE DEPT ADD CONSTRAINT CK01A(LD2_IN IS NULL);
returns the following error:
Lookup Error
ERROR [42601] [IBM][DB2] SQL0104N An unexpected token "(" was found following "". Expected tokens may include: "FOREIGN CHECK UNIQUE PRIMARY". SQLSTATE=42601
ALTER TABLE DEPT ALTER COLUMN LD2_IN SET DATA TYPE CHAR(1);
This statement executes, but it does not do anything to the NULL option.
ALTER TABLE DEPT ALTER COLUMN LD2_IN SET DATA TYPE CHAR(1) IS NULL;
produces the following error:
Lookup Error
ERROR [42601] [IBM][DB2] SQL0199N The use of the reserved word "IS" following "" is not valid. Expected tokens may include: "FOR ADD ALTER APPEND VALIDPROC AUDIT DROP DATA VOLATILE NOT". SQLSTATE=42601
ALTER TABLE DEPT ALTER COLUMN LD2_IN SET DATA TYPE CHAR(1) NULL;
produces the following error:
Lookup Error
ERROR [42601] [IBM][DB2] SQL0199N The use of the reserved word "NULL" following "" is not valid. Expected tokens may include: "FOR ADD ALTER APPEND VALIDPROC AUDIT DROP DATA VOLATILE NOT". SQLSTATE=42601
Any other suggestions?
Did you ever determine how to do this? I am trying to do the same thing using db2 zos v9.
too late to reply- this is what i tried and it worked - - alter table table_name alter column column_name set not null
Hi,
in DB2 version 12 this doesn't work:
---------+---------+---------+---------+---------+---------+---------+-----
ALTER TABLE DBRF001T.RFT2291_IMAGE_ZUSATZ
ALTER COLUMN OB
SET NOT NULL;
---------+---------+---------+---------+---------+---------+---------+-----
DSNT408I SQLCODE = -199, ERROR: ILLEGAL USE OF KEYWORD NOT. TOKEN WITH
DEFAULT DATA INLINE CACHE MAXVALUE MINVALUE NOCACHE WAS EXPECTED
DSNT418I SQLSTATE = 42601 SQLSTATE RETURN CODE
DSNT415I SQLERRP = DSNHPARS SQL PROCEDURE DETECTING ERROR
DSNT416I SQLERRD = 2 0 0 -1 157 506 SQL DIAGNOSTIC INFORMATION
DSNT416I SQLERRD = X'00000002' X'00000000' X'00000000' X'FFFFFFFF'
X'0000009D' X'000001FA' SQL DIAGNOSTIC INFORMATION
---------+---------+---------+---------+---------+---------+---------+-----
DSNE618I ROLLBACK PERFORMED, SQLCODE IS 0
DSNE616I STATEMENT EXECUTION WAS SUCCESSFUL, SQLCODE IS 0
---------+---------+---------+---------+---------+---------+---------+-----
DSNE601I SQL STATEMENTS ASSUMED TO BE BETWEEN COLUMNS 1 AND 72
DSNE620I NUMBER OF SQL STATEMENTS PROCESSED IS 1
DSNE621I NUMBER OF INPUT RECORDS READ IS 3
DSNE622I NUMBER OF OUTPUT RECORDS WRITTEN IS 20
******************************** Bottom of Data ***************************
Sign in to post your reply or Sign up for a free account.
Similar topics
by: luc h |
last post by:
Hello,
Easy one for the SQL experts.
I have a simple table. For the example let's say it looks like this:
CREATE TABLE doc_exb ( column_a INT, column_b VARCHAR(20) NULL)
Now I want to alter...
|
by: me |
last post by:
I would like to add an Identity to an existing column in a table using a
stored procedure then add records to the table and then remove the identity
after the records have been added or something...
|
by: Danny |
last post by:
I'm trying to simply change a column definition from Null to Not Null. It's
a multi million row table. I've already checked to make sure there are no
nulls for any rows and a default has been...
|
by: Euler Almeida via SQLMonster.com |
last post by:
Hi people,
I?m trying to alter a integer field to a decimal(12,4) field in MSACCESS 2K.
Example:
table : item_nota_fiscal_forn_setor_publico
field : qtd_mercadoria integer NOT NULL...
|
by: Prince Kumar |
last post by:
Is there any way I can define an Unique constraint or unique index
which allows more than one null values for the same column combination
in DB2?
ie, If my index is defined on (col3, col4) where...
|
by: Jeff Kish |
last post by:
Hi.
I have a database I need to supply something (I'm assuming a t-sql script..
maybe something else is better) to update customer tables with.
The operations include mostly changing varchar...
|
by: sparks |
last post by:
several months ago I was trying to set the field size of text fields
in a table and Lyle Fairfield was nice enought to post a way using
alter column.
it was surprising since it was ALTER COLUMN...
|
by: siujean |
last post by:
As captioned question, i would like to how to alter the column from
null to not null?
Thanks
|
by: Jeff Kish |
last post by:
Hi.
I've read up on this, and have something that works, but I was wondering if
there is anything I'm overlooking with this.
Situation is:
I have a bunch of tables.. I need to modify table2...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |