How to only create table if it doesn't exist? Using “object_id('table') IS NULL” doesn't work?
问题 I would like to check if the table does not exist, then create one, otherwise, insert data into it. use tempdb if object_id('guest.my_tmpTable') IS NULL begin CREATE TABLE guest.my_tmpTable ( id int, col1 varchar(100) ) end --- do insert here ... The first time run, the table was created but the 2nd run the sybase complains the table already exist. Thanks! 回答1: The reason is that the entire statement - if and its "true" part are compiled as one. If the table exists during compilation - error.