To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here

HOME News MS SQL Oracle DB2 Access MySQL PHP Scripts Books Links DBA Talk


Go Back   Database Journal Forums > Database Discussions > MySQL

MySQL Discuss all aspects of MySQL, from installation, development and maintenance

Reply Post New Thread
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 11-04-2002, 08:46 AM
fudun fudun is offline
Junior Member
 
Join Date: Nov 2002
Posts: 3
Question Create a table if it does not exist

Simple SQL question (mySQL):

I want to create a table if it does not already exist.

How?

Please help....
Reply With Quote
  #2  
Old 11-11-2002, 09:42 AM
ggarman ggarman is offline
Junior Member
 
Join Date: Nov 2002
Posts: 6
I'm not familiar with MySQL, but here's a link to the SQL reference on msdn:

http://msdn.microsoft.com/library/de...eate2_8g9x.asp

This is the code I used:

Create Table MyNewTable ({field-name} {field type}).

For example: Create Table MyNewTable (MyField memo)

Hope this helps,
Greg
Reply With Quote
  #3  
Old 11-11-2002, 10:01 AM
fudun fudun is offline
Junior Member
 
Join Date: Nov 2002
Posts: 3
Hello?

How does that check whether the table already exists?

I think you misunderstood my question.

I know there are some advanced SQL functions, like IF EXISTS <table> or something.

But I haven't found any examples describing it. It is a really simple task, and I can make it work by some other ugly code in my application.

But what I really wanted, was a nice SQL sentence that did all the work and looked a lot nicer...


Håkon
Reply With Quote
  #4  
Old 11-13-2002, 04:02 AM
mist mist is offline
Member
 
Join Date: Oct 2002
Posts: 42
Quote:
Originally posted by fudun
Hello?

How does that check whether the table already exists?

I think you misunderstood my question.

I know there are some advanced SQL functions, like IF EXISTS <table> or something.

if not exists (select * from dbo.sysobjects where name = 'table_name')

is how you would do it in Sql Server. You probably need to find the equivalent of the sysobjects table in mysql, and query that. sysobjects is the table which contains all the objects in the database, I would imagine that there is a similar thing in mysql.
Reply With Quote
  #5  
Old 11-13-2002, 04:56 AM
fudun fudun is offline
Junior Member
 
Join Date: Nov 2002
Posts: 3
Thanks.

I'll look into that when I get time for it.

But if anyone can tell me exactly how this is done in mySQL, I'd be more than happy...
Reply With Quote
  #6  
Old 12-06-2002, 05:49 AM
gbarnett gbarnett is offline
Junior Member
 
Join Date: Dec 2002
Posts: 4
This is the sql syntax for create table. Utilise the IF NOT EXISTS clause....

CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)]

HTH
Graeme
Reply With Quote
Reply Post New Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 09:25 PM.


DatabaseJournal Recent Articles


 » Grouping with SQL Server 2008

 » Conducting Service Broker Conversation Usi...

 » SQL Server Consolidation Initiative Under ...

 » Transaction Log Growth, do you need it?

 » New FileMaker Pro 10 Ships With Sleek New ...

Search Database Journal:
 





Acceptable Use Policy

JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers

Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.