sqlite error near '''' syntax error data input - syntax

I am using sqlite3 and trying to put data into my database.
CREATE TABLE CLUB(
cl_id INT PRIMARY KEY NOT NULL,
naam TEXT NOT NULL,
adres VARCHAR(200) NOT NULL,
dtm_opricht TEXT NOT NULL
);
CREATE TABLE STADION(
sta_id INT PRIMARY KEY NOT NULL,
cl_id INT REFERENCES CLUB(cl_id),
naam TEXT NOT NULL,
adres VARCHAR(200) NOT NULL,
capaciteit INT NOT NULL,
dtm_bouw TEXT NOT NULL
);
CREATE TABLE TECHNISCHDIRECTEUR(
td_id INT PRIMARY KEY NOT NULL,
cl_id INT REFERENCES CLUB(cl_id),
naam TEXT NOT NULL,
adres VARCHAR(200) NOT NULL,
salaris REAL NOT NULL,
nationaliteit TEXT NOT NULL,
geslacht TEXT NOT NULL,
dtm_geboorte TEXT NOT NULL
);
Everything was going fine with putting in data for the first 2 tables.
insert into CLUB values(101, 'Ajax', 'Amsterdamstraat 1', '05-01-1916');
insert into STADION values(201, 101, 'ArenA', 'Arenaweg 10', 50000, '05-03-1990');
However when I tried to put data into my 3rd table it gave me a syntax error near "301".
insert into TECHNISCHDIRECTEUR(301, 101, 'Michael Kinsbergen', 'Kalverstraat 18', 120000.13,
'Nederlands', 'Man', '03-09-1960');
What could it be?

You're missing the keyword values:
insert into TECHNISCHDIRECTEUR values(301,...

Related

How to add constraint in ALTER TABLE statement: ORA-00942: table or view does not exist

I am altering a table and add constraints, but I get the error "ORA-00942: table or view does not exist". Could somebody please help me, as I can't manage to find from where the error is coming from? Thank you!
CREATE TABLE Functionar (
CNP NUMBER(11),
Nume VARCHAR (255) NOT NULL,
Salariu NUMBER(9, 2) NOT NULL,
Functie VARCHAR (255) NOT NULL,
Oras VARCHAR (255) NOT NULL,
Str VARCHAR (255) NOT NULL,
Num NUMBER(9) NOT NULL,
Cod_postal VARCHAR (2) NOT NULL,
Sector VARCHAR (255) NOT NULL,
PRIMARY KEY(CNP)
);
CREATE TABLE TELEFON_FUNCTIONAR (
Telefon_F NUMBER(9) NOT NULL,
Nr NUMBER(9) NOT NULL,
Doza_zil NUMBER(3) NOT NULL,
PRIMARY KEY(Telefon_F)
);
ALTER TABLE TELEFON_FUNCTIONAR
ADD CONSTRAINT "efectueaza" FOREIGN KEY(CNP) REFERENCES Functionar(CNP) ON DELETE
CASCADE;
ALTER TABLE TELEFON_FUNCTIONAR
ADD CONSTRAINT pk_TELEFON_FUNCTIONAR PRIMARY KEY(Telefon_F);

Missing right parenthesis error while creating a table with SQL code generated in Vertabelo

I want to create a Database for my school project. Some tables were created without an error, but when I wanted to create a more complex table, I had this error:
ORA-00907: missing right parenthesis
The code is following (the names of the table and attributes are in Romanian):
CREATE TABLE Curse (
id_cursa int NOT NULL,
id_tura int NULL,
moment_inceput_cursa timestamp NULL,
moment_sfarsit_cursa timestamp NULL,
adresa_initiala text NULL,
GPS_punct_start text NULL,
adresa_destinatie text NULL,
destinatie_GPS text NULL,
stare_cursa char NOT NULL DEFAULT 0,
modalitate_plata int NULL,
pret decimal NULL,
CONSTRAINT Curse_pk PRIMARY KEY (id_cursa)
);
The actual fault is the DEFAULT clause comes before the NOT NULL clause. So this the correct syntax:
stare_cursa char DEFAULT 0 NOT NULL
Beyond that you need to change the text datatype to something like varchar2(1000) or whatever length you need.
A few objections:
TEXT datatype is invalid; I used VARCHAR2(100); could be larger, or CLOB
correct order is DEFAULT 0 NOT NULL (not NOT NULL DEFAULT 0)
Although it is not an error, you don't have to specify that NULL values are allowed
SQL> CREATE TABLE curse(
2 id_cursa INT NOT NULL,
3 id_tura INT NULL,
4 moment_inceput_cursa TIMESTAMP NULL,
5 moment_sfarsit_cursa TIMESTAMP NULL,
6 adresa_initiala VARCHAR2(100)NULL,
7 gps_punct_start VARCHAR2(100)NULL,
8 adresa_destinatie VARCHAR2(100)NULL,
9 destinatie_gps VARCHAR2(100)NULL,
10 stare_cursa CHAR DEFAULT 0 NOT NULL,
11 modalitate_plata INT NULL,
12 pret DECIMAL,
13 CONSTRAINT curse_pk PRIMARY KEY(id_cursa)
14 );
Table created.
SQL>

ORA-00906 missing left parenthesis error while creating table

Getting ORA-00906 error while creating table.
CREATE TABLE TEST.BSTXTEST(
PDBC_PFX CHAR NOT NULL,
BSBS_TYPE CHAR NOT NULL,
BSTX_SEQ_NO NUMBER NOT NULL,
BSTX_TEXT RAW NOT NULL,
BSTX_LOCK_TOKEN NUMBER NOT NULL,
ATXR_SOURCE_ID TIMESTAMP NOT NULL,
BSTXTEXT VARCHAR2(500) NOT NULL,
LENTEXT NUMBER NOT NULL
)
For a RAW datatype the size portion of the definition is mandatory.
e.g.
BSTX_TEXT RAW(2000) NOT NULL,

ERROR: null value in column "id" violates not-null constraint

I just migrated my app from mysql to postgres but when I try to insert a record in a specific table I get violates not-null constraint error:
ERROR: null value in column "id" violates not-null constraint DETAIL: Failing row contains (null, 1, 1, null, null, null, 2016-03-09 09:24:12.841891, 2012-12-31 23:00:00, 2012-12-31 23:00:00, null, null, f, null, f, XYZAssignment, null, null, null, null).
********** Error **********
ERROR: null value in column "id" violates not-null constraint
SQL state: 23502
Detail: Failing row contains (null, 1, 1, null, null, null, 2016-03-09 09:24:12.841891, 2012-12-31 23:00:00, 2012-12-31 23:00:00, null, null, f, null, f, XYZAssignment, null, null, null, null).
When I try to create the record using factory_girl:
#assignment = FactoryGirl.create(:assignment)
It builds this sql query:
INSERT INTO assignments(
id, account_id, l_id, viewed_at, accepted_at, declined_at,
expires_at, created_at, updated_at, decline_reason, decline_reason_text,
promotion, c_checked_at, forwardable, type, f_promo,
c_check_successful, c_check_api_result, c_check_human_result)
VALUES (null, 1, 1, null, null, null, '2016-03-09 09:24:12.841891', '2012-12-31 23:00:00', '2012-12-31 23:00:00', null, null, 'f', null, 'f', 'XYZAssignment', null, null, null, null);
This is the assignment factory:
FactoryGirl.define do
factory :assignment do
expires_at 24.hours.from_now
account
lead
end
end
this is the table description:
CREATE TABLE assignments(
id serial NOT NULL, account_id integer NOT NULL, l_id integer NOT NULL, viewed_at timestamp without time zone, accepted_at timestamp without time zone, declined_at timestamp without time zone, expires_at timestamp without time zone, created_at timestamp without time zone, updated_at timestamp without time zone, decline_reason character varying(16), decline_reason_text character varying(256), promotion boolean NOT NULL DEFAULT false, c_checked_at timestamp without time zone, forwardable boolean DEFAULT true, type character varying(64), f_promo boolean, c_check_successful boolean, c_check_api_result character varying(32), c_check_human_result character varying(32), CONSTRAINT assignments_pkey PRIMARY KEY (id)
) WITH (
OIDS=FALSE
);
Looks its not able to auto increment the id, any idea?
You have to skip id in the INSERT operation:
INSERT INTO assignments(account_id, l_id, ...)
VALUES
(1, 1, ...)
The id will automatically get the next sequence number, since it is an auto-increment field.

SQL Error: ORA-00906: missing left parenthesis 00906. 00000 - "missing left parenthesis"

i have been trying to make a simple table and i it keeps coming up with SQL Error: ORA-00906: missing left parenthesis 00906. 00000 - "missing left parenthesis"
CREATE TABLE USER_TABLE(
USER_ID int NOT NULL,
Username varchar NULL,
Password varchar NULL,
Email varchar NOT NULL,
DOB Date NULL,
Address VARCHAR NOT NULL,
First_name VARCHAR NOT NULL,
Telephone_number int NULL,
PRIMARY KEY (User_ID));
You simply need to add the size of VARCHAR colums:
CREATE TABLE USER_TABLE
(
USER_ID INT NOT NULL,
Username VARCHAR(1) NULL,
Password VARCHAR(1) NULL,
Email VARCHAR(1) NOT NULL,
DOB DATE NULL,
Address VARCHAR(1) NOT NULL,
First_name VARCHAR(1) NOT NULL,
Telephone_number INT NULL,
PRIMARY KEY(User_ID)
);
Notice that VARCHAR is deprecated, better use VARCHAR2

Resources