PC Nerd Posted August 9, 2008 Share Posted August 9, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/118871-solved-truncate-table-if-exists-users-not-valid/ Share on other sites More sharing options...
MasterACE14 Posted August 9, 2008 Share Posted August 9, 2008 I'm not entirely sure. But I think you have the query back the front. IF EXISTS TRUNCATE TABLE `Users` Quote Link to comment https://forums.phpfreaks.com/topic/118871-solved-truncate-table-if-exists-users-not-valid/#findComment-612155 Share on other sites More sharing options...
PC Nerd Posted August 9, 2008 Author Share Posted August 9, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/118871-solved-truncate-table-if-exists-users-not-valid/#findComment-612156 Share on other sites More sharing options...
PC Nerd Posted August 9, 2008 Author Share Posted August 9, 2008 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); Quote Link to comment https://forums.phpfreaks.com/topic/118871-solved-truncate-table-if-exists-users-not-valid/#findComment-612160 Share on other sites More sharing options...
ShaunO Posted August 9, 2008 Share Posted August 9, 2008 IF OBJECT_ID('Users') IS NOT NULL TRUNCATE TABLE `Users` Quote Link to comment https://forums.phpfreaks.com/topic/118871-solved-truncate-table-if-exists-users-not-valid/#findComment-612161 Share on other sites More sharing options...
PC Nerd Posted August 9, 2008 Author Share Posted August 9, 2008 ahhh ok - thanks. Quote Link to comment https://forums.phpfreaks.com/topic/118871-solved-truncate-table-if-exists-users-not-valid/#findComment-612162 Share on other sites More sharing options...
PC Nerd Posted August 9, 2008 Author Share Posted August 9, 2008 IF OBJECT_ID('Users') IS NOT NULL TRUNCATE TABLE `Users` raises an error for the entire SQL statement. Any ideas why? Quote Link to comment https://forums.phpfreaks.com/topic/118871-solved-truncate-table-if-exists-users-not-valid/#findComment-612222 Share on other sites More sharing options...
Third_Degree Posted August 9, 2008 Share Posted August 9, 2008 you might need IF OBJECT_ID('databasename.Users') IS NOT NULL TRUNCATE TABLE `Users` Quote Link to comment https://forums.phpfreaks.com/topic/118871-solved-truncate-table-if-exists-users-not-valid/#findComment-612225 Share on other sites More sharing options...
Third_Degree Posted August 9, 2008 Share Posted August 9, 2008 you could also consider doing this with php. Quote Link to comment https://forums.phpfreaks.com/topic/118871-solved-truncate-table-if-exists-users-not-valid/#findComment-612226 Share on other sites More sharing options...
PC Nerd Posted August 9, 2008 Author Share Posted August 9, 2008 well then how woudl i do it in php? - im new to the live creation of tables in SQL - i usually use phpmyadmin Thanks Quote Link to comment https://forums.phpfreaks.com/topic/118871-solved-truncate-table-if-exists-users-not-valid/#findComment-612248 Share on other sites More sharing options...
Third_Degree Posted August 10, 2008 Share Posted August 10, 2008 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/118871-solved-truncate-table-if-exists-users-not-valid/#findComment-612756 Share on other sites More sharing options...
PC Nerd Posted August 10, 2008 Author Share Posted August 10, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/118871-solved-truncate-table-if-exists-users-not-valid/#findComment-612764 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.