从前我无论删表还是删除存储过程都是否样删除的
if exists(select * from sysobjects where name = 'Name')
  drop table/proc/trigger Name
go请问如果我想要分门别类去在括号中查询,然后再删除应该怎么去做就是我想删除存储过程,那么查询出来的都是存储过程,然后再name中判断是否是想要删除的
.....
说得不太清楚,请见谅..
谢谢帮助我的朋友

解决方案 »

  1.   

    select * from sysobjects where name = 'Name' and xtype = 'P'P = 存储过程 
    TR = 触发器 
    U = 用户表
      

  2.   

    xtype 列是类型,如:'U'是用户表,'PK'是主键。
      

  3.   

    select * from sysobject where xtype='u'  表
    xtype='p'存储
    'v'视图
      

  4.   


    if exists(select * from sysobjects where name = 'Name' and xtype='P')
      drop proc Name
    go
      

  5.   

    if object_id('Name') is not null
    begin
    declare @id int
    set @id=object_id('Name')
    if objectproperty(@id,'istable')=1
    drop table Name
    else if objectproperty(@id,'isveiw')=1
    drop view Name
    else if objectproperty(@id,'isprocedure')=1
    drop proc Name
    else if objectproperty(@id,'istrigger')=1
    drop trigger Nameend
      

  6.   

    if object_id('Name') is not null
    就是证明有这个name表存在么?
      

  7.   

    是的.if exists(select * from sysobjects where name = 'Name' and xtype = 'U'/'P'...)
      drop table/proc/trigger Name
    go
    即可分类删除了.
      

  8.   


    go
    if exists(select * from sysobjects where xtype='p' and name = 'Name')
    drop proc Name
    go
    if exists(select * from sysobjects where xtype='tr' and name = 'Name')
    drop trigger Name
    go
    if exists(select * from sysobjects where xtype='u' and name = 'Name')
    drop table Name