开发者

CREATE TABLE IF NOT EXISTS equivalent in SQL Server [duplicate]

This question already has answers here: Check if table exists in SQL Server (29 answers) Closed 3 years ago.

The community reviewed whether to reopen this question 7 months 开发者_JS百科ago and left it closed:

Original close reason(s) were not resolved

CREATE TABLE IF NOT EXISTS works on mysql but fails with SQL Server 2008 R2. What is the equivalent syntax?


if not exists (select * from sysobjects where name='cars' and xtype='U')
    create table cars (
        Name varchar(64) not null
    )
go

The above will create a table called cars if the table does not already exist.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜