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

前端 未结 9 1761
有刺的猬
有刺的猬 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条回答
  • 2020-12-14 21:15

    I haven't tested this, but you could try moving the create table statement into a sproc. You could then conditionally call that sproc based on your existing if statement.

    0 讨论(0)
  • 2020-12-14 21:23

    Assign the "CREATE TABLE" statement in a char @variable and then do an EXEC(@variable).

    0 讨论(0)
  • 2020-12-14 21:24

    There are no workarounds needed ;)

    According to the documentation:

    CREATE [ GLOBAL TEMPORARY ] TABLE [ IF NOT EXISTS ] [ owner.]table-name
    ( { column-definition | table-constraint | pctfree }, ... )
    [ { IN | ON } dbspace-name ]
    [ ENCRYPTED ]
    [ ON COMMIT { DELETE | PRESERVE } ROWS
       | NOT TRANSACTIONAL ]
    [ AT location-string ]
    [ SHARE BY ALL ]
    

    Just use the IF NOT EXISTS.

    0 讨论(0)
提交回复
热议问题