Use SQL Server to create a simple table
Because two identical tables are not allowed in the same database, you should determine whether the table exists before creating a new table. Therefore, two functions are used.
I,
Object_id:
Returns the ID of the database object.
Syntax
Object_id ('object ')
Parameters
'Object'
The object to use. The object data type is Char or nchar. If the object data type is Char, It is implicitly converted to nchar.
Return type
Int
Example
The following example shows the ID of the object returned from the authors table in the pubs database.
Use master
Select object_id ('pubs .. Authors ')
The following is the result set:
-----------
1977058079
(1 row (s) affected)
(2)
Objectproperty
Returns information about objects in the current database.
Syntax
Objectproperty (ID, property)
-
ID
-
-
Is the expression that represents the Object ID in the current database.
IDThe data type of is
IntAnd it is assumed that it is an object within the framework range of the current database context.
-
-
Property
-
-
An expression that provides
IDReturned information of the specified object
-
-
There are many property options, so we will not list them here. The name of the istable attribute is a table, and the return value 1 is true, and the value 0 is false.
-
Example
-
-
Test whether authors is a table.
If objectproperty (object_id ('authors '), 'istable') = 1
Print 'authors is a table'
Else if objectproperty (object_id ('authors '), 'istable') = 0
Print 'authors is not a table'
Else if objectproperty (object_id ('authors '), 'istable') is null
Print 'error: authors is not an Object'