SQL Server 2000/2005 determines whether stored procedures, triggers, views exist, and deletes

Source: Internet
Author: User
Tags scalar

1, determine whether there is addonearticle this stored procedure

If Exists (select name from sysobjects where name = ' addonearticle ' and type= ' P ')

drop procedure Addonearticle
2, determine whether there is countar this trigger

if exists (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].[ Countar] ') and OBJECTPROPERTY (ID, N ' istrigger ') = 1)

Drop Trigger Countar
3, judge whether there is view_1 this view

IF EXISTS (SELECT table_name from INFORMATION_SCHEMA. Views WHERE table_name = N ' view_1 ')

DROP View View_1
4, judge whether there is user_fun this user function

(Note that there are two types in this type, the ' TF '-table-valued function table-valued functions or the ' FN '-scalar-valued function Scalar-valued functions)

if exists (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].[ User_fun] and (type = ' FN ' or type = ' TF ')

DROP FUNCTION User_fun

5. Determine if the table ' Tb ' exists

if (Exists (SELECT * from dbo.sysobjects WHERE id = object_id (n ' Tb ') and OBJECTPROPERTY (ID, n ' isusertable ') = 1))

DROP TABLE Tb

6. Determine if the database exists

if exists (SELECT * from master.dbo.sysdatabases where dbid=db_id (' scbjdb '))

Drop Database Scbjdb

Else

print ' No exist scbjdb '

SQL Server 2000/2005 determines whether stored procedures, triggers, views exist, and deletes

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.