这个怎么写啊

解决方案 »

  1.   

    if not exists(select * from sysobjects where object_id('table1')=id) create table table1......
      

  2.   

    if object_id('[tb]') is not null drop table [tb]
    go
    create table [tb]([Id] int,[Name] varchar(1),[Step] int)
      

  3.   


    if object_id('table') is not null  ---存在該表
      

  4.   

    IF OBJECT_ID('xx','U') IS NULL
        CREATE TABLE xx(xx xx)
      

  5.   

    if exists(select name from sysobjects where name='P_CityBuilding_CreatedBuilding' and type='P')
    drop proc P_CityBuilding_CreatedBuilding
    go
      

  6.   

    if not exists(select * from sysobjects where name='table1') create table table1 ......
      

  7.   

    if not exists (select * from sysobjects where object_id('TableName')=id and xtype='U')
    create table TableName(..)
      

  8.   

    [code=SQL]
    if object_id('[tb]') is not null 
    create table [code]
      

  9.   


    if object_id('ta','U') is not null
    begin
    drop table ta
    create table ta
    (
    a int,
    b varchar(60)
    )
    end
    else
    print '该表存在啦!'
      

  10.   


    原理:
    表是一个对象,如果该表存在那么必定在 sys.objects 里存在该表的对象定义数据,楼主与其在看别人怎么写,还不如研究下系统表 sys.objects,里面存放的是系统对象元数据。另外,像 object_id 这些函数都是基于这张表的。
      

  11.   

    If Object_ID('Table1') Is Not Null
    Begin
     Create Table......
    End
    Else
     .............
    End