Subject Re: Firebird SQL - Alter table command (does it work?) - BUG?
Author rrokytskyy
--- In Firebird-Java@y..., Sanjay Amatya <sanjayamatya@y...> wrote:
> Create a database test.gdb. Create a table test with fields
> objectid (Integer), userid (Integer), name (Varchar). Then try to
> add primary key constraint to the first 2 fields:
>
> ALTER TABLE TEST ADD CONSTRAINT PRIMARY KEY PK_TEST
> (OBJECTID, USERINSTID);
>
> Doesn't work. Is this a bug of Firebird SQL?

No, syntax is:

ALTER TABLE <table_name> ADD CONSTRAINT <constraint_name> PRIMARY KEY
(<col_name>[, <col_name>[,...]]);

Note, only columns with NOT NULL constraint are eligible for primary
or unique key.

> I had a script that creates a number of tables then adds primary
> key to fields. The script worked fine. Created tables. But no
> constraints added to table.
>
> BUG?

Yes, in script. For such situations I would recommend you to use
Language Reference, that is available for download
(http://www.ibphoenix.com/downloads/60LangRef.zip) from
http://www.ibphoenix.com/ibp_download.html.

Best regards,
Roman Rokytskyy