Jump to content

How To Check If A Table Exists In Sql?

Recommended Posts

<?php$database = "test";$connect = mysql_connect("localhost","assessment","hsilgne");if(is_resource($database)){mysql_query("CREATE DATABASE ".$database,$connect) or die(mysql_error());}mysql_select_db($database,$connect);$sqlTable = "CREATE TABLE scoresTable (id int NOT NULL AUTO_INCREMENT,PRIMARY KEY(id),name varchar(15),score int NOT NULL)";mysql_query($sqlTable,$connect);mysql_query("INSERT INTO scoresTable (name, score)		 VALUES ('Tin','100')		 ");mysql_close($connect);?>

I've searched online for this and some answers are like usingOBJECT_ID() But it seems not working or I don't know the exact syntax.Could anyone point me to the right direction?

If object_id('tbl_name') is not null<command> ORif exists (select * from sysobjects where id = object_id('tbl_name') and sysstat & 0xf = 4)<command>
  • Like 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...