如果SQL Server中不存在等价的表,则创建表[duplicate]

时间:2023-01-18 03:37:52

Possible Duplicate:
SQL Server: Check if table exists

可能的重复:SQL Server:检查表是否存在

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

如果在mysql中不存在工作,则创建表,但在SQL Server 2008 R2中失败。什么是等效语法?

1 个解决方案

#1


131  

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.

如果表还不存在,上面将创建一个名为cars的表。

#1


131  

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.

如果表还不存在,上面将创建一个名为cars的表。