How do I conditionally create a table in Sybase (TSQL)?

前端 未结 9 1803
有刺的猬
有刺的猬 2020-12-14 20:31

OK, so Sybase (12.5.4) will let me do the following to DROP a table if it already exists:

IF EXISTS (
    SELECT 1
    FROM sysobjects
    WHERE name = \'a_t         


        
9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 20:57

    Try using Begin and End.

    IF NOT EXISTS ( SELECT Count(1) FROM sysobjects WHERE name = 'a_table' AND type = 'U' ) BEGIN CREATE TABLE a_table ( col1 int not null, col2 int null ) END GO

提交回复
热议问题