About SQL table [closed] - sql

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
Error report:
ORA-00906: missing left parenthesis
00906. 00000 - "missing left parenthesis"
*Cause:
*Action:
I am getting this error and I tried a lot to solve this but it could not work please help me with this error so I can complete my project
This is my code:
create table Customers1
(
cust_id number(20) NOT NULL UNIQUE,
cust_name varchar(25) NOT NULL,
cust_address varchar(35),
cmp_id number (22),
constraint Customers1_cust_id_pk
primary key (cust_id),
constraint Customers1_cmp_id_fk
foreign key cmp_id References Company (cmp_id)
);

Put brackets around the columns in the foreign key constraint and you also do not need both a UNIQUE and PRIMARY KEY constraint on the same column:
create table Customers1(
cust_id number(20) NOT NULL,
cust_name varchar(25) NOT NULL,
cust_address varchar(35),
cmp_id number (22),
constraint Customers1_cust_id_pk
primary key (cust_id),
constraint Customers1_cmp_id_fk
foreign key (cmp_id) References Company (cmp_id)
);

Related

ORA-00904: : invalid identifier in Oracle Life database [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Even i run this as script, i got error. first i didnt use 'wrent_id' and still got error.
CREATE TABLE want_renting (
'wrent_id' int NOT NULL PRIMARY KEY,
'property_id' int,
'client_id' int,
'agent_id' int,
'wrent_date' date,
'expired_date' date,
CONSTRAINT 'fk_property' FOREIGN KEY ('property_id') REFERENCES 'property'('property_id'),
CONSTRAINT 'fk_client' FOREIGN KEY ('client_id') REFERENCES 'clients'('client_id'),
CONSTRAINT 'fk_agent' FOREIGN KEY ('agent_id') REFERENCES 'agents'('agent_id'),
);
ORA-00904: : invalid identifier
Remove quotes from your query. Quotes is used to define a string and not during table creation.
CREATE TABLE want_renting (
wrent_id int NOT NULL PRIMARY KEY,
property_id int,
client_id int,
agent_id int,
wrent_date date,
expired_date date,
CONSTRAINT fk_property FOREIGN KEY (property_id) REFERENCES
property(property_id),
CONSTRAINT fk_client FOREIGN KEY (client_id) REFERENCES clients(client_id),
CONSTRAINT fk_agent FOREIGN KEY (agent_id) REFERENCES agents(agent_id)
);
And make sure you have all other tables referencing the foreign keys.

SQL Error: Invalid table name [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am trying to create table (orders) with some foreign keys by using this query statement,
CREATE TABLE orders
)
order_id VARCHAR2(20),
item_id VARCHAR2(30) CONSTRAINT item_id_not_null NOT NULL,
quantity_id VARCHAR2(30) CONSTRAINT quantity_id_not_null NOT NULL,
customer_id VARCHAR2(30) CONSTRAINT mobile_no_not_null NOT NULL,
CONSTRAINT order_pk PRIMARY KEY(order_id),
CONSTRAINT fk_customer FOREIGN KEY (customer_Id) REFERENCES ORDER(customer_Id),
CONSTRAINT fk_item FOREIGN KEY (item_Id) REFERENCES ORDER(item_Id),
CONSTRAINT fk_quantity FOREIGN KEY (quantity_Id) REFERENCES ORDER(quantity_Id)
);
I get the following back,
SQL Error: ORA-00903: invalid table name
00903. 00000 - "invalid table name"
There is a typo in the FK definitions. The table should be ORDERS and not ORDER, which is a reserved keyword.

Tables not creating? Syntax issue? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I am currently doing a lab for school and cannot for the life of me figure out why I am getting these errors (2 in particular). The first error thrown to me is that in the table "invoice" the PRIMARY KEY constraint is asking for a second right parentheses. The second error I'm receiving is in the creation of table "invprod" where it is arguing to me that "invno" doesn't actually exist.
I don't know if this is an error in my syntax or otherwise but any help is greatly appreciated.
CREATE TABLE invoice
(invno CHAR(5) NOT NULL
,invdate DATE
,orderno CHAR(5) NOT NULL
,CONSTRAINT invorder FOREIGN KEY (orderno)
REFERENCES salesorder(orderno)
,CONSRAINT pkinvoice PRIMARY KEY (invno)
);
CREATE TABLE invprod
(invno CHAR(5) NOT NULL
,partno CHAR(4) NOT NULL
,shipqty INTEGER CHECK (shipqty>0)
,CONSTRAINT fk1invprod FOREIGN KEY(invno)
REFERENCES invoice(invno)
,CONSTRAINT fk2invprod FOREIGN KEY(partno)
REFERENCES part(partno)
);
You have typo CONSRAINT should be CONSTRAINT:
CREATE TABLE invoice
(
invno CHAR(5) NOT NULL
,invdate DATE
,orderno CHAR(5) NOT NULL
,CONSTRAINT invorder FOREIGN KEY (orderno)
REFERENCES salesorder(orderno)
,CONSTRAINT pkinvoice PRIMARY KEY (invno)
);
SqlFiddleDemo

SQL Error: ORA-00904: "MEBERSHIPID": invalid identifier [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am creating a table whereI'm currently trying to add multiple foreign keys in Oracle
The table scripts is as follows
Create table Member
(
memeberID int Not null Primary Key,
membershipID int Not null,
group_id int not NULL,
Dutycode int not null,
MemberRole varchar(255),
name varchar(255),
last_joined date,
DOB date,
address varchar(255),
CONSTRAINT fk_DutCode FOREIGN KEY (Dutycode)
REFERENCES RaceManagementDuty(Dutycode),
CONSTRAINT fk_GrMemeber FOREIGN KEY (group_id)
REFERENCES Group_member(group_id),
CONSTRAINT fk_Meberships FOREIGN KEY (mebershipID)
REFERENCES Membership(mebershipID)
)
Wandering where I'm going wrong?
Its just a typo error . Change mebershipID to membershipID
CONSTRAINT fk_Meberships FOREIGN KEY (membershipID)
REFERENCES Membership(membershipID)
There is no column mebershipID in table and so throws error

name already used by an existing constraint [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
Create Table Resources_user
(
Resources_userID INTEGER NOT NULL,
Resources_ID INTEGER NOT NULL,
User_ID INTEGER NOT NULL,
Data Accessed DATE,
CONSTRAINT PK_Resources_user PRIMARY KEY (Resources_userID),
constraint fk_Resources_user1 Foreign key (Resources_ID ) references Resources,
constraint fk_Resources_user2 Foreign key (User_ID) references User1);
Create table Staff_Position
(
Staff_Position_ID INTEGER NOT NULL,
Position_ID INTEGER NOT NULL,
User_ID INTEGER NOT NULL,
CONSTRAINT PK_Staff_Position PRIMARY KEY (Staff_Position_ID),
Constraint fk_Staff_Position1 foreign key (Position_ID) references position,
Constraint fk_Staff_Position2 foreign key (User_ID) references User1);
Thank you the problem been solved, I realized that i need to number my foreign keys for avoiding the error of repeating .
Your foreign key constraints are incomplete. You did not specify a field. This:
, constraint fk_Resources_user Foreign key (Resources_ID ) references Resources
should be something like this:
, constraint fk_Resources_user Foreign key (Resources_ID )
references Resources (resources_id)
Some Oracle error messages are misleading. This is one of them.
Edit Starts Here
You also have duplicate constraint names for your foreign keys. You will likely get a message indicating such once the other problems are resolved.