Home >Database >Mysql Tutorial >How to Create a Table Only if It Doesn't Exist in SQL Server?
Equivalent of CREATE TABLE IF NOT EXISTS in SQL Server
The MySQL command CREATE TABLE IF NOT EXISTS is used to create a table only if it does not already exist. This syntax is not directly compatible with SQL Server.
Alternative Syntax in SQL Server
To achieve the same functionality in SQL Server, an alternative syntax using a conditional query can be employed:
if not exists (select * from sysobjects where name='cars' and xtype='U') create table cars ( Name varchar(64) not null ) go
In this code:
Additional Notes
The above is the detailed content of How to Create a Table Only if It Doesn't Exist in SQL Server?. For more information, please follow other related articles on the PHP Chinese website!