All Forums UDA
Witarsa 2 posts Joined 03/06
29 Mar 2006
Primary Key - Create table (select)

Is it possible to set a PRIMARY KEY when I'm creating a table from a select statement?Ex.:CREATE TABLE TESTAS (SELECT VAR1, VAR2, VAR3 FROM TABLE) WITH DATA;Where VAR1 should be the PRIMARY KEY.Tks,Marc

Barry-1604 176 posts Joined 07/05
31 Mar 2006

I don't believe that the syntax allows that, since the PRIMARY KEY specification is done along with specifying the columns of the table. You can specify a UNIQUE PRIMARY INDEX though by doing this:CREATE TABLE TESTAS (SELECT VAR1, VAR2, VAR3FROM TABLE) WITH DATAUNIQUE PRIMARY INDEX(VAR1);Hope that helps.Barry

nattyait 1 post Joined 08/09
03 Aug 2009

Please use command belowCREATE TABLE [newtable] LIKE [oldtable]it will automatically create table with the same primary key as the old table.

You must sign in to leave a comment.