How can I determine whether an SQL Server table exists? If I need to know whether a table exists in the SQL database, what should I do? The following describes how to determine whether an SQL Server table exists. If you are interested in this, take a look.
AD:
In SQL Server, how does one determine whether an SQL Server table exists? This method will be described in detail below for your reference. I hope it will help you better understand SQL Server tables.
How to determine the existence of a table or database in SQL Server, but in actual use, you need to determine the status bit: some status bits can be set by the user using sp_dboption (read only, DBO use only, single user, etc.): 1 = autoclose; sp_dboption. The database is completely closed, and its resources are released after the last user logs out. 4 = select into/bulkcopy; Use sp_dboption to set. The select into statement and quick large-capacity replication are allowed. 8 = trunc. Log On chkpt; Use sp_dboption to set. If the database is in log truncation mode, the check point truncates the non-active part of the log. This option can only be set for the master database. 16 = torn page detection, which is set using sp_dboption. Detect incomplete pages. 32 = loading. 64 = pre recovery. 128 = recovering. 256 = not recovered. 512 = offline; Use sp_dboption to set. The database is offline. 1024 = read only; Use sp_dboption. Users can only read data in the database and cannot modify it. 2048 = DBO use only; Use sp_dboption to set. Only the database owner can use the database. 4096 = single user; Use sp_dboption to set. Only one user can access the database at a time. 32768 = emergency mode. 4194304 = autoshrink. 1073741824 = cleanly shutdown. You can open multiple locations at the same time.
For example:
Determine whether a database exists
Offline select * from Master. DBO. sysdatabases where name = 'pubs' and status <> 512
Check whether the table object exists in SQL Server:
Select count (*) from sysobjects where id = object_id ('database name. Owner. Table name ')
If exists (select count (*) from sysobjects where id = object_id ('database name. Owner. Table name') print ''else print' doesn't exist'
In SQL Server, check whether the fields in the table exist:
If exists (select * From syscolumns where name = 'colname1' and ID = object_id ('database name. Owner. Table name') print ''else print' does not exist'
Access checks whether the table object exists: in fact, the ACCESS database also has a system table and stores the select count (*) as qty from msysobjects where (msysobjects. name) Like 'table name ');