tags:

views:

68

answers:

2

I'm trying to alter the table named company, but it will display the error

syntax error at or near "("
LINE 2: ADD( company_access_level short NOT NULL,

My syntax is

ALTER TABLE company
ADD company_access_level short NOT NULL,
workgroup_level short NOT NULL,
Company Logon URL character varying NOT NULL,
Company Logoff URL character varying NOT NULL

Thanks

+2  A: 

Also, if your table has data in it then you can't add NOT NULL columns (and for some RDBMSs you can't add NOT NULL columns even when there is no data present in the table).

Either provide a default value or allow the column to be NULLable. You can always populate the new columns with data and modify the columns to be NOT NULL afterwards.

John Pickup
+2  A: 

I just tried this fixed syntax in postgressql and it worked. There is no short datatype though so you'll have to use something else (maybe smallint?) If your table contains data this script will fail for the reasons in John's answer.

ALTER TABLE company
ADD company_access_level int NOT NULL,
ADD workgroup_level int NOT NULL,
ADD "Company Logon URL" character varying NOT NULL,
ADD "Company Logoff URL" character varying NOT NULL
Martin Smith