Jump to content

How To Check If A Table Exists In Sql?


tinfanide

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>
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...