473,396 Members | 2,037 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,396 software developers and data experts.

HELP: Adding a field to a database table

When adding a field to a table using ALTER TABLE is it possible to check if
the field already exits before the ADD command is run? If so how do I do
this?

Thanks
Hamilton
Jul 23 '05 #1
3 1788
Funnyweb wrote:
When adding a field to a table using ALTER TABLE is it possible to check if
the field already exits before the ADD command is run? If so how do I do
this?


Read the following pages and see if you can find a solution that meets
your needs (you didn't state what programming language or environment
you are using):
http://dev.mysql.com/doc/mysql/en/show-columns.html
http://dev.mysql.com/doc/mysql/en/describe.html
http://dev.mysql.com/doc/mysql/en/mysqlshow.html

Also see a similar thread from earlier this week on this group:
http://groups-beta.google.com/group/...46b4f04e52c84/

Regards,
Bill K.
Jul 23 '05 #2
Thanks for the information.

I should have explained that I was talking about writing .sql files.

You can check if a table (and some other things) exist by using IF EXISTS.
I gather from reading the links you quoted that there is no such test for
columns (fields) in a table?

Hamilton

"Bill Karwin" <bi**@karwin.com> wrote in message
news:cv********@enews2.newsguy.com...
Funnyweb wrote:
When adding a field to a table using ALTER TABLE is it possible to check
if the field already exits before the ADD command is run? If so how do I
do this?


Read the following pages and see if you can find a solution that meets
your needs (you didn't state what programming language or environment you
are using):
http://dev.mysql.com/doc/mysql/en/show-columns.html
http://dev.mysql.com/doc/mysql/en/describe.html
http://dev.mysql.com/doc/mysql/en/mysqlshow.html

Also see a similar thread from earlier this week on this group:
http://groups-beta.google.com/group/...46b4f04e52c84/

Regards,
Bill K.

Jul 23 '05 #3
Funnyweb wrote:
Thanks for the information.

I should have explained that I was talking about writing .sql files.

You can check if a table (and some other things) exist by using IF EXISTS.
I gather from reading the links you quoted that there is no such test for
columns (fields) in a table?


As far as I know, that is correct. I don't think there is any solution
that can be written purely in .sql files.

If you have a scripting language, you could use the SHOW COLUMNS,
examine the output, and conditionally create the columns. But .sql
files are not a replacement for a more fully-featured scripting
language. That is, there's no SQL script equivalent to run a statement
conditionally based on the output of the previous statement.

One possibility is to run a script that contains ALTER TABLE ADD COLUMN
statements, which will fail if there is already a column by that name.
But you can run the script using the "mysql --force" so that the
command-line interpreter will continue even if some statements result in
an SQL error.

Regards,
Bill K.
Jul 23 '05 #4

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

Similar topics

0
by: Preston Landers | last post by:
Hello all. I am trying to write a query that "just" switches some data around so it is shown in a slightly different format. I am already able to do what I want in Oracle 8i, but I am having...
11
by: Bobbak | last post by:
Hello All, I have these tables (lets call it ‘EmpCalls', ‘EmpOrders', and ‘Stats') that each contain the list of EmployeeIDs, I want to be able to create a Module in which I could call in my VB...
9
by: Edward S | last post by:
I budget for a Project in an Excel sheet as illustrated below. The months below are usually a 2 year period i.e. 24 months, though it could be over 24 months depending upon a Project. I then...
11
by: my-wings | last post by:
I think I've painted myself into a corner, and I'm hoping someone can help me out. I have a table of books (tblBooks), which includes a field (strPubName) for Publisher Name and another field...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
4
by: bpneary1 | last post by:
First of all, I want to thank everyone who posts messages in this group. I am very new to VB and developing full-blown database apps, and I have learned a great deal by reading these posts, so I...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
10
by: 60325 | last post by:
This is the page where I collect the data in drop-down boxes with values of 1-10 and send it to a submitted page to do calculations. Example: Employee1 TeamScore(1-10) Employee2 ...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
0
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
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:
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...
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
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...
0
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...
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,...

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.