EllisLab/CodeIgniter — Issue #862: dbforge create_table IF NOT EXISTS with sqlsrv
Author: colonelchlorine
Created: 2012-01-03 18:55:29+00:00
State: open

With the following code SQL gives an error **Incorrect syntax near the keyword 'IF'.**

```php
$this->dbforge->add_field(array(
'version' => array('type' => 'INT'),
));

$this->dbforge->create_table('migrations', TRUE);
```

This generates the following code in SQL Server 2008 with sqlsrv.

```sql
CREATE TABLE IF NOT EXISTS migrations (
version INT NOT NULL
)
```

Changing the last line to the below line fixes this error, but may result in an error generated from SQL Server (table already exists) if this code is called twice.

```php
$this->dbforge->create_table('migrations', false);
```