Before you create a table, you usually need to determine if the table already exists, and if it does, you do not need to create it, and sometimes you need to determine whether it exists before you delete the table, or you will get an error.
There are roughly two ways of judging the method:
Method One:
if Exists(Select Top 1 1 fromSysObjectswhereId=object_id(N'Le_user') andXtype='U') Print 'exist'Else Print 'does not exist'
Method Two:
if object_id (n'le_user', n'U'is notnull print' exists ' else Print ' does not exist '
Both of these methods use the sysobjects system table, which holds all object information, since it is all objects, naturally including the information of the table, where xtype is represented by U as the user table.
The method for determining whether a temporary table exists is as follows:
if object_id(N'tempdb: #TempTable'N'U') is not NULL Print 'exist'Else Print 'does not exist'if exists(Select * fromTempdb.dbo.sysobjectswhereId= object_id(N'tempdb: #TempTable') andType='U') Print 'exist' Else Print 'does not exist'
The temporary table itself is also a table, so judging the existence of the method is the same as the normal table, but need to increase tempdb. Indicates a temporary table.
SQL Server determine if table exists method