不使用保留字的 table 名称无效?
Invalid table name without using a reserved word?
我正在使用 Oracle SQL 创建一个 table,当我尝试创建一个名为 'Card' 的 table 时,我一直收到错误消息,它是一个无效的 table名字。这是我的代码:
CREATE TABLE Card
(
CardNumber varchar2(20) Not Null,
CardType varchar2(5) Not Null,
CONSTRAINT CustomerIDForeignKey FOREIGN KEY (CustomerID) REFERENCES (Customer),
CONSTRAINT CardTypeConstraint CHECK (CardType='Credit' or CardType='Debit' or CardType='Gift')
)
这是我收到的错误代码:
Error starting at line : 1 in command -
CREATE TABLE Card
(
CardNumber varchar2(20) Not Null,
CardType varchar2(5) Not Null,
CONSTRAINT CustomerIDForeignKey FOREIGN KEY (CustomerID) REFERENCES (Customer),
CONSTRAINT CardTypeConstraint CHECK (CardType='Credit' or CardType='Debit' or CardType='Gift')
)
Error report -
SQL Error: ORA-00903: invalid table name
00903. 00000 - "invalid table name"
*Cause:
*Action:
如有任何帮助,我们将不胜感激!我没有在 list of Oracle SQL's reserved words 上找到 'Card',所以我不确定是什么问题。谢谢!
您需要将列 CustomerId
添加到 Card
table 并将引用更改为 table_name(column_name)
:
CREATE TABLE Customer(CustomerID INT PRIMARY KEY);
CREATE TABLE Card(
CardNumber varchar2(20) Not Null,
CardType varchar2(5) Not Null,
CustomerId INT NOT NULL,
CONSTRAINT CustomerIDForeignKey FOREIGN KEY (CustomerID) REFERENCES Customer(CustomerId),
CONSTRAINT CardTypeConstraint CHECK (CardType IN ('Credit', 'Debit' ,'Gift'))
);
你也可以替换:
CHECK (CardType='Credit' or CardType='Debit' or CardType='Gift')
与:
CHECK (CardType IN ('Credit', 'Debit' ,'Gift'))
你可以考虑:
- 正在将主键添加到卡片 table
- Hashing/encrypting卡号(不存储为明文)
- 正在创建 CreditCardType 字典 table
我正在使用 Oracle SQL 创建一个 table,当我尝试创建一个名为 'Card' 的 table 时,我一直收到错误消息,它是一个无效的 table名字。这是我的代码:
CREATE TABLE Card
(
CardNumber varchar2(20) Not Null,
CardType varchar2(5) Not Null,
CONSTRAINT CustomerIDForeignKey FOREIGN KEY (CustomerID) REFERENCES (Customer),
CONSTRAINT CardTypeConstraint CHECK (CardType='Credit' or CardType='Debit' or CardType='Gift')
)
这是我收到的错误代码:
Error starting at line : 1 in command - CREATE TABLE Card ( CardNumber varchar2(20) Not Null, CardType varchar2(5) Not Null, CONSTRAINT CustomerIDForeignKey FOREIGN KEY (CustomerID) REFERENCES (Customer), CONSTRAINT CardTypeConstraint CHECK (CardType='Credit' or CardType='Debit' or CardType='Gift') )
Error report - SQL Error: ORA-00903: invalid table name 00903. 00000 - "invalid table name" *Cause:
*Action:
如有任何帮助,我们将不胜感激!我没有在 list of Oracle SQL's reserved words 上找到 'Card',所以我不确定是什么问题。谢谢!
您需要将列 CustomerId
添加到 Card
table 并将引用更改为 table_name(column_name)
:
CREATE TABLE Customer(CustomerID INT PRIMARY KEY);
CREATE TABLE Card(
CardNumber varchar2(20) Not Null,
CardType varchar2(5) Not Null,
CustomerId INT NOT NULL,
CONSTRAINT CustomerIDForeignKey FOREIGN KEY (CustomerID) REFERENCES Customer(CustomerId),
CONSTRAINT CardTypeConstraint CHECK (CardType IN ('Credit', 'Debit' ,'Gift'))
);
你也可以替换:
CHECK (CardType='Credit' or CardType='Debit' or CardType='Gift')
与:
CHECK (CardType IN ('Credit', 'Debit' ,'Gift'))
你可以考虑:
- 正在将主键添加到卡片 table
- Hashing/encrypting卡号(不存储为明文)
- 正在创建 CreditCardType 字典 table