0 oracle default-value alter-table
我是甲骨文新手。我需要将 SQL Server 命令移植到 Oracle。
我想更改列以添加具有默认值的新约束。
ALTER TABLE <schema_name>.<table_name>
ADD CONSTRAINT [<constraint_name>]
DEFAULT (1) FOR [<column_name>]
Run Code Online (Sandbox Code Playgroud)
ALTER TABLE <table_name>
ADD CONSTRAINT <constraint_name>
DEFAULT (1) FOR <column_name>
Run Code Online (Sandbox Code Playgroud)
运行 Oracle 查询时出现以下错误:
Run Code Online (Sandbox Code Playgroud)Error report - SQL Error: ORA-00904: : invalid identifier 00904. 00000 - "%s: invalid identifier" *Cause: *Action:
可能是因为FOR标识符无效?
但是如何为特定列添加具有默认值的约束呢?
我们是否需要更改列并设置默认值?
哪种方法是正确的?
默认值不是 Oracle 中的约束。您只需将列更改为:
SQL> create table tab1 (col1 number, col2 number);
Table created.
SQL> alter table tab1 modify (col2 default 1);
Table altered.
SQL> select * from user_constraints;
no rows selected
SQL> insert into tab1 (col1) values (0);
1 row created.
SQL> select * from tab1;
COL1 COL2
---------- ----------
0 1
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17936 次 |
| 最近记录: |