Sql creation format - mysql

How would one format the following sql file in a way that would work and keep the current values;
delimiter $$
CREATE TABLE "login" (
"IdUser" int(11) NOT NULL AUTO_INCREMENT,
"username" varchar(45) CHARACTER SET latin1 NOT NULL,
"pass" varchar(45) CHARACTER SET latin1 NOT NULL,
PRIMARY KEY ("IdUser")
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8$$
CREATE TABLE "photos" (
"IdPhoto" int(11) NOT NULL AUTO_INCREMENT,
"title" varchar(100) CHARACTER SET latin1 NOT NULL,
"IdUser" int(11) NOT NULL,
PRIMARY KEY ("IdPhoto")
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8$$
I get the following error when I try to create it from my mac terminal
"'ERROR 1064 (42000) at line 3: 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 '"login" (
"IdUser" int(11) NOT NULL AUTO_INCREMENT,
"username" varchar(45) C' at line 1
"

use this. Fiddler Demo
CREATE TABLE login (
IdUser int(11) NOT NULL AUTO_INCREMENT,
username varchar(45) CHARACTER SET latin1 NOT NULL,
pass varchar(45) CHARACTER SET latin1 NOT NULL,
PRIMARY KEY (IdUser)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE photos (
IdPhoto int(11) NOT NULL AUTO_INCREMENT,
title varchar(100) CHARACTER SET latin1 NOT NULL,
IdUser int(11) NOT NULL,
PRIMARY KEY (IdPhoto)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

CREATE TABLE login (//"login" is incorrect syntex
IdUser int(11) NOT NULL AUTO_INCREMENT, // Dont give "" to Column name
username varchar(45) CHARACTER SET latin1 NOT NULL,
pass varchar(45) CHARACTER SET latin1 NOT NULL,
PRIMARY KEY (IdUser)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8$$
CREATE TABLE photos (//"photos" is incorrect syntex
IdPhoto int(11) NOT NULL AUTO_INCREMENT,
title varchar(100) CHARACTER SET latin1 NOT NULL,
IdUser int(11) NOT NULL,
PRIMARY KEY (IdPhoto)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFA

Related

#1273 - Unknown collation: 'utf 32 croatian ci' how solve this error in phpmyadmin wamp server

my create table code is
CREATE TABLE IF NOT EXISTS `current_sabhay` (
`current_id` int(11) NOT NULL AUTO_INCREMENT,
`year_id` int(11) NOT NULL,
`parment_id` int(11) NOT NULL,
`photo` varchar(225) NOT NULL,
`desc` varchar(225) CHARACTER SET utf32 COLLATE utf32_croatian_ci NOT NULL,
PRIMARY KEY (`current_id`,`parment_id`),
KEY `year_id` (`year_id`),
KEY `current_sabhay_ibfk_2` (`parment_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

Creating table mySQL syntax error

I am trying to run the following query in PHP my admin:
CREATE TABLE IF NOT EXISTS 'ibn_table' (
'id' int(11) NOT NULL AUTO_INCREMENT,
'itransaction_id' varchar(60) NOT NULL,
'ipayerid' varchar(60) NOT NULL,
'iname' varchar(60) NOT NULL,
'iemail' varchar(60) NOT NULL,
'itransaction_date' datetime NOT NULL,
'ipaymentstatus' varchar(60) NOT NULL,
'ieverything_else' text NOT NULL,
PRIMARY KEY ('id')
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
I get 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 ''ibn_table' ( 'id' int(11) NOT NULL AUTO_INCREMENT, 'itransaction_id' varchar(' at line 1
Any help is appreciated.
use backtick for quoting columns and table names
mysql> CREATE TABLE IF NOT EXISTS `ibn_table` (
-> `id` int(11) NOT NULL AUTO_INCREMENT,
-> `itransaction_id` varchar(60) NOT NULL,
-> `ipayerid` varchar(60) NOT NULL,
-> `iname` varchar(60) NOT NULL,
-> `iemail` varchar(60) NOT NULL,
-> `itransaction_date` datetime NOT NULL,
-> `ipaymentstatus` varchar(60) NOT NULL,
-> `ieverything_else` text NOT NULL,
-> PRIMARY KEY (`id`)
-> ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Query OK, 0 rows affected (0.12 sec)
The column names should be in Backticks or just remove quotes. Backticks are to be used for table and column identifiers, but are only necessary when the identifier is a MySQL reserved keyword, or when the identifier contains whitespace characters or characters beyond a limited set (see below) It is often recommended to avoid using reserved keywords as column or table identifiers when possible, avoiding the quoting issue.
Try this:
CREATE TABLE `ibn_table` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`itransaction_id` VARCHAR(60) NOT NULL,
`ipayerid` VARCHAR(60) NOT NULL,
`iname` VARCHAR(60) NOT NULL,
`iemail` VARCHAR(60) NOT NULL,
`itransaction_date` DATETIME NOT NULL,
`ipaymentstatus` VARCHAR(60) NOT NULL,
`ieverything_else` TEXT NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MYISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Creating tables in PhpMyAdmin - error 1064

The code:
delimiter $$
CREATE TABLE "login" (
"IdUser" int(11) NOT NULL AUTO_INCREMENT,
"username" varchar(45) CHARACTER SET latin1 NOT NULL,
"pass" varchar(45) CHARACTER SET latin1 NOT NULL,
PRIMARY KEY ("IdUser")
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8$$
CREATE TABLE "photos" (
"IdPhoto" int(11) NOT NULL AUTO_INCREMENT,
"title" varchar(100) CHARACTER SET latin1 NOT NULL,
"IdUser" int(11) NOT NULL,
PRIMARY KEY ("IdPhoto")
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8$$
Errors:
#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 '"login" (
"IdUser" int(11) NOT NULL AUTO_INCREMENT,
"username" varchar(45)' at line 1
#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 '"photos" ( "IdPhoto" int(11) NOT NULL AUTO_INCREMENT, "title" varchar(100)' at line 1
Any ideas? I'm brand new to this so any help would be very much appreciated.
Use backticks like this ` instead of double quotes throughout
For example:
`IdUser` int(11) NOT NULL AUTO_INCREMENT,
You can use double quotes in identifiers only if the ANSI_QUOTES SQL mode is enabled.
SET sql_mode='ANSI_QUOTES';
Here is SQLFiddle demo
Otherwise just use back ticks or nothing at all if your identifiers are not in a reserved words list.
CREATE TABLE `login` (
`IdUser` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(45) CHARACTER SET latin1 NOT NULL,
`pass` varchar(45) CHARACTER SET latin1 NOT NULL,
PRIMARY KEY (`IdUser`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
;
CREATE TABLE `photos` (
`IdPhoto` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(100) CHARACTER SET latin1 NOT NULL,
`IdUser` int(11) NOT NULL,
PRIMARY KEY (`IdPhoto`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8
;
Here is SQLFiddle demo
Further reading Schema Object Names
you should use backticks ` not double quotes "
like that.
CREATE TABLE `login` (
same for other columns.

incomprehensible error on this simple create table query

I've just exported the CREATE sql of a singular table using phpmyadmin. this is the result:
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`register_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`account_type` int(11) NOT NULL,
`active` int(11) NOT NULL,
`email` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`login` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`password` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`name` varchar(200) COLLATE utf8_unicode_ci NOT NULL
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
But when i run this code on the very phpmyadmin i receive 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 '(`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREME' at line 14
I have tried many ways, but my skills aren't enough.
You forgot to add comma before PRIMARY KEY (id)
`name` varchar(200) COLLATE utf8_unicode_ci NOT NULL, -- <== this
PRIMARY KEY (`id`)
add comma and it will work, see this fiddle (click link)

mysql error 1064

Im trying to create a table with this code:
CREATE TABLE IF NOT EXISTS `entries` (
`id` int(10) NOT NULL auto_increment,
`atom_id` varchar(512) NOT NULL,
`title` varchar(256) NOT NULL,
`author` varchar(128) NOT NULL,
`link` varchar(512) NOT NULL,
`content` longtext NOT NULL,
`updated` varchar(25) NOT NULL,
`inserted` varchar(25) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `atom_id` (`atom_id`),
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `topics` (
`id` int(10) NOT NULL auto_increment,
`status` varchar(32) NOT NULL,
`hub` varchar(512) NOT NULL,
`topic` varchar(512) NOT NULL,
`lease` varchar(25) NOT NULL,
`secret` varchar(256) NOT NULL,
`token` varchar(40) NOT NULL,
`date` varchar(25) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
but i got 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 ') ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1' at line 12
I can't figure what's going on, any advice?
Remove the comma after UNIQUE KEY 'atom_id' ('atom_id'), in line 11
UNIQUE KEY `atom_id` (`atom_id`),
^
Try losing the ","