SQL Create table missing parenthesis [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 8 years ago.
Improve this question
I am running these two commands to create new tables, but the second create table command keeps giving me error.
CREATE TABLE TEAMSTADIUM(
stadium_name varchar2(40) not null,
stadium_max_capcity number(10) not null,
stadium_field_serface varchar2(40) not null,
stadium_year_built number(4) not null,
stadium_location varchar2(40) not null,
Primary KEY(stadium_name)
)
CREATE TABLE TEAMINFO(
team_name varchar2(40) not null,
team_owner varchar2(40) not null,
team_coach varchar2(40) not null,
team_created Date() not null,
PRIMARY KEY(team_name)
foreign key(stadium_name) references TEAMSTADIUM(stadium_name)
)

Your TEAMINFO table references TEAMSTADIUM.stadium_name, but has no such column of its own. Add it, and ensure it has exactly the same data type as the parent table:
CREATE TABLE TEAMINFO(
team_name varchar2(40) not null,
team_owner varchar2(40) not null,
team_coach varchar2(40) not null,
team_created Date not null,
-- Remove () ^^
-- This column must exist in both tables
stadium_name varchar2(40) not null,
PRIMARY KEY(team_name),
-- missing comma ^^
foreign key(stadium_name) references TEAMSTADIUM(stadium_name)
)
After applying the three modifications above, it will execute correctly: http://sqlfiddle.com/#!4/883a4

Try using Date not null; and put ; after each ) of end table
CREATE TABLE TEAMINFO(
stadium_name varchar2(40) not null,
team_name varchar2(40) not null,
team_owner varchar2(40) not null,
team_coach varchar2(40) not null,
team_created Date not null,
PRIMARY KEY(team_name),
foreign key(stadium_name) references TEAMSTADIUM(stadium_name)
);

Related

ORA-00907: missing right parenthesis .. when i don't have any missing parenthesis or spelling mistakes [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
When I run this SQL it gives me this error and I can't figure it out
CREATE TABLE PAYMENT (
Payment_ID int(16) not null,
Amount_paid varchar2(30) not null,
Payment_ReceivedBy varchar(30) not null,
Payment_ReceivedFrom varchar(30) not null,
Payment_Date datetime not null,
Card_Number varchar2(20) not null,
Card_Holder_Name varchar2(30) not null,
Is_CreditCard number(20) ,
Is_DebitCard number(20),
Online_Payment varchar(10),
CashOnDelivery varchar(10),
CONSTRAINT PaymentID_PK PRIMARY KEY (Payment_ID)
);
error:
ORA-00907: missing right parenthesis
The error message isn't great, and the issue in fact isn't really about parenthesis - it's about datatypes. Oracle doesn't have int and datetime types. Instead, you could use number(16) and date:
CREATE TABLE PAYMENT (
Payment_ID number(16) not null, -- Here
Amount_paid varchar2(30) not null,
Payment_ReceivedBy varchar(30) not null,
Payment_ReceivedFrom varchar(30) not null,
Payment_Date date not null, -- And here
Card_Number varchar2(20) not null,
Card_Holder_Name varchar2(30) not null,
Is_CreditCard number(20) ,
Is_DebitCard number(20),
Online_Payment varchar(10),
CashOnDelivery varchar(10),
CONSTRAINT PaymentID_PK PRIMARY KEY (Payment_ID)
);

update field with special conditions [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
How to update the password for username (of type Admin) with next condition: first 3 letters of his name, 2 last letters of the last name and 4 last digits of his phone
create table company
(
CODE_COMPANY char(30),
NAME_COMPANY varchar2(30) not null,
MAIL_COMPANY varchar2(30) null,
constraint PK_CODE_COMPANY primary key (CODE_COMPANY),
);
create table USERNAME
(
NAME_USERNAME varchar2(30),
USER_LOCATION number,
fNAME varchar2 (30) not null,
lNAME varchar2 (30) not null,
PHONE_USER char(13) null,
PASSWORD varchar2(30) not null,
USER_POSITION varchar2 (30),
check (USER_POSITION in('Admin', 'Superadmin', 'Technician', 'Student')),
constraint PK_NAME_USERNAME primary key (NAME_USERNAME),
constraint FK_USER_LOCATION foreign key (USER_LOCATION) references uLOCATION (LOCATION)
);
create table uLOCATION
(
LOCATION number,
CODE_COMPANY char(30),
NAME_LOCATION varchar2(30) not null,
FLOOR_LOCATION varchar2(10),
check (FLOOR_LOCATION in ('MAIN_FLOOR', '1ST FLOOR', '2ND FLOOR', '3RD FLOOR')),
constraint PK_LOCATION primary key (LOCATION),
constraint FK_CODE_COMPANY_L foreign key (CODE_COMPANY) references company (CODE_COMPANY),
);
Oracle concat function accepts only two parameters, so there must be two nested concats to join 3 strings together.
update username set password =
concat(
concat(
substr(fname,1,3),
substr(lname, length(lname) - 1)
),
substr(phone_user, length(phone_user) - 3)
)
where user_position = 'Admin';
These links explain how substr() works with length()
https://www.techonthenet.com/oracle/functions/substr.php
https://www.w3resource.com/oracle/character-functions/oracle-length-function.php

Getting an error that I'm missing a right paren when I am not [duplicate]

This question already has answers here:
Missing right Paranthesis on Create Table command SQL
(2 answers)
Closed 3 years ago.
I'm getting an error when creating two tables that I'm missing a right paren on the second table although I am not.
I've tried different oracle variations of this code and I'm still getting the error.
(ORACLE LIVE SQL)
CREATE TABLE PET_OWNER
(OwnerID Integer Primary Key,
OwnerLastName Char(25) Not Null,
OwnerFirstName Char(25) Not Null,
OwnerPhone Char(25) Null,
OwnerEmail Char(50) Not Null);
CREATE TABLE PET_DATA
(PetID Integer Not Null,
PetName Char(50) Not Null,
PetType Char(25) Not Null,
PetBreed Char(50) Not Null,
PetDOB Varchar(50) Not Null,
Primary Key (PetID)
Constraint FK_PetOwner Foreign Key (OwnerID)
References Owner(OwnerID));
I expect the tables to be created but only the first table is being created successfully. The second table has a foreign key.
It looks like you are missing a comma after the primary-key definition on the second table.
The Oracle parser often complains about missing closing parentheses when the real issue is some other syntax error.
I would recommend:
CREATE TABLE PET_OWNER (
OwnerID Integer Primary Key,
OwnerLastName varchar2(25) Not Null,
OwnerFirstName varchar2(25) Not Null,
OwnerPhone varchar2(25) Null,
OwnerEmail varchar2(50) Not Null
);
CREATE TABLE PET_DATA (
PetID Integer Not Null,
OwnerID Integer,
PetName varchar2(50) Not Null,
PetType varchar2(25) Not Null,
PetBreed varchar2(50) Not Null,
PetDOB varchar2(50) Not Null,
Primary Key (PetID),
Constraint FK_PetOwner Foreign Key (OwnerID) References Pet_Owner(OwnerID)
);
This fixes small problems (missing OwnerId column in the second table, wrong table name). It also uses varchar2() for variable length strings rather than char() -- which are padded with spaces to the specified length.

ORA-00902: invalid datatype trying to define a column with a unique constraint [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I created the following table definition in netbeans ide 8.
CREATE TABLE DOCTOR_INFO(
DOCTOR_ID NUMBER(38) NOT NULL CONSTRAINT DOCTORINFO_ID_UQ UNIQUE,
D_F_NAME VARCHAR(50) NOT NULL,
D_M_NAME VARCHAR(50) NOT NULL,
D_S_NAME VARCHAR(50) NOT NULL,
DOCTOR_NAME VARCHAR(50),
D_TITLE VARCHAR(10) NOT NULL,
D_ACTIVE_STATUS BOOLEAN NOT NULL,
SUFFIX VARCHAR(10) NOT NULL,
PASSWORD VARCHAR(50) NOT NULL,
SPECIALITY VARCHAR(35) NOT NULL,
QUALIFICATION_YEAR NUMBER(4) NOT NULL,
UNIVERSITY_NAME VARCHAR(35) NOT NULL,
HOSPITAL_NAME VARCHAR(35) NOT NULL,
D_ADDR1 VARCHAR(50),
D_ADDR2 VARCHAR(50),
USER_EMAIL_ADDRESS VARCHAR(255) NOT NULL,
D_CITY VARCHAR(50) NOT NULL,
D_STATE VARCHAR(50),
D_ZIPCODE NUMBER(6) NOT NULL,
D_HOMEPHONE NUMBER(15) NOT NULL,
D_WORKPHONE NUMBER(15) NOT NULL,
D_MOBILE NUMBER(15) NOT NULL,
START_DAYTIME TIMESTAMP,
END_DAYTIME TIMESTAMP,
START_NIGHTTIME TIMESTAMP,
END_NIGHTTIME TIMESTAMP,
D_TOKENLIMIT NUMBER(4),
D_DOB DATE NOT NULL
);
When I try to run it in Oracle 10g, I get this error:
Error code 902, SQL state 42000: ORA-00902: invalid datatype
Line 1, column 1
What is wrong with the table definition?
Your definition for column DOCTOR_ID does not conform to Oracle SQL syntax. You cannot append a named constraint to a column declaration as you attempt to do. You may do this ...
DOCTOR_ID NUMBER(38) NOT NULL,
CONSTRAINT DOCTORINFO_ID_UQ UNIQUE (DOCTOR_ID),
... to achieve the effect you seem to want. If you don't care about the specific constraint name, however, then you can also do this:
DOCTOR_ID NUMBER(38) NOT NULL UNIQUE,

#1215 SQL Cannot add foreign key constraint error [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Here is my code. I can't figure out why I can't add the constraint.
Create table customer(
UserId Integer
)
CREATE TABLE Date(
DateID INTEGER,
User1ID INTEGER NOT NULL,
User2ID INTEGER NOT NULL,
Date CHAR(20) NOT NULL,
GeoLocation CHAR(20) NOT NULL,
BookingFee INTEGER NOT NULL,
CustomerRepresentative CHAR(20) NOT NULL,
Comments CHAR(200),
User1Ratings CHAR(20),
User2Ratings CHAR(20),
Primary Key (DateID),
Check ( User1Ratings IN (‘Excellent’, ‘VeryGood’, ‘Good’, ‘Fair’, ‘Poor’) ),
Check ( User2Ratings IN (‘Excellent’, ‘VeryGood’, ‘Good’, ‘Fair’, ‘Poor’) ),
FOREIGN KEY (User1ID) REFERENCES customer(UserID)
)
The most likely explanation for the behavior is that UserID column is not defined as the PRIMARY KEY or a UNIQUE KEY in the customer table
One fix for this would be to re-write the create for the customer table
For SQL Server:
CREATE TABLE customer
( UserId Integer NOT NULL
, CONSTRAINT PK_customer PRIMARY KEY CLUSTERED (UserId)
);
For MySQL:
CREATE TABLE customer
( UserId INTEGER NOT NULL PRIMARY KEY
);