Add a column to a table with check constraint SQL

白昼怎懂夜的黑 提交于 2020-01-06 03:16:06

问题


I want to add a column to a table, then add a check constraint to make sure its greater than 0. I cant seem to get this to run in oracle sl developer.

Alter TABLE store101
add column Base_salary Number(7,2)
constraint store101_Base_salary_ck
check (Base_salary > 0);

Error report - SQL Error: ORA-00904: : invalid identifier 00904. 00000 - "%s: invalid identifier"


回答1:


There is no ADD COLUMN clause in ALTER TABLE syntax. It's just ADD.

ALTER TABLE store101
ADD Base_salary NUMBER(7, 2) -- there is no need to add COLUMN clause
CONSTRAINT store101_Base_salary_ck 
CHECK (Base_salary > 0);

Here is SQLFiddle demo



来源:https://stackoverflow.com/questions/21541366/add-a-column-to-a-table-with-check-constraint-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!