Jump to content

Archived

This topic is now archived and is closed to further replies.

PC Nerd

[SOLVED] TRUNCATE TABLE IF EXISTS `Users` - not valid?

Recommended Posts

Hi,

 

mysql spits out he following error in phpmyadmin:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF EXISTS `Users`' at line 1

 

so...... im assuming from that that the TRUNCATE statement doesnt allow you to place teh "IF EXISTS" with it..... so what can i do as an alternative?

 

Thanks

Share this post


Link to post
Share on other sites

I'm not entirely sure. But I think you have the query back the front.

IF EXISTS TRUNCATE TABLE `Users`

Share this post


Link to post
Share on other sites

thanks - but still raises an error.

 

It looks to me that whereever i place the "IF EXISTS" in teh SQL - is where the error starts, which is what broght me to my guess that it doesnt support "IF EXISTS".

 

Thanks though

Share this post


Link to post
Share on other sites

Ill use:

 

DROP TABLE IF EXISTS `Users` and then CREATE TABLE IF NOT EXISTS `Users` etc etc etc

 

thanks though ( unless you have a better solution);

Share this post


Link to post
Share on other sites

IF OBJECT_ID('Users') IS NOT NULL TRUNCATE TABLE `Users`

Share this post


Link to post
Share on other sites

IF OBJECT_ID('Users') IS NOT NULL TRUNCATE TABLE `Users`

raises an error for the entire SQL statement.  Any ideas why?

 

Share this post


Link to post
Share on other sites

well then how woudl i do it in php? - im new to the live creation of tables in SQL - i usually use phpmyadmin

 

Thanks

Share this post


Link to post
Share on other sites

honestly, all you really need here is:

 

<?php

/*
MySQL Connection Here
*/

$q = @mysql_query( "TRUNCATE TABLE `Users`" );
$result = ( $q ) ? "Table 'Users' does exist, and has been truncated." : "Table 'Users' does not exist";
echo $result;

?>

Share this post


Link to post
Share on other sites

ok - thanks.... ive ended up just doing a :

DROP TABLE IF EXISTS `name`

CREATE TABLE IF NOT EXISTS `name`

 

and so forth..

 

thanks for all the help.

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.