Determines whether a table (temporary table) exists and whether a stored procedure exists.

Source: Internet
Author: User

Determines whether a table (temporary table) exists and whether a stored procedure exists.
1. Determine whether a formal table or stored procedure has a select * from dbo. sysobjects where id = OBJECT_ID (N 'dbo. users') and type = 'U' -- U table
Select * from dbo. sysobjects where id = object_id (N 'usp _ insertalipayfeedback') and type = 'P' -- P indicates the Stored Procedure
2. Determine the temporary table type select * from tempdb. dbo. sysobjects where id = OBJECT_ID (N 'tempdb. dbo. # tempa ') and type = 'U' -- U table
Select * from tempdb. dbo. sysobjects where id = OBJECT_ID (N 'usp _ insertalipayfeedback') and type = 'P' -- P indicates the Stored Procedure
Object type. It can be one of the following values:
C = CHECK constraint D = DEFAULT value or DEFAULT constraint F = foreign key constraint
FN = scalar function IF = nested table function K = primary key or UNIQUE constraint
L = log P = Stored Procedure R = rule RF = copy and filter Stored Procedure
S = system table TF = table function TR = trigger U = User table V = view X = Extended Stored Procedure
For example, if exists (select * from tempdb. dbo. sysobjects where id = OBJECT_ID (n' tempdb. dbo. # tempa ') -- whether the temporary table drop table # tempa exists -- delete create table # tempa (Num int, Name varchar (20) default 'name' -- column default value settings) declare @ a int set @ a = 1 while @ a <30 begin insert into # tempa (Num) values (@) set @ a = @ a + 1 endselect * from # tempa

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.