473,761 Members | 8,372 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding new column to a table

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

Sep 5 '06 #1
13 22068
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/
Sep 5 '06 #2
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
Sep 5 '06 #3
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

Sep 5 '06 #4
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

Sep 5 '06 #5
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
Sep 5 '06 #6
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
Sep 5 '06 #7
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
Sep 5 '06 #8
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/
Sep 5 '06 #9
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
Sep 6 '06 #10

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

Similar topics

5
5290
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 (table.ID is TestTable) On .aspx page: <HeaderTemplate> <asp:Table ID="TestTable" runat="Server" /> </HeaderTemplate>
1
9896
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 created a function using VBA to achieve a more dynamic (and very slow) solution.. so I would like to implement it using a user defined function in sql server. The problems I'm facing are, that I can't use dynamic sql in a
11
5158
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 is the input element. The left column is right aligned and the right column is left aligned. I would like to replace this table with code that does not use a table for layout, and was hoping someone might be able to help me with the HTML and...
2
12605
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 far and wide. Books and news group threads are coming up nill. Thanks, RLN
0
2279
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 table to the subscriber? IE, will it copy the entire table contents out to the subscribers with this change, or will it automagically just add the new column? It's a relatively slow link and I've got a limited time window to do this upgrade, so...
2
1940
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 is, they don't align horizontally with the organization name. I need to lower the logo's within the column. However, I don't know how to manipulate one column at a time. Everything I
5
2669
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 is, they don't align horizontally with the organization name. I need to lower the logo's within the column. However, I don't know how to manipulate one column at a time. Everything I
10
2246
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 thumbnail gallery. I can query and output the data as a single column table, but I'm having problems filling up a 3 column table (with different images, looping continuously until the end).
1
4065
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" border="0"></a> </td> <td><a href="#">
3
4835
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 delete the whole table and recreates it, adding in the extra column. I don't want that. I want the data that is currently there to stay there and then add anew column. How do I reword this (If possible) to make it work? if exists (select * from...
0
9531
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9345
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
9957
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9775
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8780
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...
0
5373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3881
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3456
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2752
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.