Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ALTER TABLE

Status
Not open for further replies.

WilliamMute007

Programmer
Sep 30, 2007
116
GB
Hi am back again with my troubles guys,

not sure how to go about this, I want to check if a name exist in a DB table if not, then insert a name into the DB prior to further updating it.

i.e

Code:
Select star from tablename;

 if { tablename.username = 'vee' DO  something }

else { Insert into tablename.username = 'username' 
}
[CODE]

How can I achieve such in SQL please? Thanks a bunch!
 
please do a SHOW CREATE TABLE for this table

then show a couple of sample rows

then describe what you're trying to do with the INSERT

and where does the ALTER come into this? you're not really going to add a new column, are you?

r937.com | rudy.ca
 
Look in the information_schema database. Write a procedure that queries the COLUMNS table, and if the field is not found, fire up your ALTER TABLE statement. The reason for this to put in a procedure is that IF statements can only occur in procedures. You can put a DROP PROCEDURE IF EXISTS clause in front of your procedure definition to make it repeatable.

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
Thanks for all your contributions guys, I figured out that this will be a complicated process so I did it another way round though longer, but easier to archieve what I wanted.

Thanks for all your suggestions and help! appreciated...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top