mysql create table ... what am i doing wrong - mysql

CREATE TABLE 'behandelingen' (
'behandeling_id' int(10) NOT NULL auto_increment,
'behandeling' varchar(35) NOT NULL default '',
'kosten' float NOT NULL default '0',
'bank_reknr' varchar(20) NOT NULL default '',
PRIMARY KEY ('behandeling_id'),
UNIQUE KEY 'behandeling' ('behandeling')
);
Trying to import a database / tables to a my local server using phpmyadmin. I keep coming up with 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 ''behandelingen' ( 'behandeling_id' int(10) NOT NULL
auto_increment, 'behan' at line 1
Static analysis:
4 errors were found during analysis.
A symbol name was expected! (near "'behandeling_id'" at position 34)
At least one column definition was expected. (near "'behandeling_id'" at position 34)
Unexpected beginning of statement. (near "10" at position 55)
Unrecognized statement type. (near "NOT NULL" at position 59)
can some one shed some light on it ... I am using Server version: 5.7.14 - MySQL Community Server (GPL)

Use backticks instead of single quotes on the table name and column names. See below:
CREATE TABLE `behandelingen` (
`behandeling_id` int(10) NOT NULL auto_increment,
`behandeling` varchar(35) NOT NULL default '',
`kosten` float NOT NULL default '0',
`bank_reknr` varchar(20) NOT NULL default '',
PRIMARY KEY (`behandeling_id`),
UNIQUE KEY `behandeling` (`behandeling`)
);

CREATE TABLE behandelingen ( behandeling_id int(10) NOT NULL auto_increment, behandeling varchar(35) NOT NULL default 'default' , kosten float NOT NULL default 0, bank_reknr varchar(20) NOT NULL default 'default' , PRIMARY KEY (behandeling_id), UNIQUE KEY behandeling (behandeling) );

I can't test it right now, but I think that you shouldn't be using single quotes to define the name of the column: e.g.
CREATE TABLE Persons (
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);

Related

Table cannot be created in mysql -Error 1064

I am trying to create a table in MySQL with the query
CREATE TABLE ofRosterGroups (
rosterID BIGINT NOT NULL,
rank TINYINT NOT NULL,
groupName VARCHAR(255) NOT NULL,
PRIMARY KEY (rosterID, rank),
INDEX ofRosterGroup_rosterid_idx (rosterID)
);
but seems like it is throwing error everytime I made updates too. I don't know what is going wrong with it.
Error coming up is
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 'rank TINYINT NOT NULL, groupName
VARCHAR at line 3
MySQL 8.0.2 added support for the window rank function, making it a reserverd word.
You could escape it using backticks (`):
CREATE TABLE ofRosterGroups (
rosterID BIGINT NOT NULL,
`rank` TINYINT NOT NULL, -- Here
groupName VARCHAR(255) NOT NULL,
PRIMARY KEY (rosterID, `rank`), -- And here
INDEX ofRosterGroup_rosterid_idx (rosterID)
);
But it may be a better idea to just use a name that isn't a reserved word, such as rosterRank instead of rank:
CREATE TABLE ofRosterGroups (
rosterID BIGINT NOT NULL,
rosterRank TINYINT NOT NULL, -- Here
groupName VARCHAR(255) NOT NULL,
PRIMARY KEY (rosterID, rosterRank), -- And here
INDEX ofRosterGroup_rosterid_idx (rosterID)
);

PhPMyAdmin Error #1064; Syntax Error

I'm trying to put together a MySQL database for a forum, And when I try to make a section table I keep encountering a problem
#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 'TYPE = INNODB' at line 7
Here's the code:
CREATE TABLE sections (
sect_id INT(8) NOT NULL AUTO_INCREMENT,
sect_name VARCHAR(255) NOT NULL,
sect_desc VARCHAR(255) NOT NULL,
UNIQUE INDEX sect_name_unique (sect_name),
PRIMARY KEY (sect_id)
) TYPE=INNODB;
Use the following query
CREATE TABLE IF NOT EXISTS sections (
sect_id INT(8) NOT NULL AUTO_INCREMENT,
sect_name VARCHAR(255) NOT NULL,
sect_desc VARCHAR(255) NOT NULL,
UNIQUE INDEX sect_name_unique (sect_name),
PRIMARY KEY (sect_id)
) ENGINE=InnoDB
To mention the type of engine use ENGINE keyword.

SQL error #1064 on CREATE TABLE

I am importing a database from MySQL 4.0.27-standard into a new webhost with Server version: 5.5.48-37.8 - Percona Server (GPL), Release 37.8, Revision 727, using PHPMySQL.
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 '(14) NOT NULL '', PRIMARY KEY (site_id) ) ENGINE=MyISAM' at
line 14
Here is the CREATE TABLE query:
CREATE TABLE Brewing (
site_id int(5) NOT NULL auto_increment,
site_url varchar(255) NOT NULL default '',
site_name varchar(255) NOT NULL default '',
site_comment varchar(255) default NULL,
site_rating int(2) NOT NULL default '0',
site_entrydate varchar(25) NOT NULL default '',
site_lasttouched timestamp(14) NOT NULL,
PRIMARY KEY (site_id)
) ENGINE=MyISAM;
Remove the size of timestamp. It already has a default for setting up timestamp. So remove (14).
Plus added bonus, add ON UPDATE CURRENT_TIMESTAMP for auto update of timestamp.
The length argument for timestamp represents fractional seconds (see the documentation). The allowed lengths for fractional seconds are 0 to 6. 14 is too long.
I would advise you to just remove the length altogether.

#1064 -You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version

I'm new to PHP and MySQL and ran into a little trouble with a learning project I'm working on.
Whenever I try to create a table
CREATE TABLE transactions(
id int NOT NULL AUTO_INCREMENT,
location varchar(50) NOT NULL,
description varchar(50) NOT NULL,
category varchar(50) NOT NULL,
amount double(10) NOT NULL,
type varchar(6) NOT NULL,
notes varchar(512),
receipt int(10),
)
I get the following error message:
#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 ') NOT NULL, type varchar(6) NOT NULL, notes varchar(512),
receipt int(10), ' at line 6**
Here is some info on what I'm working with
Server type: MySQL
Server version: 5.5.32 - MySQL Community Server(GPL)
phpMyAdmin: 4.0.4.1, latest stable version: 4.1.7
I've spent a day knocking my head against the wall over this and now I think its time to ask for help.I was wondering if anyone can tell me what I'm doing wrong?
Remove the comma
receipt int(10),
And also AUTO INCREMENT should be a KEY
double datatype also requires the precision of decimal places so right syntax is double(10,2)
One obvious thing is that you will have to remove the comma here
receipt int(10),
but the actual problem is because of the line
amount double(10) NOT NULL,
change it to
amount double NOT NULL,
In MySQL, the word 'type' is a Reserved Word.
I see two problems:
DOUBLE(10) precision definitions need a total number of digits, as well as a total number of digits after the decimal:
DOUBLE(10,8)
would make be ten total digits, with 8 allowed after the decimal.
Also, you'll need to specify your id column as a key :
CREATE TABLE transactions(
id int NOT NULL AUTO_INCREMENT,
location varchar(50) NOT NULL,
description varchar(50) NOT NULL,
category varchar(50) NOT NULL,
amount double(10,9) NOT NULL,
type varchar(6) NOT NULL,
notes varchar(512),
receipt int(10),
PRIMARY KEY(id) );
I've faced this problem before, the reason behind that for me was the last comma in the schema definition should be deleted if there's no extra columns would be added.
CREATE TABLE users
(
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL, // this comma should be deleted
);
Rule 1: You can not add a new table without specifying the primary key constraint[not a good practice if you create it somehow].
So the code:
CREATE TABLE transactions(
id int NOT NULL AUTO_INCREMENT,
location varchar(50) NOT NULL,
description varchar(50) NOT NULL,
category varchar(50) NOT NULL,
amount double(10,9) NOT NULL,
type varchar(6) NOT NULL,
notes varchar(512),
receipt int(10),
PRIMARY KEY(id));
Rule 2: You are not allowed to use the keywords(words with predefined meaning) as a field name.
Here type is something like that is used(commonly used with Join Types).
So the code:
CREATE TABLE transactions(
id int NOT NULL AUTO_INCREMENT,
location varchar(50) NOT NULL,
description varchar(50) NOT NULL,
category varchar(50) NOT NULL,
amount double(10,9) NOT NULL,
transaction_type varchar(6) NOT NULL,
notes varchar(512),
receipt int(10),
PRIMARY KEY(id));
Now you please try with this code.
First check it in your database user interface(I am running HeidiSQL, or you can try it in your xampp/wamp server also)and make sure this code works. Now delete the table from your db and execute the code in your program.
Thank You.

What am I missing? MySQL syntax error

I am having this 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 ''tablename'(
'id'MEDIUMINT NOT NULL AUTO_INCREMENT,
'content'TEXT NOT NULL,
'd' at line 1
From this statement:
CREATE TABLE 'tablename'(
'id'MEDIUMINT NOT NULL AUTO_INCREMENT,
'content'TEXT NOT NULL,
'date_added' DATETIME NOT NULL,
'user' VARCHAR (16) NOT NULL,
PRIMARY KEY ('id'),
UNIQUE ('id')
); ENGINE=MyISAM;
Why?
You need the backtick instead of the single quote ('). The backtick is this character:
`
Better yet - don't bother with either:
CREATE TABLE tablename (
id MEDIUMINT ...
Important: also see the comments below from tadman; they round out this answer nicely by explaining the backticks and pointing out another syntax issue.
You are using incorrect notation.
In your create table statement, you are using the single quote ( ').
You can't use that here for table names and column names.
Alternatives would be the tick mark (`). Or just completely remove all notation altogether.
Here is your code, fully functional:
CREATE TABLE tablename (
`id` MEDIUMINT NOT NULL,
`content`TEXT NOT NULL,
`date_added` DATETIME NOT NULL,
`user` VARCHAR (16) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE (`id`)
);
You are missing a space between the columnname and the type of the first two columns. Also, you have a ; to many at the end
CREATE TABLE 'tablename'(
'id' MEDIUMINT NOT NULL AUTO_INCREMENT,
'content' TEXT NOT NULL,
'date_added' DATETIME NOT NULL,
'user' VARCHAR (16) NOT NULL,
PRIMARY KEY ('id'),
UNIQUE ('id')
) ENGINE=MyISAM;