ORA-00907: missing right patenthesis - sql

I just can't see what needs to be changed in this code:
create table tblGirlScout (
GirlScout_ID varchar(10,0) not null,
GirlScoutFirstName varchar(25) not null,
GirlScoutLastName varchar(25),
GirlScoutAddress varchar(30),
GirlScoutCity varchar(20),
GirlScoutState char(2),
GirlScoutPostalCode varchar(9),
Constraint tblGirlScout_PK Primary Key(GirlScout_ID)
);

I believe you wanted to set GirlScout_ID column as a number, not a varchar. This is what causes the problem. Here is a fix
create table tblGirlScout (
GirlScout_ID number(10,0) not null,
GirlScoutFirstName varchar(25) not null,
GirlScoutLastName varchar(25),
GirlScoutAddress varchar(30),
GirlScoutCity varchar(20),
GirlScoutState char(2),
GirlScoutPostalCode varchar(9),
Constraint tblGirlScout_PK Primary Key(GirlScout_ID)
);

Related

Arithmetic overflow error converting expression to data type int, How do I resolve this?

This is the code that created the table.
CREATE TABLE CUSTOMERS
(
Customer_ID INT NOT NULL,
CHECK(Customer_ID <= 11),
First_Name varchar(20) NOT NULL,
Last_Name varchar(30),
Home_Street varchar(30),
Home_City varchar(20),
Home_State varchar(2),
Home_Zip varchar(5),
PhoneNumber varchar(11) NOT NULL
);
ALTER TABLE CUSTOMERS
ADD CONSTRAINT PK_CUSTOMERS PRIMARY KEY(Customer_ID);
Then I try to insert data (using this code) into the table and that is where I get this error.
INSERT INTO dbo.CUSTOMERS(Customer_ID, First_Name, Last_Name, Home_Street, Home_City, Home_State, Home_Zip, PhoneNumber)
VALUES (11223344556, 'John', 'Doe', '1234 Hand Street', 'Wahiawa', 'HI', 96786, 2535551267);
What am I doing wrong and what can I do to fix this issue?
AS per my understanding you are checking length of Customer_ID <=11 so you should mention len(Customer_ID)<=11 it will work and you should alter datatype of Customer_ID int to bigint
CREATE TABLE CUSTOMERS
(
Customer_ID bigINT NOT NULL,
CHECK(len(Customer_ID)<=11),
First_Name varchar(20) NOT NULL,
Last_Name varchar(30),
Home_Street varchar(30),
Home_City varchar(20),
Home_State varchar(2),
Home_Zip varchar(5),
PhoneNumber varchar(11) NOT NULL
);
ALTER TABLE CUSTOMERS
ADD CONSTRAINT PK_CUSTOMERS
PRIMARY KEY(Customer_ID);
INSERT INTO dbo.CUSTOMERS(Customer_ID,First_Name,Last_Name,Home_Street,
Home_City,Home_State,Home_Zip,PhoneNumber)
VALUES(11223344556,'John','Doe','1234 Hand Street',
'Wahiawa','HI',96786,2535551267);
You need customer id to be bigint:
CREATE TABLE CUSTOMERS
(
Customer_ID BIGINT NOT NULL,
CHECK(Customer_ID<=11),
First_Name varchar(20) NOT NULL,
Last_Name varchar(30),
Home_Street varchar(30),
Home_City varchar(20),
Home_State varchar(2),
Home_Zip varchar(5),
PhoneNumber varchar(11) NOT NULL
);
ALTER TABLE CUSTOMERS
ADD CONSTRAINT PK_CUSTOMERS
PRIMARY KEY(Customer_ID);
The problem may be due to CHECK(Customer_ID<=11) since Customer_ID id integer datatype the server may check for integer validation and not length validation. Try to change the validation.

Informix - Cant find syntax error

This may be a stupid mistake but I'm new to Informix and I can't seem to figure out why none of my CREATE TABLE statements won't run. I keep getting a syntax error on all of my CREATE TABLE statements.
CREATE TABLE customer(
store_num INTEGER NOT NULL,
store_name VARCHAR(20) NOT NULL,
addr VARCHAR(20),
addr2 VARCHAR(20),
city VARCHAR(15),
state VARCHAR(2),
zip-code VARCHAR(5),
contact_name VARCHAR(30),
phone VARCHAR(18),
CONSTRAINT cust_pk PRIMARY KEY(store_num)
);
create table orders(
order_num INTEGER NOT NULL,
order_date DATE NOT NULL,
store_num INTEGER NOT NULL,
fac_code CHAR(3),
ship_instr CHAR(10),
promo CHAR(1) NOT NULL,
CONSTRAINT orders_pk PRIMARY KEY(order_num)
);
create table factory(
fac_code CHAR(3) NOT NULL,
fac_name CHAR(15) NOT NULL,
CONSTRAINT fac_pk PRIMARY KEY(fac_code)
);
create table stock(
stock_num INTEGER NOT NULL,
fac_code CHAR(3) NOT NULL,
description CHAR(15) NOT NULL,
reg_price DECIMAL(8,2) NOT NULL,
promo_price DECIMAL(8,2),
price_updated DATE,
unit CHAR(4) NOT NULL,
CONSTRAINT stock_pk PRIMARY KEY(stock_num)
);
create table items(
order_num INTEGER NOT NULL,
stock_num INTEGER NOT NULL,
quantity SMALLINT NOT NULL,
price DECIMAL(8,2) NOT NULL,
CONSTRAINT items_pk PRIMARY KEY(order_num, stock_num)
);
create table state(
state_code CHAR(2) NOT NULL,
state_name CHAR(15) NOT NULL,
CONSTRAINT state_pk PRIMARY KEY(state_code)
);
Any help will be appreciated.
For reasons I don't understand, Informix requires the constraint name after the constraint, whereas standard SQL requires the constraint name before the constraint.
Thus, in addition to changing zip-code to zip_code (as pointed out by daniel.shih in an answer), you need:
CREATE TABLE customer(
store_num INTEGER NOT NULL,
store_name VARCHAR(20) NOT NULL,
addr VARCHAR(20),
addr2 VARCHAR(20),
city VARCHAR(15),
state VARCHAR(2),
zip_code VARCHAR(5),
contact_name VARCHAR(30),
phone VARCHAR(18),
PRIMARY KEY(store_num) CONSTRAINT cust_pk
);
You can try customer's field zip_code instead of zip-code

Oracle Problems with Composite Keys

bit confusing question here:
I am trying to create a composite FK from a composite PK. I'll show you my tables in question that I'm having problems with;
CREATE TABLE Weapons (
Weapon_ID VARCHAR(10) NOT NULL,
Weapon_Name VARCHAR(30),
Range_In_Meters INT,
Maximum_Number_Of_Uses INT,
Damage_Factor INT,
Cost INT,
primary key(Weapon_ID));
CREATE TABLE WeaponInventory (
Inventory_ID VARCHAR(30) NOT NULL,
WeaponInventory_ID Varchar(10) NOT NULL,
Weapon_ID VARCHAR(10) REFERENCES Weapons(Weapon_ID) NOT NULL,
primary key(Inventory_ID, WeaponInventory_ID));
CREATE TABLE Avatars (
Avatar_ID VARCHAR(10) NOT NULL,
Avatar_Name VARCHAR(30),
AvA_DOB DATE,
Age VARCHAR(30),
Gender VARCHAR(30),
Strength_Indicated INT,
Hoard INT,
Avatar_Level VARCHAR(30),
Skill VARCHAR(30),
Original_Owner VARCHAR(30),
Family_ID VARCHAR(10) NOT NULL,
Species_ID VARCHAR(10) NOT NULL,
Inventory_ID VARCHAR(30) NOT NULL,
Weapon_ID VARCHAR(10) NOT NULL,
Player_ID VARCHAR(10) NOT NULL,
PRIMARY KEY (Avatar_ID),
FOREIGN KEY (Inventory_ID, Weapon_ID)
REFERENCES WeaponInventory (Inventory_ID, Weapon_ID));
In the table Avatars, I have been trying to create this Foreign key but I'm having no luck. I have errors such as:
ORA-02270: no matching unique or primary key for this column-list
and:
ORA-02270: no matching unique or primary key for this column-list
Any help would be greatly appreciated! I just keep getting confused and ending up in the same place! (:
I think you planned to reference column WeaponInventory_ID (instead of Weapon_ID) in table WeaponInventory:
FOREIGN KEY (Inventory_ID, Weapon_ID)
REFERENCES WeaponInventory (Inventory_ID, WeaponInventory_ID) -- see here
Note that Weapon_ID is not part of the PK in WeaponInventory:
CREATE TABLE WeaponInventory (
Inventory_ID VARCHAR(30) NOT NULL,
WeaponInventory_ID Varchar(10) NOT NULL,
Weapon_ID VARCHAR(10) REFERENCES Weapons(Weapon_ID) NOT NULL,
primary key(Inventory_ID, WeaponInventory_ID) -- Weapon_ID is not part of PK
);
Check this Fiddle.

How can I re-design with fewer tables?

I have designed a database for online donation. I have not added foreign key relationships because first I want to achieve a simple design. It's currently 11 tables, and it seems already more complicated than necessary.
The first one is registration table. The other 8 are different item types which will be donated by donors or by receivers, and 1 will be for post table it means when the user or receiver wants donate they will post what they want to donate or what they want ask others to give them. The last one will be for comment, the comment might be on the post by donors or receivers.
Can any one can help me re-design this in a simpler way?
Create Table Registration
(
ID int NOT NULL primary key,
FirstName varchar(25) NOT NULL,
LastName varchar(25) NOT NULL,
Username varchar(20),
Gender varchar(10),
Home_Address varchar(100),
Office_Address varchar(100),
City varchar(25),
State varchar(25),
Zip varchar(25),
Contact_No int ,
Email varchar(25)
);
2 posts
CREATE TABLE Post
( p_id int constraint p_pk primary key,
Username varchar(25),
Status varchar(25),
image nvarchar(max),
date_time varchar(100)
);
3,
CREATE TABLE Books
(
ISBN nvarchar(200) constraint ISBN_pk primary key,
Username varchar(25),
Book_title varchar(25),
Authorname varchar(25),
Publicationdate varchar(25),
Purchasedate varchar(25),
Book_edition varchar(25)
);
4,
CREATE TABLE images
(I_id int constraint i_pk primary key,
Username varchar(25),
Title varchar(25),
url varchar(50),
description varchar(100)
);
5,
CREATE TABLE laptop
(
L_id int constraint L_pk primary key,
Username varchar(25),
Model varchar(25),
Speed varchar(25),
Ram varchar(25),
HD varchar(50),
Screen varchar(50)
);
6, other items
CREATE TABLE other_items
(O_id int constraint O_pk primary key,
Username varchar(25),
Item_title varchar(25),
Item_type varchar(25),
Item_description varchar(100),
Itempicture varchar(100)
);
7, recipient
CREATE TABLE Recipient
(R_id int constraint R_pk primary key,
Firstname varchar(25),
Lastname varchar(25),
National_id_no varchar(50),
Address varchar(100),
Contact_no varchar(100)
);
8
CREATE TABLE Shoesimages
(
s_id int constraint Rss_pk primary key,
Username varchar(25), standard varchar(25),
Gender varchar(25),
Colour varchar(25),
Description varchar(100)
);
9,
CREATE TABLE uniform
(U_id int constraint u_pk primary key,
Username varchar(25),
Standard varchar(25),
Gender varchar(25),
Colour varchar(25),
Description varchar(100)
);
10,
CREATE TABLE Research_paper
(
Rs_id int constraint Rs_pk primary key,
Username varchar(25),
title varchar(25),
authorname varchar(25),
year_of_publish varchar(25),
venu varchar(100)
);
11,
CREATE TABLE Comments
(
C_id int constraint C_pk primary key,
Username varchar2(25),
comment nvarchar(max),
date_time varchar2(100)
);

oracle SQL - ORA-009007 Missing right parenthesis

I have this sql
CREATE TABLE PATIENTS
(
patientID NUMBER NOT NULL,
healthInsID NUMBER,
fname VARCHAR(20) NOT NULL,
minit VARCHAR(15),
lname VARCHAR(30) NOT NULL,
gender CHAR(2),
email VARCHAR(40),
street VARCHAR(40),
postalCode NUMBER,
city VARCHAR(20),
country VARCHAR(20),
PRIMARY KEY (patientID),
FOREIGN KEY (healthInsID) REFERENCES HEALTH_INSURANCES
ON DELETE SET NULL ON UPDATE CASCADE
);
I have no idea why I keep getting this error. I have search a lot but still nothing that can solve it. Any ideas?
Thanks
You have to specify column from HEALTH_INSURANCES table in FOREIGN KEY caluse.
You should also remove ON UPDATE CASCADE. You can use a trigger on update instead of this clause.
CREATE TABLE PATIENTS
(
patientID NUMBER NOT NULL,
healthInsID NUMBER,
fname VARCHAR(20) NOT NULL,
minit VARCHAR(15),
lname VARCHAR(30) NOT NULL,
gender CHAR(2),
email VARCHAR(40),
street VARCHAR(40),
postalCode NUMBER,
city VARCHAR(20),
country VARCHAR(20),
PRIMARY KEY (patientID),
FOREIGN KEY (healthInsID) REFERENCES HEALTH_INSURANCES (healthInsID)
ON DELETE SET NULL
);
More information about constraints