473,785 Members | 2,498 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DDL question WRT adding NOT NULL constraints

Hi,

I'm new to DB2, but am relatively familiar with databases, and I've run
into something I don't fully understand. I created a table tab4, then,
after the fact, altered the table so that one of the columns must not
contain null values. I used the command:

db2inst1@reihe5 1:~> db2 "alter table tab4 ADD CHECK (sp1 is NOT NULL)"
// using "alter table add constraint" didn't work

I then created a table tab5, defining the column as NOT NULL at
creation time.

db2inst1@reihe5 1:~> db2 "create table tab5 (sp1 int NOT NULL)"

Running "describe table" against each of the two, I get an unexpected
result:

db2inst1@reihe5 1:~> db2 "describe table tab4"

Column Type Type
name schema name Length
Scale Nulls
------------------------------ --------- ------------------ --------
----- ------
SP1 SYSIBM INTEGER 4
0 Yes
SP2 SYSIBM CHARACTER 10
0 Yes

2 record(s) selected.

db2inst1@reihe5 1:~> db2 "describe table tab5"

Column Type Type
name schema name Length
Scale Nulls
------------------------------ --------- ------------------ --------
----- ------
SP1 SYSIBM INTEGER 4
0 No

1 record(s) selected.
// expected behavior since I defined sp1 as NOT NULL at create time

Since I added the check constraint to tab4, why does the "Nulls" column
still show "Yes"? Is there a way to change that other than dropping the
table and recreating it?

Thanks,
Mike

Nov 12 '05 #1
2 4357
mi*********@gma il.com wrote:
Since I added the check constraint to tab4, why does the "Nulls" column
still show "Yes"? Is there a way to change that other than dropping the
table and recreating it?

DB2 treats NOT NULL as column property.
CHECK (c1 IS NOT NOT) on the other hand is a check constraint like any
other.
Describe only tests for the column preperty.
Currently in DB2 for LUW you would have to drop and recreate the table
to alter the NOT NULL column property.
DB2 V8.2 has an ALTE TABEL "wizard" built into control center which
automates that process.

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2
Serge,

Thanks for responding. I had a suspicion that it might have been
something along those lines, but you locked it in for me.

Mike

Nov 12 '05 #3

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

Similar topics

2
14495
by: Jennifer | last post by:
I've got a table with 36+ million rows. I've been asked to modify the table and add in an identity column. The code I used caused SQL to lock up and it maxed out the log files. :) The code I used is: Begin Transaction Alter Table ODS_DAILY_SALES_POS ADD ODS_DAILY_SALES_POS_ID BigInt NOT NULL IDENTITY (1,1) Commit
10
4015
by: Eric Petruzzelli | last post by:
If I fill my dataset and there is no data. The dataset is still created with zero rows (all columns are there). When I add my first row using the script below, it takes over 2 seconds to add??? If I add the second row, instant. How can I eliminate this delay?
1
3886
by: Robin Tucker | last post by:
I'm considering adding domain integrity checks to some of my database table items. How does adding such constraints affect SQL Server performance? For example, I have a simple constraint that restricts a couple of columns to having values within the values assigned in my application by an enumeration: (( >= 0 and <=3) and ( >= 0 and <= 2)) This enforces domain integrity for two enumerations having values 0, 1, 2, 3
2
2920
by: Gail Zacharias | last post by:
I am investigating the possibility of using pgsql as the database in an application. I have some unusual requirements that I'd like to ask you all about. I apologize in advance if my terminology is a little "off", I'm not familiar with pgsql (yet). My first requirement is that I need to be able to add new columns to any database table on the fly. By this I mean that I need this to happen interactively -- a user will drag some UI widget...
31
3538
by: vp | last post by:
If I have a pointer char * p, is it correct to assign NULL to this pointer by: "memset( &p, 0, sizeof(p));" instead of "p = NULL;" The reason I ask is I have an array of structure of N function variables, for example, typedef struct {
41
10060
by: Alexei A. Frounze | last post by:
Seems like, to make sure that a pointer doesn't point to an object/function, NULL (or simply 0) is good enough for both kind of pointers, data pointers and function pointers as per 6.3.2.3: 3 An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.55) If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed...
13
8735
by: Federico Balbi | last post by:
Hi, I was wondering if PGSQL has a function similar to binary_checksum() of MS SQL Server 2000. It is pretty handy when it comes to compare rows of data instead of having to write long boolean expressions. binary_checksum() takes a list of fields and it returns an integer value which sumarize the row content. Thanks, Fed
5
6852
by: yeoj13 | last post by:
Hello, I have a db2load script I'm using to populate a large table. Ideally, my target table is required to have "Not Null" constraints on a number of different columns. I've noticed a huge performance hit when I load the target table with "Not Null" constraints as compared to loading a target table without the constraints.
4
22006
by: Bobby Edward | last post by:
I have an xsd dataset. I created a simple query called GetDataByUserId. I can preview the data fine! I created a very simple BLL function that calls it and returns a datatable. When I run the code I get.... ======================= Server Error in '/MyCompanyMyProject' Application.
0
9481
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
10341
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10095
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
8979
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6741
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
5383
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
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2881
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.