CREATE TABLE IF NOT EXISTS equivalent in SQL Server [duplicate]
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.
精彩评论