I’m a Java student and I was trying to create a table for my database web app project.
CREATE TABLE customer ( customer_id int IDENTITY(1,1) PRIMARY KEY, first_name varchar(45), last_name varchar(45), email varchar(45), );
So I used IDENTITY(1,1) to get the id start from 1 and auto increment by 1. But IDENTITY is underlined and I do not know why. Also when I try to run the code I get this Output :
Error starting at line : 1 in command - CREATE TABLE customer ( customer_id int IDENTITY(1,1), first_name varchar(45), last_name varchar(45), email varchar(45), ) Error report - ORA-00907: missing right parenthesis 00907. 00000 - "missing right parenthesis" *Cause: *Action:
Advertisement
Answer
You have multiple syntax errors. But the code you want is:
CREATE TABLE customers (
customer_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
first_name varchar2(45),
last_name varchar2(45),
email varchar2(45)
);
Notes:
- The syntax in Oracle is different from SQL Server. There are no arguments to
IDENTITYand you wantGENERATED ALWAYS ASfor the column. - Oracle prefers
VARCHAR2()toVARCHAR(). - You have missing and extra commas.
- 45 characters seems too short for the columns, particularly the email.
- I prefer table names in the plural because they contain multiple copies of an entity.