473,398 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Enter Default Values for all columns in all tables except Primary Keys

How can i enter Default Values of " " to all the columns of type character
of all the tables (excluding system tables) and Default Values of 0
of all columns of type numbers. Excluding all primary key columns.

Thank you
Nov 12 '05 #1
5 2650
serge wrote:
How can i enter Default Values of " " to all the columns of type character
of all the tables (excluding system tables) and Default Values of 0
of all columns of type numbers. Excluding all primary key columns.

Thank you

A little SQL procedure browsing SYSCAT.COLUMNS and firing an ALTER TABLE
... ALTER COLUMN .. SET DEFAULT should do it.
The ALTER TABLE statement needs to be glued together as a string and
then fired with EXECUTE IMMEDIATE.

Cheres
Serge

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

Re: the ALTER TABLE /. ALTER COLUMN .. SET DEFAULT you mention

I have DB2 WSE LUW v8.1 FP5
Can you give me an example of the SQL to do this? I want to set
a default value for *existing* columns in existing tables. I didn't
think I could do this in DB2 yet..???

Is this possible? How?

TIA
aj
Serge Rielau wrote:
serge wrote:
How can i enter Default Values of " " to all the columns of type
character
of all the tables (excluding system tables) and Default Values of 0
of all columns of type numbers. Excluding all primary key columns.

Thank you

A little SQL procedure browsing SYSCAT.COLUMNS and firing an ALTER TABLE
.. ALTER COLUMN .. SET DEFAULT should do it.
The ALTER TABLE statement needs to be glued together as a string and
then fired with EXECUTE IMMEDIATE.

Cheres
Serge

Nov 12 '05 #3
aj wrote:
Hey Serge.

Re: the ALTER TABLE /. ALTER COLUMN .. SET DEFAULT you mention

I have DB2 WSE LUW v8.1 FP5
Can you give me an example of the SQL to do this? I want to set
a default value for *existing* columns in existing tables. I didn't
think I could do this in DB2 yet..???

Is this possible? How?

DB2 V8.2 (FP7).
You can add/alter/drop:
* defaults,
* expression generated column property,
* identity column property

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #4
You're talking about changing the values from an alter add column?

You can't change the exists default other than by an update
statement...it's immutable once the column is added.

aj wrote:
Hey Serge.

Re: the ALTER TABLE /. ALTER COLUMN .. SET DEFAULT you mention

I have DB2 WSE LUW v8.1 FP5
Can you give me an example of the SQL to do this? I want to set
a default value for *existing* columns in existing tables. I didn't
think I could do this in DB2 yet..???

Is this possible? How?

TIA
aj
Serge Rielau wrote:
serge wrote:
How can i enter Default Values of " " to all the columns of type
character
of all the tables (excluding system tables) and Default Values of 0
of all columns of type numbers. Excluding all primary key columns.

Thank you

A little SQL procedure browsing SYSCAT.COLUMNS and firing an ALTER
TABLE .. ALTER COLUMN .. SET DEFAULT should do it.
The ALTER TABLE statement needs to be glued together as a string and
then fired with EXECUTE IMMEDIATE.

Cheres
Serge

Nov 12 '05 #5
Sean McKeough wrote:
You're talking about changing the values from an alter add column?

You can't change the exists default other than by an update
statement...it's immutable once the column is added.

Uh... lots of confusion. Especially since DB2 Dev. lingo is now in the mix.
Let me try to consolidate:

You cannot alter the DEFAULT property before DB2 V8.2.
You can alter the property in V8.2 and higher.
Now, changing the default property does not affect any existing values
in the table, even if they were added using the DEFAULT keyword.
So far so good and presumably uncontested.
Sean now is talking about the "exist default" for added columns.
That is, if a column is added to an existin table with existing rows,
then there must be some sort of default which is chosen for those
existing rows.
DB2 does not acually update the table when you add a column.
the ALTER TABLE returns instantanious (well, pretty much, ...)
Instead DB2 logs a separate "exist default" for those rows in the
descriptors for the table.
Whenever a row is updated the exist default will be materialized.
It is independent from the "external" semantics of changing teh default
for new rows.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #6

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

Similar topics

3
by: James | last post by:
Hello group: I've done alot of reading on this subject somewhat and have found that many people have many different opinions on this subject. My question centers mainly around using a lookup...
1
by: serge | last post by:
How can i enter Default Values of " " to all the columns of type character of all the tables (excluding system tables) and Default Values of 0 of all columns of type numbers. Excluding all primary...
10
by: serge | last post by:
I am doing a little research on Google about this topic and I ran into this thread: ...
17
by: Wilfried | last post by:
Hi, I have 5 tables: main data1
2
by: Usenet User | last post by:
I have a datagrid bound to a dataset table. Unfortunately, the table's primary key consists of not 1, but 3 columns, so I cannot correctly set the DataKeyField property of the grid (it only...
6
by: Bruce D | last post by:
I have a datagrid (uggg) that I use and create the columns programmatically...see below. objCol = New DataGridTextBoxColumn objCol.MappingName = "amount" objCol.HeaderText = "Amount"...
3
by: dbuchanan | last post by:
Hello, (Windows forms - SQL Server) I fill my datagrid with a stored procedure that includes relationships to lookup tables so that users can see the values of the combobox selections rather...
3
by: binder | last post by:
I am designing a new table with a few columns that may or may not have a value on each row that is inserted. What issues determine whether to allow a NULL value to be inserted for that column or...
8
by: Leon_Amirreza | last post by:
I have a column named "ID" and its type is "uniqueidentifier" in SQL Server 2005 Express. this column is the primary key and its default value is "newid()" in SQL Server. I have generated a...
0
by: Maric Michaud | last post by:
Le Thursday 28 August 2008 03:43:16 norseman, vous avez écrit : Disctionaries are hash tables with a unique key and constant time lookup. What you want could be implemented as a complex data...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...
0
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,...
0
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...

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.