CREATE TABLE AS - how to add column with PK?
CREATE TABLE AS
statement.
My code:
CREATE TABLE DOC AS
SELECT I.ID, I.STATUS, A.REMINDERINFORMATION
FROM IE802 I JOIN IE802_ATTRIBUTES A ON A.IE802_ID=I.ID;
Each row which is generated from the code above additionally must have DOCID
PrimaryKey. How can I add 开发者_如何学Pythonthis column and make it autoincrement and PK at the same time?
Thanks for any tips and other solutions!
Alternatively, how can I make existing I.ID to be PK?
I'm still getting an error: Column "ID" must not be nullable; SQL statement: ALTER TABLE DOC ADD PRIMARY KEY (ID) [90023-147]
H2 supports column definitions in CREATE AS SELECT:
CREATE TABLE DOC(
ID INT PRIMARY KEY,
STATUS INT,
REMINDERINFORMATION VARCHAR(255)
)
AS SELECT I.ID, I.STATUS, A.REMINDERINFORMATION
FROM IE802 I JOIN IE802_ATTRIBUTES A ON A.IE802_ID=I.ID;
精彩评论