CREATE TABLE students (
Year NUMBER(4) NOT NULL,
Semester VARCHAR2(1) NOT NULL CONSTRAINT stu_sem_ck CHECK (semester IN ('1', '2', '3')),
department VARCHAR2(3) NOT NULL,
course_number NUMBER NOT NULL,
session VARCHAR2(3),
first_name NVARCHAR2(10),
Middle_name NVARCHAR2(15),
last_name NVARCHAR2(15) NOT NULL,
id NUMBER(9) NOT NULL,
area_code VARCHAR2(3),
phone_number VARCHAR2(7),
email_address NVARCHAR2(60),
Street1 NVARCHAR2(20),
street2 NVARCHAR2(20),
city NVARCHAR2(20),
State_prov NVARCHAR2(20),
country CHAR(2),
postal_code NVARCHAR2(15),
language CHAR(2),
CONSTRAINT student_pk PRIMARY KEY (id))
在 SQL 开发者上运行时,它给我以下错误
Error starting at line 2 in command:
CREATE TABLE students (
Year NUMBER(4) NOT NULL,
Semester VARCHAR2(1) NOT NULL CONSTRAINT stu_sem_ck CHECK (semester IN ('1', '2', '3')),
department VARCHAR2(3) NOT NULL,
course_number NUMBER NOT NULL,
session VARCHAR2(3),
first_name NVARCHAR2(10),
Middle_name NVARCHAR2(15),
last_name NVARCHAR2(15) NOT NULL,
id NUMBER(9) NOT NULL,
area_code VARCHAR2(3),
phone_number VARCHAR2(7),
email_address NVARCHAR2(60),
Street1 NVARCHAR2(20),
street2 NVARCHAR2(20),
city NVARCHAR2(20),
State_prov NVARCHAR2(20),
country CHAR(2),
postal_code NVARCHAR2(15),
language CHAR(2),
CONSTRAINT student_pk PRIMARY KEY (id))
Error at Command Line:6 Column:1
Error report:
SQL Error: ORA-00904: : invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error starting at line 1 in command:
CREATE TABLE students (
SESSION
是Oracle保留字,不允许重新定义保留字的含义。
重命名您的列
session
非保留字的名称。你应该没事吧!
参考 - http://docs.oracle.com/cd/B10501_01/appdev.920/a42525/apb.htm
SESSION是Oracle中的保留关键字。但如果您想将其用作列名,请使用双引号。因此改变
session VARCHAR2(3),
到
"session" VARCHAR2(3),
否则只需重命名该列即可。
这里是SQLFiddle
1-创建学生表,其中包含 id(pk)、名字、姓氏、地址、城市、国家/地区 2-添加列电话 3-删除列国家 4-删除表学生