I have simple sql code for create table and then add constraint to it. It looks like this:
CREATE TABLE bills (
id INTEGER NOT NULL,
code VARCHAR2(25) NOT NULL,
dateOfGeneration DATE NOT NULL,
job_id INTEGER NOT NULL
);
ALTER TABLE bills ADD CONSTRAINT bills_pk PRIMARY KEY ( id,job_id );
I am using IBExpert - client for Firebird. When I execute this code I get 2 errors:
First error: - in code VARCHAR2(25) NOT NULL
Invalid token.
Dynamic SQL Error.
SQL error code = -104.
Token unknown - line 3, column 29.
(.
Second error: - in code ALTER TABLE ...
Invalid token.
Dynamic SQL Error.
SQL error code = -104.
Token unknown - line 8, column 1.
ALTER.
The first one I think is because i am using varchar2 instead of varchar. What about second error? How to fix this?
There is no VARCHAR2 type in Firebird - https://firebirdsql.org/file/documentation/reference_manuals/fblangref25-en/html/fblangref25-datatypes-chartypes.html
If you want to run two commands - you have to run TWO commands. You try to run two commands in one, but that is not a way to do it. You have to split them and run one after another. Or you have to wrap them into one EXECUTE BLOCK command.
Also IBExpert has a separate window of Script Executive for multiple commands running. It is not SQL Editor which is designed to execute ONE command, it is a separate window in another menu - https://www.ibexpert.net/ibe/pmwiki.php?n=Doc.ScriptExecutive
Table creation command is described here: https://firebirdsql.org/file/documentation/reference_manuals/fblangref25-en/html/fblangref25-ddl-tbl.html
Basically what you trying to do looks like this, if to do it in one command:
CREATE TABLE bills (
id INTEGER NOT NULL,
code VARCHAR(25) NOT NULL,
dateOfGeneration DATE NOT NULL,
job_id INTEGER NOT NULL,
PRIMARY KEY ( id,job_id )
)
or if you insist on naming then perhaps
CREATE TABLE bills (
id INTEGER NOT NULL,
code VARCHAR(25) NOT NULL,
dateOfGeneration DATE NOT NULL,
job_id INTEGER NOT NULL,
CONSTRAINT bills_pk PRIMARY KEY ( id,job_id )
)
Related
I'm getting an error with this SQL code when I execute it in my Flask app. I swear I've done this exact thing before and it worked, so I'm not sure what's happening.
Here is the SQL:
DROP TABLE IF EXISTS user;
CREATE TABLE order (
id TEXT PRIMARY KEY,
plan_id INTEGER NOT NULL,
placed TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
ssh_key TEXT NOT NULL,
region INTEGER NOT NULL,
operating_system INTEGER NOT NULL,
enable_ipv6 INTEGER NOT NULL
expires INTEGER NOT NULL
);
Here is the relevant part of my python error:
sqlite3.OperationalError: near "order": syntax error
Thank you for the help
Order is a reserved keyword for sqlite. If you want to use a keyword as a name, you need to quote it.
https://www.sqlite.org/lang_keywords.html
I made a script to create a database with PostgreSQL.
So I copy in my script, click "Analyze & Explain" in pgAdmin4 and I have no clue why it says I have a syntax error at or near 'INT' on idSituationFamiliale.
I really can't see what's wrong...
--Personnes
--
CREATE TABLE SITUATION_FAMILIALE (
idSituationFamiliale INT NOT NULL,
intituleSituationFamiliale VARCHAR(50) NOT NULL,
PRIMARY KEY(idSituationFamiliale)
);
The query is fine if you RUN it. It is wrong if you EXPLAIN / ANALYZE it.
The doc says that you can explain a CREATE TABLE AS, not a pure CREATE TABLE statement. While the former contains a SELECT statement that can be explained/analyzed, the later has nothing to be explained/analyzed and fails on the 1st field, regardless of its name or type.
You should be using integer as opposed to int.
e.g
--Personnes
--
CREATE TABLE SITUATION_FAMILIALE (
idSituationFamiliale INTEGER NOT NULL,
intituleSituationFamiliale VARCHAR(50) NOT NULL,
PRIMARY KEY(idSituationFamiliale)
);
I'm trying to use a simple CREATE TABLE statement to create a new table in my very first SQL-database. PHPmyadmin won't accept the code and gives me an error statement.
There doesn't appear to be anything wrong with the syntax of my SQL command. In fact, I receive the same error statement when I copy and past an example code from any internet tutorial to create a table.
this is my SQL command:
CREATE TABLE Guestbook(
ID int AUTO_INCREMENT PRIMARY KEY NOT NULL,
Name varchar(50) NOT NULL,
Message TEXT NOT NULL,
Date datetime,
Sport varchar(30),
Practicioner BOOLEAN default 0,
)
This is the error statement:
Static analysis:
3 errors were found during analysis.
A symbol name was expected! (near "Name" at position 74)
Unexpected beginning of statement. (near "50" at position 87)
Unrecognized statement type. (near "NOT NULL" at position 91)
SQL query:
CREATE TABLE Guestbook( ID int AUTO_INCREMENT PRIMARY KEY NOT NULL, Name varchar(50) NOT NULL, Message TEXT NOT NULL, Date datetime, Sport varchar(30), Practicioner BOOLEAN default 0, )
MySQL said: Documentation
#1064 - 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 ')' at line 8
I can't imagine why this won't work. I'd like to be able to use to command line in phpMyadmin. and this seems pretty straigtht forward. Yet I've been fiddling around with it for ages and I can't figure out how to create even the simplest possible table.
Can anyone help me out?
You should remove the last comma in your CREATE statement:
CREATE TABLE Guestbook(
ID int AUTO_INCREMENT PRIMARY KEY NOT NULL,
Name varchar(50) NOT NULL,
Message TEXT NOT NULL,
Date datetime,
Sport varchar(30),
Practicioner BOOLEAN default 0
)
I'm having a problem with a table I created. I am trying to run a query however a red line appears under my code ('excursionID', and 'excursions'), claiming 'Invalid Column name 'excursionID' and 'Invalid object name 'dbo.excursions' even though I have created the table already!
Here is the query
SELECT
excursionID
FROM [dbo].[excursions]
Here is the query I used to create the table
USE [zachtravelagency]
CREATE TABLE excursions (
[excursionID] INTEGER NOT NULL IDENTITY (1,1) PRIMARY KEY,
[companyName] NVARCHAR (30) NOT NULL,
[location] NVARCHAR (30) NOT NULL,
[description] NVARCHAR (30) NOT NULL,
[date] DATE NOT NULL,
[totalCost] DECIMAL NOT NULL,
I've tried dropping the table and inserting table again.
For some reason all my other tables work, it's just this table that doesn't identify itself. I'm very new to SQL so thank you for your patience!
You use DB [zachtravelagency] for create table.And You dont use this DB in your query. Default used db master in SSMS. Try
SELECT
excursionID
FROM [zachtravelagency].[excursions]
I am trying to create tables in an SQLite database with sqlite3.
The command $ sqlite3 mydb < mytables.sql produce the following error: Incomplete SQL: ??C.
mytables.sql is:
CREATE TABLE SizeCulture (
SizeCultureID INTEGER PRIMARY KEY ASC,
SizeID INTEGER NULL,
CultureID TEXT NULL,
Name TEXT NULL,
Description TEXT NULL,
Abbreviation TEXT NULL,
);
CREATE TABLE Size(
SizeID INTEGER PRIMARY KEY ASC ,
Creation TEXT NOT NULL,
Modification TEXT NOT NULL,
Deleted INTEGER NOT NULL,
);
/****** Object: Table [Ordering].[BarCode] Script Date: 11/09/2011 14:58:19 ******/
CREATE TABLE BarCode(
BarCodeID INTEGER PRIMARY KEY ASC NOT NULL,
BarCodeValue TEXT NOT NULL,
);
This was modified from a script generated by SQL Server, where some tables need to be replicated on an Android device.
The above is just a set of repeating create table statements. From what I understand, SQLite follows standard SQL (like MySQL or postgres).
Though I can't test it at the moment, I think it's the trailing commas that are confusing it (for example, the comma at the end of Abbreviation TEXT NULL,). Try removing all those trailing commas.
Edit: To be clear, I'm talking about all of these commas:
Abbreviation TEXT NULL,
...
Deleted INTEGER NOT NULL,
...
BarCodeValue TEXT NOT NULL,
I had the same problem, but for a different reason (so I'm commenting because Google led me here). Turns out you can also encounter this error if your file has a weird encoding (like UCS-2 instead of UTF8).