ORA-00907: missing right parenthesis (With Examples) - sql

I'm trying to create this table in SQL.
CREATE TABLE Orders (
order_id int(10) NOT NULL,
order_date date NOT NULL,
total_value varchar(250) DEFAULT NULL,
order_status varchar(250) DEFAULT NULL,
payment_type_id int(10) NOT NULL,
delivery_id int(10) DEFAULT NULL,
store_id int(10) NOT NULL,
staff_id int(10) DEFAULT NULL,
client_id int(10) NOT NULL,
sale_type_id int(10) NOT NULL
);
I gives me [Err] ORA-00907: missing right parenthesis
I really don't know why. I already searched a lot, I put this example:
CREATE TABLE suppliers (
supplier_id number(10) NOT NULL,
supplier_name varchar2(50) NOT NULL,
contact_name varchar2(50)
);
And it works! But it's the same as mine, so why does it give this error?

You dont have to define the length of int. Remove the (10)
CREATE TABLE Orders (
order_id int NOT NULL,
order_date date NOT NULL,
total_value varchar(250) DEFAULT NULL,
order_status varchar(250) DEFAULT NULL,
payment_type_id int NOT NULL,
delivery_id int DEFAULT NULL,
store_id int NOT NULL,
staff_id int DEFAULT NULL,
client_id int NOT NULL,
sale_type_id int NOT NULL
);
SQL FIDDLE DEMO

Remove the (10) from all the ints, or change it all to number(10), like so
CREATE TABLE Orders (
order_id int NOT NULL,
order_date date NOT NULL,
total_value varchar(250) DEFAULT NULL,
order_status varchar(250) DEFAULT NULL,
payment_type_id int NOT NULL,
delivery_id int DEFAULT NULL,
store_id int NOT NULL,
staff_id int DEFAULT NULL,
client_id int NOT NULL,
sale_type_id int NOT NULL
);

Related

i am trying to create tables but it show me 2 errors, how i fix it?

2 errors were found during analysis.
Unexpected beginning of statement. (near "admin_id" at position 349)
Unrecognized statement type. (near "INT" at position 358)
CREATE TABLE Users (
user_id INT NOT NULL AUTO_INCREMENT,
email VARCHAR(80) NOT NULL,
password CHAR(41) NOT NULL,
name VARCHAR(50) NOT NULL,
phone VARCHAR(20) NOT NULL,
gender VARCHAR(6) NOT NULL,
fbinfo VARCHAR(50) NOT NULL,
age INT NOT NULL,
PRIMARY KEY (user_id),
UNIQUE INDEX (email)
)
CREATE TABLE Admin (
admin_id INT NOT NULL AUTO_INCREMENT,
email VARCHAR(80) NOT NULL,
password CHAR(41) NOT NULL,
PRIMARY KEY (admin_id),
UNIQUE INDEX (email)
)
CREATE TABLE Task (
task_id INT NOT NULL AUTO_INCREMENT,
tex VARCHAR(140) NOT NULL,
datetime DATE,
status INT,
calendar BOOLEAN,
PRIMARY KEY (task_id),
lat DECIMAL(9,6),
long DECIMAL(9,6)
)
If you are doing this in one execution, you would need to include a ; at the end of each of your table creation statements.
CREATE TABLE Users (
user_id INT NOT NULL AUTO_INCREMENT,
email VARCHAR(80) NOT NULL,
password CHAR(41) NOT NULL,
name VARCHAR(50) NOT NULL,
phone VARCHAR(20) NOT NULL,
gender VARCHAR(6) NOT NULL,
fbinfo VARCHAR(50) NOT NULL,
age INT NOT NULL,
PRIMARY KEY (user_id),
UNIQUE INDEX (email)
);
CREATE TABLE Admin (
admin_id INT NOT NULL AUTO_INCREMENT,
email VARCHAR(80) NOT NULL,
password CHAR(41) NOT NULL,
PRIMARY KEY (admin_id),
UNIQUE INDEX (email)
);
CREATE TABLE Task (
task_id INT NOT NULL AUTO_INCREMENT,
tex VARCHAR(140) NOT NULL,
datetime DATE,
status INT,
calendar BOOLEAN,
PRIMARY KEY (task_id),
lat DECIMAL(9,6),
long DECIMAL(9,6)
);

Importing .sql file into SQL Server 2012

I have database with .sql, I want to import that .sql file into SQL Server 2012 using Management Studio.
When I tried to import the data, I'm getting an error:
Msg 156, Level 15, State 1, Line 76
Incorrect syntax near the keyword 'NOT'.
[![enter image description here][1]][1]
CREATE TABLE ct_bookings(
id int NOT NULL,
order_id bigint NOT NULL,
client_id bigint NOT NULL,
order_date date NOT NULL,
booking_date_time datetime NOT NULL,
service_id int NOT NULL,
method_id int NOT NULL,
method_unit_id int NOT NULL,
method_unit_qty int NOT NULL,
method_unit_qty_rate double NOT NULL,
booking_status varchar(10) not null ('A','C','R','CC','CS','CO','MN','RS') NOT NULL COMMENT 'A=active, C=confirm, R=Reject, CC=Cancel by Client, CS=Cancel by service provider,CO=Completed,MN=MARK AS NOSHOW',
`reject_reason` varchar(200) NOT NULL,
`reminder_status` enum('0','1') NOT NULL DEFAULT '0' COMMENT '0=Email Not Sent,1=Email Sent',
`lastmodify` datetime NOT NULL,
`read_status` enum('R','U') NOT NULL DEFAULT 'U'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
How can I solve this issue?
Please help me out. Thanks in advance.
in MySQL:-
CREATE TABLE ct_addon_service_rate(
id int(11) NOT NULL,
addon_service_id int(11) NOT NULL,
unit varchar(20) NOT NULL,
rules VARCHAR(10) NOT NULL CHECK (rules IN('E', 'G')),
rate DOUBLE NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Equals in SQL Server:-
Create TABLE ct_addon_service_rate (
id int NOT NULL,
addon_service_id int NOT NULL,
unit varchar(20) NOT NULL,
rules char(1) not null,
rate FLOAT(25) NOT NULL,
CHECK (rules in ('E', 'G'))
)
Update:-
In MySQL:-
CREATE TABLE ct_bookings(
id int NOT NULL,
order_id bigint NOT NULL,
client_id bigint NOT NULL,
order_date date NOT NULL,
booking_date_time datetime NOT NULL,
service_id int NOT NULL,
method_id int NOT NULL,
method_unit_id int NOT NULL,
method_unit_qty int NOT NULL,
method_unit_qty_rate double NOT NULL,
booking_status varchar(10) not null ('A','C','R','CC','CS','CO','MN','RS') NOT NULL COMMENT 'A=active, C=confirm, R=Reject, CC=Cancel by Client, CS=Cancel by service provider,CO=Completed,MN=MARK AS NOSHOW',
`reject_reason` varchar(200) NOT NULL,
`reminder_status` enum('0','1') NOT NULL DEFAULT '0' COMMENT '0=Email Not Sent,1=Email Sent',
`lastmodify` datetime NOT NULL,
`read_status` enum('R','U') NOT NULL DEFAULT 'U'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Equals in SQL Server:-
CREATE TABLE ct_bookings(
id int NOT NULL,
order_id bigint NOT NULL,
client_id bigint NOT NULL,
order_date date NOT NULL,
booking_date_time datetime NOT NULL,
service_id int NOT NULL,
method_id int NOT NULL,
method_unit_id int NOT NULL,
method_unit_qty int NOT NULL,
method_unit_qty_rate float(25) NOT NULL,
booking_status varchar(10) not null check (booking_status in ('A','C','R','CC','CS','CO','MN','RS')),
/*COMMENT 'A=active, C=confirm, R=Reject, CC=Cancel by Client, CS=Cancel by service provider,CO=Completed,MN=MARK AS NOSHOW', */
reject_reason varchar(200) NOT NULL,
reminder_status char(1)NOT NULL check (reminder_status in ('0','1')) DEFAULT '0', /*COMMENT '0=Email Not Sent,1=Email Sent', */
lastmodify datetime NOT NULL,
read_status char(1) NOT NULL check (read_status in ('R','U')) DEFAULT 'U'
)
Update 2:-
in MySQL:-
CREATE TABLE ct_email_templates (
id int NOT NULL,
email_subject varchar(200) COLLATE Latin1_General_CI_AS NOT NULL,
email_message text COLLATE Latin1_General_CI_AS NOT NULL,
default_message text COLLATE Latin1_General_CI_AS NOT NULL,
email_template_status varchar(10) NOT NULL check(email_template_status in('E','D')) COLLATE Latin1_General_CI_AS,
email_template_type varchar(10) check(email_template_type IN('A','C','R','CC','RS','RM')) COLLATE Latin1_General_CI_AS NOT NULL COMMENT 'A=active, C=confirm, R=Reject, CC=Cancel by Client, RS=Reschedule, RM=Reminder',
user_type` enum('A','C') COLLATE utf8_unicode_ci NOT NULL COMMENT 'A=Admin,C=client'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Equals in SQL Server:-
CREATE TABLE ct_email_templates (
id int NOT NULL,
email_subject varchar(200) COLLATE Latin1_General_CI_AS NOT NULL,
email_message text COLLATE Latin1_General_CI_AS NOT NULL,
default_message text COLLATE Latin1_General_CI_AS NOT NULL,
email_template_status varchar(10) COLLATE Latin1_General_CI_AS NOT NULL check(email_template_status in('E','D')) ,
email_template_type varchar(10) COLLATE Latin1_General_CI_AS check(email_template_type IN('A','C','R','CC','RS','RM')) NOT NULL, /*COMMENT 'A=active, C=confirm, R=Reject, CC=Cancel by Client, RS=Reschedule, RM=Reminder',
user_type` enum('A','C') COLLATE utf8_unicode_ci NOT NULL COMMENT 'A=Admin,C=client' */
)

SQL - Cannot add foreign key constraint

I am completely new to writing SQL code and I am attempting to run a simple table creation, however I cannot find where the error in my programming is, and as I am completely new I am struggling with this creation.
This is a school project that I am working on, and hoping anyone can help.
The error I am receiving in 'SQLFiddle' is "Cannot add foreign key constraint" on the following code:
CREATE TABLE invoice(
invoice_id INT NOT NULL,
customer_id INT NOT NULL,
order_date DATE NULL,
spec_order_note VARCHAR(45) NULL,
PRIMARY KEY(invoice_id, customer_id),
FOREIGN KEY (customer_id)
REFERENCES customer.customer_id
ON DELETE CASCADE
ON UPDATE CASCADE
);
CREATE TABLE line_item (
invoice_id INT NOT NULL,
donut_id INT NOT NULL,
quantity INT NULL
CONSTRAINT donut_invoice
FOREIGN KEY invoice_id
REFERENCES invoice.invoice_id
ON DELETE RESTRICT
ON UPDATE RESTRICT
)
CREATE TABLE donut (
donut_id INT NOT NULL,
donut_name VARCHAR(15) NULL,
description VARCHAR(30) NULL,
unit_price INT NULL
PRIMARY KEY(donut_id),
)
CREATE TABLE customer (
customer_id INT NOT NULL,
last_name VARCHAR(15) NULL,
first_name VARCHAR(10) NULL,
street_add VARCHAR(20) NULL,
apt_num INT NULL,
city VARCHAR(20) NULL,
state VARCHAR(15) NULL,
zip_code INT NULL,
home_phone VARCHAR(10) NULL,
mobile_phone VARCHAR(10) NULL,
other_phone VARCHAR(10) NULL,
customer_notes VARCHAR(45) NULL
PRIMARY KEY(customer_id),
)
Any help is greatly appreciated.
You can only reference existing tables and columns in foreign constraints. So if you want to reference customer table in invoice's foreign key, you need to either create customer before invoice or add the foreign key constrain additionally using ALTER TABLE.
Apart of that, there's couple syntax errors in your code like missing semicolons and misplaced (missing and additional) commas.
A working code:
CREATE TABLE customer (
customer_id INT NOT NULL,
last_name VARCHAR(15) NULL,
first_name VARCHAR(10) NULL,
street_add VARCHAR(20) NULL,
apt_num INT NULL,
city VARCHAR(20) NULL,
state VARCHAR(15) NULL,
zip_code INT NULL,
home_phone VARCHAR(10) NULL,
mobile_phone VARCHAR(10) NULL,
other_phone VARCHAR(10) NULL,
customer_notes VARCHAR(45) NULL,
PRIMARY KEY(customer_id)
);
CREATE TABLE invoice(
invoice_id INT NOT NULL,
customer_id INT NOT NULL,
order_date DATE NULL,
spec_order_note VARCHAR(45) NULL,
PRIMARY KEY(invoice_id, customer_id),
FOREIGN KEY (customer_id)
REFERENCES customer (customer_id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
CREATE TABLE line_item (
invoice_id INT NOT NULL,
donut_id INT NOT NULL,
quantity INT NULL,
CONSTRAINT donut_invoice
FOREIGN KEY (invoice_id)
REFERENCES invoice (invoice_id)
ON DELETE RESTRICT
ON UPDATE RESTRICT
);
CREATE TABLE donut (
donut_id INT NOT NULL,
donut_name VARCHAR(15) NULL,
description VARCHAR(30) NULL,
unit_price INT NULL,
PRIMARY KEY(donut_id)
);
http://sqlfiddle.com/#!9/36b044

SQL table creation code gives error

could someone have a look at this for me, I can't seem to find why it is not working.
CREATE TABLE Person(
Person_ID int auto_increment NOT NULL,
Person_Type_ID int NOT NULL,
Create_Date datetime NOT NULL ,
Modify_Date datetime NOT NULL ,
First_Name varchar(50) NOT NULL,
Surname varchar(50) NOT NULL,
DOB date NOT NULL,
Gender char(1) NOT NULL CHECK (Gender ='f' OR Gender ='m'),
Archive char(1) NULL,
Allergies varchar(200) NOT NULL,
Dietry_Requirements varchar(200) NOT NULL,
Disabilities varchar(200) NOT NULL,
Medicine_Requirements varchar(200) NOT NULL,
username varchar (30) NOT NULL,
password varchar (30) NOT NULL,
CONSTRAINT PK_Person_ID PRIMARY KEY (Person_ID)
CONSTRAINT FK_Person_Type_ID FOREIGN KEY (Person_Type_ID)
REFERENCES Person_Type (Person_Type_ID));
You missed a comma! This should work...
CREATE TABLE Person(
Person_ID int auto_increment NOT NULL,
Person_Type_ID int NOT NULL,
Create_Date datetime NOT NULL ,
Modify_Date datetime NOT NULL ,
First_Name varchar(50) NOT NULL,
Surname varchar(50) NOT NULL,
DOB date NOT NULL,
Gender char(1) NOT NULL CHECK (Gender ='f' OR Gender ='m'),
Archive char(1) NULL,
Allergies varchar(200) NOT NULL,
Dietry_Requirements varchar(200) NOT NULL,
Disabilities varchar(200) NOT NULL,
Medicine_Requirements varchar(200) NOT NULL,
username varchar (30) NOT NULL,
password varchar (30) NOT NULL,
CONSTRAINT PK_Person_ID PRIMARY KEY (Person_ID),
CONSTRAINT FK_Person_Type_ID FOREIGN KEY (Person_Type_ID)
REFERENCES Person_Type (Person_Type_ID));

Problem with SQL syntax (probably simple)

I'm doing some custom database work for a module for Drupal and I get the following SQL error when trying to create my table:
user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DEFAULT NULL, rooms INT DEFAULT NULL, adults INT DEFAULT NULL, children' at line 14 query: CREATE TABLE dr_enquiry ( eId INT unsigned NOT NULL auto_increment, eKey VARCHAR(16) NOT NULL, dateSent INT NOT NULL DEFAULT 0, status VARCHAR(30) NOT NULL DEFAULT 'Unanswered', custName VARCHAR(50) NOT NULL, custEmail VARCHAR(200) NOT NULL, custPhone VARCHAR(25) NOT NULL, custCountry VARCHAR(40) NOT NULL, custIP VARCHAR(11) DEFAULT NULL, offerName VARCHAR(100) NOT NULL, offerURL VARCHAR(200) NOT NULL, arrival DATETIME DEFAULT NULL, departure DEFAULT NULL, rooms INT DEFAULT NULL, adults INT DEFAULT NULL, children INT DEFAULT NULL, childAges VARCHAR(32) DEFAULT NULL, toddlers INT DEFAULT NULL, toddlerAges VARCHAR(32) DEFAULT NULL, catering VARCHAR(255) DEFAULT NULL, comments VARCHAR(255) DEFAULT NULL, agent VARCHAR(100) DEFAULT NULL, voucher VARCHAR(100) DEFAULT NULL, PRIMARY KEY (eId) ) /*!40100 DEFAULT CHARACTER SET UTF8 */ in /home/travelco/public_html/includes/database.inc on line 550.
The 'departure' field doesn't seem to have a type eg varchar, mediumint etc. Try adding one and see if that solves your problem :)
Nullability is not set using a DEFAULT constraint. Thus, the compiler is balking at each instance of DEFAULT NULL. Thus, the create statement should look like:
CREATE TABLE dr_enquiry (
eId INT unsigned NOT NULL auto_increment
, eKey VARCHAR(16) NOT NULL
, dateSent INT NOT NULL DEFAULT 0
, status VARCHAR(30) NOT NULL DEFAULT 'Unanswered'
, custName VARCHAR(50) NOT NULL
, custEmail VARCHAR(200) NOT NULL
, custPhone VARCHAR(25) NOT NULL
, custCountry VARCHAR(40) NOT NULL
, custIP VARCHAR(11) NULL
, offerName VARCHAR(100) NOT NULL
, offerURL VARCHAR(200) NOT NULL
, arrival DATETIME NULL
, departure DATETIME NULL
, rooms INT NULL
, adults INT NULL
, children INT NULL
, childAges VARCHAR(32) NULL
, toddlers INT NULL
, toddlerAges VARCHAR(32) NULL
, catering VARCHAR(255) NULL
, comments VARCHAR(255) NULL
, agent VARCHAR(100) NULL
, voucher VARCHAR(100) NULL
, PRIMARY KEY (eId)
)
(Oh and departure did not have a datatype as richsage mentioned. I presumed it was DateTime.)