Is it possible to develop separate SQL scripts for creating a system-versioned table and its primary key in SQL Server? I encounter an error when attempting this.
> The system-versioned table requires a primary key to be established.
For illustration:
```sql
CREATE TABLE example_table
(
[Identifier] int IDENTITY(1,1) NOT NULL,
[Title] varchar(1024),
[RowStart] [datetime2](7) GENERATED ALWAYS AS ROW START NOT NULL,
[RowEnd] [datetime2](7) GENERATED ALWAYS AS ROW END NOT NULL,
PERIOD FOR SYSTEM_TIME ([RowStart], [RowEnd])
)
WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = example_history, DATA_CONSISTENCY_CHECK = ON));
ALTER TABLE example_table
ADD CONSTRAINT [PK_Example]
PRIMARY KEY CLUSTERED (Identifier) ASC;
Yep, you can do this, but SQL Server needs the primary key defined in the table itself when you initially create a system-versioned table. It’s because of the row uniqueness it relies on. Just include the primary line in your original create table statement and it should work smoothly. 