phpMyAdmin creating an attribute with '#" character in its name - sql

I am trying to create the following table.
CREATE TABLE customer
(
cust# CHAR(3)NOT NULL ,
cname VARCHAR(30) NOT NULL ,
city VARCHAR(20) NOT NULL,
PRIMARY KEY (cust#)
)engine=InnoDB;
I am getting the following error
#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 'cname VARCHAR(30) NOT NULL , city VARCHAR(20) NOT NULL, PRIMARY KEY (cust#' at line 4
I have confirmed that the problem is with the '#' by replacing it with 'custNum'.
However, I must use the '#' sign. I know I can rename the field in the myPhpAdmin interface to cust# but I need to know how to escape it in the SQL statement.
*Edit to say I have already tried '\#'
Thanks

I was able to answer my own question and I'm posting here in case someone else has the same problem.
You have to use '`' around the name. So `cust#` did the trick.

Related

PostgreSQL syntax error at or near INT

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)
);

PHPmyadmin won't accept CREATE TABLE statement

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
)

SQL Error: Missing Right Parenthesis in Line 1 ORA-00907

I've checked other similar questions. about repeating commas, error in commands but cant find any in my error. I've also searched examples of create tables to compare with mine, but fail to find any difference :(.
Below is the CREATE table statement:
CREATE TABLE DRIVER(L# VARCHAR(15) NOT NULL
, DNAME VARCHAR(75) NOT NULL
, STATUS VARCHAR(50) NOT NULL
, NRIC VARCHAR (15) NOT NULL
, PRIMARY KEY(L#)
, CANDIDATE KEY(NRIC)
);
Anyone can help me point out that i can't see or missing something,thanks (:
You can't specify CANDIDATE KEY like that in Oracle. The right way is to create a UNIQUE CONSTRAINT on your Candidate Key(s).
Like so.
Here's a working SQLFiddle: http://sqlfiddle.com/#!4/b392d/1
CREATE TABLE DRIVER(
L# VARCHAR(15) NOT NULL,
DNAME VARCHAR(75) NOT NULL,
STATUS VARCHAR(50) NOT NULL,
NRIC VARCHAR (15) NOT NULL,
PRIMARY KEY(L#),
CONSTRAINT UK_NRIC UNIQUE (NRIC)
);
ORA-00907 pretty much always indicates a syntax error. It happens when the parser finds a word which is not a key word in a position where it is expecting either a keyword or a right-hand bracket to close the current statement (hence Missing Right Parenthesis). Although sometime it can just be that we have an unmatched left-hand bracket: a decent text editor can help trace that.
In your case the intruding word is CANDIDATE. Syntax errors can be tricky for beginners. I recommend you familarise yourself with the Oracle documentation:it is online, complete and free, and has quite a lot of examples. Check it out . The list of reserved words could have helped you, because CANDIDATE is not on it, which is a big clue.
If you are going to use odd characters in a name, wrap it in square brackets. []

Can't create new table

I'm new to SQL Server 2000 and face a problem. I want to make a new table but I encounter an error message with the following code:
create table Buku
(
Kode_Buku char(5) constraint PK_Kode_Buku Primary Key,
Judul_Buku varchar(10)not null,
Nama_Pengarang varchar(30) not null,
Penerbit varchar(30),
Kota_Terbit varchar(30) default,
Tahun_Terbit varchar(4) default,
Bahasa varchar(4) check,
Harga_Jual money,
)
and here's the error code:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'Buku'.
You have three problems:
You have multiple cases where you say default but don't specify anything
You have a check but don't specify anything
Your last column definition says money, with a trailing comma
Now, none of these lead to the exact error message you're getting, so maybe there is more you're not telling us (is there more code before the create table bit?), but these little syntax problems are far too localized to be useful in this Q & A format.
EDIT
I just ran this on a SQL Server 2000 instance and it worked just fine:
create table Buku
(
Kode_Buku char(5) constraint PK_Kode_Buku Primary Key,
Judul_Buku varchar(10) not null, -- added space here
Nama_Pengarang varchar(30) not null,
Penerbit varchar(30),
Kota_Terbit varchar(30), -- removed default here
Tahun_Terbit varchar(4), -- removed default here
Bahasa varchar(4), -- removed check here
Harga_Jual money -- removed comma here
)
So I'm not sure what you're doing differently, but I can't get the error message you are seeing with the information you've provided in the question. If you're still getting an error message with this code (and only this code), you'll need to provide more information, such as ##VERSION, what interface you're using to submit the create table statement to SQL Server, etc.

sql: making a table structure for injections

I want to take the values from this site for the country table in my database.
The problem is that they don't provide the table structure, so I have to create one, but I cannot get it right - my phpMyAdmin keeps displaying an error when I want to inject the data into the table I created below:
#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 'NUMERIC, alpha3, name, officialName) VALUES ('004','AFG','Afghanistan','Afghan' at line 1
--
-- Table structure for table `countrytable`
--
CREATE TABLE IF NOT EXISTS `countrytable` (
`NUMERIC` int(11) NOT NULL,
`alpha3` int(11) NOT NULL,
`name` varchar(255) DEFAULT NULL,
`officialName` varchar(255) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
I think my table structure is incorrect. How can I fix it? Thanks!
Try all varchar fields to get the data in since all fields are in quotes in the string you have.
NUMERIC is reserved word in mysql
add in back-tick or quote it -> http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html
`alpha3` should be a varchar(3) (or larger), not an int(11).