00905. 00000 - "missing keyword" - sql

I'm new to SQL and I'm stuck with creating the table
CREATE TABLE Recording(
recordingID int not null,
title varchar(255) not null,
nameRec varchar(255) not null,
price DOUBLE not null,
quantityStock int not null,
musicID int not null,
StockDiscNum int not null,
orderNums int not null,
FOREIGN KEY(orderNums) REFERENCES Orders (orderNumber),
PRIMARY KEY(recordingID)
);
I checked every type but not sure why it say missing keyword
Thank you
What is the exact issue and the exact way to create table in SQL

There's no DOUBLE datatype in Oracle; use NUMBER instead. Also, Oracle recommends us to use varchar2 instead of varchar.
SQL> CREATE TABLE Recording
2 (
3 recordingID INT NOT NULL,
4 title VARCHAR2 (255) NOT NULL,
5 nameRec VARCHAR2 (255) NOT NULL,
6 price NUMBER NOT NULL,
7 quantityStock INT NOT NULL,
8 musicID INT NOT NULL,
9 StockDiscNum INT NOT NULL,
10 orderNums INT NOT NULL,
11 FOREIGN KEY (orderNums) REFERENCES Orders (orderNumber),
12 PRIMARY KEY (recordingID)
13 );
Table created.
SQL>

Related

SQL CREATE TABLE missing left parentheses error

CREATE TABLE residents
(
R_ID NUMBER(4), CONSTRAINTS pk_residents_R_ID PRIMARY KEY,
R_FN VARCHAR2(15), NOT NULL,
R_LN VARCHAR2(15), NOT NULL,
R_Contact NUMBER(10), NOT NULL,
DoB DATE, NOT NULL
);
Tried a few changes but I'm unable to resolve this error. Any help would be appreciated!
It works for Oracle in this way:
CREATE TABLE residents(
R_ID NUMBER(4),
R_FN VARCHAR2(15) NOT NULL,
R_LN VARCHAR2(15) NOT NULL,
R_Contact NUMBER(10) NOT NULL,
DoB DATE NOT NULL,
pk_residents_R_ID NUMBER(4) PRIMARY KEY
);
Code which is the closest to your attempt is:
SQL> CREATE TABLE residents
2 (
3 r_id NUMBER (4) CONSTRAINT pk_residents_r_id PRIMARY KEY,
4 r_fn VARCHAR2 (15) NOT NULL,
5 r_ln VARCHAR2 (15) NOT NULL,
6 r_contact NUMBER (10) NOT NULL,
7 dob DATE NOT NULL
8 );
Table created.
SQL>
keyword is constraint, not constraintS
don't separate NOT NULL (or any other constraint) from its column with a comma
Also, using mixed letter case is irrelevant as Oracle - by default - stores object names in UPPERCASE. That's so unless you decide to enclose names into double quotes, but then you'll always have to use double quotes and exactly match letter case so - that's not what anyone should do, not in Oracle.

I am creating a table in pgweb Heroku, and get this error "ERROR: pq: syntax error at or near "(""

Here is my exact query
CREATE Table Publisher
(Publisher_Id Int primary key not null,
Name varchar(20) not null,
Address varchar(50) not null,
Phone Int(10),
Isbn varchar(13) references books (Isbn) not null
)
Any help would be greatly appreciated.
datatype int does not take a length. So:
create table publisher (
publisher_id int primary key,
name varchar(20) not null,
address varchar(50) not null,
phone int,
isbn varchar(13) references books (isbn) not null
);
Notes:
not null is redondant on a primary key column
int does not seem like a good pick for a phone number; you would typically need to store leading 0s, or allow special characters such as + or () - int cannot do that. A string datatype would probably be a better pick

oracle - Alter table doesn't work [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I find this mysql code and when i past it to oracle sql developer the alter table command show me an error when i'v tried to execute it.
this is my table:
CREATE TABLE article (
code varchar(20) NOT NULL,
designation varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
num_serie int(50) NOT NULL,
num_reference int(50) NOT NULL,
num_inventaire int(50) NOT NULL,
tva double NOT NULL,
famille varchar(50) NOT NULL,
sous_famille varchar(50) NOT NULL
) ;
and this is the alter table command :
ALTER TABLE article
ADD PRIMARY KEY (code),
ADD KEY code (code),
ADD KEY code_2 (code);
this is the error message:
Rapport d'erreur - ORA-01735: option ALTER TABLE non
valide
01735. 00000 - "invalid ALTER TABLE option"
*Cause:
*Action:
Such a CREATE TABLE won't work in Oracle (at least, 11gR2). Therefore, I rearranged it a little bit (please, compare column by column yourself to see differences). Primary key constraint can be created inline (as I did), at the end of the columns' list (2nd example) or separately, using the ALTER TABLE (3rd example).
Note that you don't have to specify NOT NULL for primary key column(s); Oracle will enforce it itself.
SQL> CREATE TABLE article (
2 code varchar2(20) constraint pk_art primary key,
3 designation varchar2(100) NOT NULL,
4 num_serie int NOT NULL,
5 num_reference int NOT NULL,
6 num_inventaire int NOT NULL,
7 tva number NOT NULL,
8 famille varchar2(50) NOT NULL,
9 sous_famille varchar2(50) NOT NULL
10 );
Table created.
SQL> drop table article;
Table dropped.
SQL> CREATE TABLE article (
2 code varchar2(20),
3 designation varchar2(100) NOT NULL,
4 num_serie int NOT NULL,
5 num_reference int NOT NULL,
6 num_inventaire int NOT NULL,
7 tva number NOT NULL,
8 famille varchar2(50) NOT NULL,
9 sous_famille varchar2(50) NOT NULL,
10 --
11 constraint pk_art primary key (code)
12 );
Table created.
SQL> drop table article;
Table dropped.
SQL> CREATE TABLE article (
2 code varchar2(20),
3 designation varchar2(100) NOT NULL,
4 num_serie int NOT NULL,
5 num_reference int NOT NULL,
6 num_inventaire int NOT NULL,
7 tva number NOT NULL,
8 famille varchar2(50) NOT NULL,
9 sous_famille varchar2(50) NOT NULL
10 );
Table created.
SQL> alter table article add constraint pk_art primary key (code);
Table altered.
SQL>
You appear to be using MySQL syntax with Oracle. I would suggest:
CREATE TABLE articles (
code varchar2(20) NOT NULL PRIMARY KEY,
designation nvarchar2(100) NOT NULL,
num_serie number NOT NULL,
num_reference number NOT NULL,
num_inventaire number NOT NULL,
tva number NOT NULL,
famille varchar2(50) NOT NULL,
sous_famille varchar2(50) NOT NULL
) ;
With code declared as a primary key, there is no reason to create separate indexes on the column.

SQL- Invalid identifier when creating foreign key- SQL Error: ORA-00904

Whenever I run the script I keep getting this error:
Error report - SQL Error: ORA-00904: "HORSE_ID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
I am trying to make a foreign key linking the HORSES and MEDICAL table. I think everything looks correct. Can someone let me know what I have done incorrectly? I am using Oracle SQLDeveloper.
CREATE TABLE HORSES (
Horse_ID varchar(10) NOT NULL Primary Key,
Name varchar(50) NOT NULL,
Height varchar(50) NOT NULL,
Weight varchar(50) NOT NULL,
Breed varchar(50) NOT NULL,
Surrender varchar(50) NOT NULL,
Seize varchar(50) NOT NULL,
Score varchar(15) NOT NULL,
Aq_Date varchar(10) NOT NULL,
Ridable varchar(50) NOT NULL,
Trim varchar(50) NOT NULL,
Age varchar(50) NOT NULL
);
/* MEDICAL */
/* ------------------------------------------------------------ */
CREATE TABLE MEDICAL (
Med_ID varchar(50) NOT NULL primary key,
Feed_Ins varchar(4000) NOT NULL,
Special_Vet varchar(2000) NOT NULL,
Coggins varchar(50) NOT NULL,
Vaccs varchar(50) NOT NULL,
Deworm varchar(50) NOT NULL,
CONSTRAINT Horse_ID_HORSES_FK FOREIGN KEY (Horse_ID) REFERENCES HORSES(Horse_ID)
);
You don't have a horse_id column in medical, how do you want it to be fk for that table?

Missing Right parenthesis error?

I'm trying to create a table in sqldeveloper however I keep getting a missing right parenthesis error when there are no missing right parenthises. Any fixes for this or am i just trying to create a table the wrong way?
CREATE TABLE Patient_T1(
PATIENT_ID INT(100) NOT NULL,
FIRST_NAME VARCHAR(20) NOT NULL,
LAST_NAME VARCHAR(30) NOT NULL,
DOB CHAR(10) NOT NULL,
P_STREET_ADRESS VARCHAR(50) NOT NULL,
PATIENT_CITY VARCHAR(30) NOT NULL,
PATIENT_STATE CHAR(2) NOT NULL,
PATIENT_ZIP CHAR(5) NOT NULL,
PATIENT_PHONE CHAR(12) NOT NULL,
PATIENT_ROOM INT(1000) NOT NULL,
CONSTRAINT PATIENT_PK PRIMARY KEY(PATIENT_ID));
Not sure why Oracle gives that error message instead of something more helpful, but the cause is the precision applied to INT, switch from INT(100) and INT(1000) to just INT:
CREATE TABLE Patient_T1(
PATIENT_ID INT NOT NULL,
FIRST_NAME VARCHAR(20) NOT NULL,
LAST_NAME VARCHAR(30) NOT NULL,
DOB CHAR(10) NOT NULL,
P_STREET_ADRESS VARCHAR(50) NOT NULL,
PATIENT_CITY VARCHAR(30) NOT NULL,
PATIENT_STATE CHAR(2) NOT NULL,
PATIENT_ZIP CHAR(5) NOT NULL,
PATIENT_PHONE CHAR(12) NOT NULL,
PATIENT_ROOM INT NOT NULL,
CONSTRAINT PATIENT_PK PRIMARY KEY(PATIENT_ID));
There are multiple issues with your table DDL:
INT(100) - In Oracle, an INTEGER is an ANSI SQL data type which refers to numeric values which have only an integer portion and no floating point or decimal part. That is, an INTEGER will only store whole numbers ONLY.
VARCHAR(20) - Oracle strongly recommends to use VARCHAR2.
From documentation,
VARCHAR Datatype
The VARCHAR datatype is synonymous with the VARCHAR2 datatype. To
avoid possible changes in behavior, always use the VARCHAR2 datatype
to store variable-length character strings.
CHAR(10) - better use VARCHAR2 as CHAR is blank-padded to the fixed length. That's a wastage of storage.
From documentation,
CHAR Datatype
The CHAR datatype stores fixed-length character strings. If you give a
shorter value, then the value is blank-padded to the fixed length.
Only the issue# 1 would throw an error, anyway fixing all the above issues would let you create the table.
For example,
SQL> CREATE TABLE Patient_T1
2 (
3 PATIENT_ID NUMBER NOT NULL,
4 FIRST_NAME VARCHAR2(20) NOT NULL,
5 LAST_NAME VARCHAR2(30) NOT NULL,
6 DOB DATE NOT NULL,
7 P_STREET_ADRESS VARCHAR2(50) NOT NULL,
8 PATIENT_CITY VARCHAR2(30) NOT NULL,
9 PATIENT_STATE VARCHAR2(2) NOT NULL,
10 PATIENT_ZIP VARCHAR2(5) NOT NULL,
11 PATIENT_PHONE VARCHAR2(12) NOT NULL,
12 PATIENT_ROOM NUMBER NOT NULL,
13 CONSTRAINT PATIENT_PK PRIMARY KEY(PATIENT_ID)
14 );
Table created.