Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alter table add column syntax in SQL

Tags:

sql

postgresql

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

like image 742
lakshmi Avatar asked Aug 10 '10 11:08

lakshmi


People also ask

How do I add a column to an ALTER TABLE in SQL?

The basic syntax of an ALTER TABLE command to add a New Column in an existing table is as follows. ALTER TABLE table_name ADD column_name datatype; The basic syntax of an ALTER TABLE command to DROP COLUMN in an existing table is as follows.

What is the syntax for ADD column in SQL?

The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.

What is ALTER TABLE add?

ALTER TABLE changes the structure of a table. For example, you can add or delete columns, create or destroy indexes, change the type of existing columns, or rename columns or the table itself. You can also change characteristics such as the storage engine used for the table or the table comment.


1 Answers

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
like image 76
Martin Smith Avatar answered Nov 15 '22 08:11

Martin Smith