I'd like to add a new column to an existing table at a specific column
location...
Existing table definition:
MyTable(Col1, Col2, Col3)
I want to add a new column in MyTable and the new column's position is
in between Col2 and Col3:
MyTable(Col1, Col2, New_Column, Col3)
"Alter Table MyTable Add Column ..." statement adds the column to the
end (i.e. MyTable(Col1, Col2, Col3, New_Column) ).
I can drop the table and recreate it, but I would like to know whether
it can be done in any other way. Thanks for your help.
A Carter 13 22032 an*************@gmail.com wrote:
I'd like to add a new column to an existing table at a specific column
location...
Existing table definition:
MyTable(Col1, Col2, Col3)
I want to add a new column in MyTable and the new column's position is
in between Col2 and Col3:
MyTable(Col1, Col2, New_Column, Col3)
"Alter Table MyTable Add Column ..." statement adds the column to the
end (i.e. MyTable(Col1, Col2, Col3, New_Column) ).
I can drop the table and recreate it, but I would like to know whether
it can be done in any other way. Thanks for your help.
A Carter
Why would you want any other way than ALTER ADD?
It's instantanious and online....
Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
IOD Conference http://www.ibm.com/software/data/ond...ness/conf2006/ an*************@gmail.com wrote:
I'd like to add a new column to an existing table at a specific column
location...
Existing table definition:
MyTable(Col1, Col2, Col3)
I want to add a new column in MyTable and the new column's position is
in between Col2 and Col3:
MyTable(Col1, Col2, New_Column, Col3)
"Alter Table MyTable Add Column ..." statement adds the column to the
end (i.e. MyTable(Col1, Col2, Col3, New_Column) ).
I can drop the table and recreate it, but I would like to know whether
it can be done in any other way. Thanks for your help.
A table is comprised of a set of columns. Therefore, the column order is
completely irrelevant conceptually. You can choose any order of the
columns in your query.
--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Thanks for replies. Here is the situation...
I have audit column (for example, update_user_id) in every table in the
database. I'd like to keep this audit column as the last column when I
execute "describe table TableName" or "select * from TableName".
But, when I add a new column to a table, it is added after the last
column...is it possible to 'insert' the new column in between?
Thanks
A Carter
Knut Stolze wrote:
A table is comprised of a set of columns. Therefore, the column order is
completely irrelevant conceptually. You can choose any order of the
columns in your query.
For example, if you have MyTable(Col1, Col2, Col3, New_Column) you can
query it through 'SELECT Col1, Col2, New_Column, Col3 FROM MyTable'
obtaining the resultset with the columns ordered in the way you
requested. And you can choose any order as Knut suggested.
Regards,
--
Antonio Cangiano
IBM Toronto Lab http://antoniocangiano.com
Zen and the Art of Ruby Programming
Knut Stolze wrote:
A table is comprised of a set of columns. Therefore, the column order is
completely irrelevant conceptually. You can choose any order of the
columns in your query.
Does it make a difference for the primary key?
--
Texeme Construct
John Bailo wrote:
Knut Stolze wrote:
>A table is comprised of a set of columns. Therefore, the column order is completely irrelevant conceptually. You can choose any order of the columns in your query.
Does it make a difference for the primary key?
No. Why should it?
If I remember correctly, there was the suggestion to have all fixed-length
columns at the beginning and all variable ones at the end. The advantage
is that the access to the fixed length data is faster because the position
of the data is known right away and you don't have to traverse over the
variable length stuff. If this still holds true with V8 and V9, I do not
know.
--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Knut Stolze wrote:
>>Does it make a difference for the primary key?
No. Why should it?
If I remember correctly, there was the suggestion to have all fixed-length
columns at the beginning and all variable ones at the end. The advantage
is that the access to the fixed length data is faster because the position
of the data is known right away and you don't have to traverse over the
variable length stuff. If this still holds true with V8 and V9, I do not
know.
Well, say there are three columns, FieldA, FieldB, FieldC, physically
laid out in that order.
If I choose FieldA and FieldC, then to create the index it will have to
scan across FieldB each time to get to FieldC.
Whereas if I choose FieldA and FieldB, it will be a best case scan --
OR, if I layout the table as FieldA, FieldC, FieldB in the column order.
--
Texeme Construct
John Bailo wrote:
Knut Stolze wrote:
>>Does it make a difference for the primary key?
No. Why should it?
If I remember correctly, there was the suggestion to have all fixed-length columns at the beginning and all variable ones at the end. The advantage is that the access to the fixed length data is faster because the position of the data is known right away and you don't have to traverse over the variable length stuff. If this still holds true with V8 and V9, I do not know.
Well, say there are three columns, FieldA, FieldB, FieldC, physically
laid out in that order.
If I choose FieldA and FieldC, then to create the index it will have to
scan across FieldB each time to get to FieldC.
Whereas if I choose FieldA and FieldB, it will be a best case scan --
OR, if I layout the table as FieldA, FieldC, FieldB in the column order.
There is no such thing as scanning within a row.
DB2 does I/O at least in pages which can each contain up to 2000 rows
(in DB2 9).
There is exactly one good reason to worry about teh order of column in a
table: logging. When a row gets updated DB2 only logs from the start of
the first change to the end of the last. So, if you often update two
columns in a table and they happen to be the last and the first column
in the table definition, that would be increase the size of the log file.
In reality customers do NOT worry about that sort of thing. In TPC-C
where 0.5% difference mean a lot, yes we do worry.
Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
IOD Conference http://www.ibm.com/software/data/ond...ness/conf2006/
Serge Rielau wrote:
There is no such thing as scanning within a row.
DB2 does I/O at least in pages which can each contain up to 2000 rows
(in DB2 9).
Question: assuming you have this table structure:
col1 INT
col2 VARCHAR
col3 INT
Now you have "SELECT col3 FROM t". DB2 will have to skip "col1" and "col2"
to find the value of "col3", won't it? So that means there is some
scanning, although it is in memory and I really doubt that it makes a
noticeable difference.
--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Knut Stolze wrote:
Serge Rielau wrote:
>There is no such thing as scanning within a row. DB2 does I/O at least in pages which can each contain up to 2000 rows (in DB2 9).
Question: assuming you have this table structure:
col1 INT
col2 VARCHAR
col3 INT
Now you have "SELECT col3 FROM t". DB2 will have to skip "col1" and "col2"
to find the value of "col3", won't it? So that means there is some
scanning, although it is in memory and I really doubt that it makes a
noticeable difference.
"Will have to"? There are other strategies than linked lists...
Now, unless anyone reading this thread is planning to write their own
LOAD utility an answer to this really yields no practical value.
Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
IOD Conference http://www.ibm.com/software/data/ond...ness/conf2006/
Knut Stolze wrote: an*************@gmail.com wrote:
>I'd like to add a new column to an existing table at a specific column location...
Existing table definition: MyTable(Col1, Col2, Col3)
I want to add a new column in MyTable and the new column's position is in between Col2 and Col3: MyTable(Col1, Col2, New_Column, Col3)
"Alter Table MyTable Add Column ..." statement adds the column to the end (i.e. MyTable(Col1, Col2, Col3, New_Column) ). I can drop the table and recreate it, but I would like to know whether it can be done in any other way. Thanks for your help.
A table is comprised of a set of columns. Therefore, the column order is
completely irrelevant conceptually. You can choose any order of the
columns in your query.
Order of columns is very important when you do EXPORT/IMPORT. Yes, you can
remap them, but still.
Best regards,
Kovi
--
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
| Gregor Kovac | Gr**********@mikropis.si |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Serge Rielau wrote:
When a row gets updated DB2 only logs from the start of
the first change to the end of the last.
Is this an improvement in DB2 V9, or DB2 has had this feature for a
while?
Also would you please explain on what gets logged for changes done to
indexes? If index changes do not get logged, then is it correct to
assume DB2 effectively inserts/updates/deletes index entries during a
roll-forward (and roll-back) operation, just as if changes to table
were done using SQL DML?
TIA
P Adhia
Gregor Kovač wrote:
Order of columns is very important when you do EXPORT/IMPORT. Yes, you can
remap them, but still.
No, not really because you can specify into which columns you want to import
and also the order of those columns. Only if you rely on implicit things,
then the order is relevant.
--
Knut Stolze
DB2 Information Integration Development
IBM Germany This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Sue |
last post by:
On code-behind page:
(attributes set programatically for each of these elements)
linkbutton added to tablecell
textbox added to tablecell
tablecells added to tablerow
tablerow added to table...
|
by: Not Me |
last post by:
Hi,
I'm sure this is a common problem.. to create a single field from a
whole column, where each row would be separated by a comma.
I can do this for a specified table, and column.. and I've...
|
by: Peter Foti |
last post by:
Hi all,
I have a form that contains a 2 column table. In the left column is the
description for a particular input (ie - "First Name", "Last Name", "Phone
Number", etc.). In the right column...
|
by: Ron Nolan |
last post by:
Re: Access 2000
Does anyone know how to add column to a table using ADO?
I need to add a column called "autonum" that has a datatype of
"AutoNumber" to a table called "MyTbl".
I have searched...
|
by: Brian K |
last post by:
I'm applying schema changes to a replicated database. One table has
approximately 3.5 million rows and I'm planning on adding a column to it
via sp_repladdcolumn.
Will it "re-initialize" that...
|
by: Hymer |
last post by:
Hello,
I have a small two-column table with three rows. The first column has a logo
and the second column has the name of the organization.
The logo's in the first column are too high. That...
|
by: Hymer |
last post by:
Hello,
I have a small two-column table with three rows. The first column has a logo
and the second column has the name of the organization.
The logo's in the first column are too high. That...
|
by: ste |
last post by:
Hi there,
I'm trying to query a MySQL database (containing image data) and to output
the results in a HTML table of 3 columns wide (and however many rows it
takes) in order to create a basic...
|
by: akress |
last post by:
Hiya,
I'm trying to convert a table with 6 colums that looks like this:
<table class="myTable" width="640px">
<tr>
<td><a href="#">
<img src="../_img/announce.gif" align="middle"...
|
by: Shestine |
last post by:
I am trying to add a column to a current table, with data in it. I am only learning, and i have no idea how to change this to make it work. Here is the script I have right now it, but what it does is...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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 projectplanning, coding, testing,...
|
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...
| |