Table structure for table activity
CREATE TABLE IF NOT EXISTS `activity` (
`fnum` int(10) unsigned NOT NULL auto_increment,
`fid` int(25) default NULL,
`fdate` datetime default NULL,
`ftask` varchar(50) default NULL,
`username` varchar(255) NOT NULL default '',
PRIMARY KEY (`fnum`),
KEY `username` (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1204 ;
MySQL said:
1046 - No database selected
As the error says "1046 - No database selected". You should start your script with selecting a database. E.g.:
use my_database;
Related
i want to change database of my simple application from mysql to sqlite, this is my sql command :
CREATE TABLE `Todo` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`Title` varchar(255) DEFAULT NULL,
`Category` varchar(255) DEFAULT NULL,
`State` varchar(255) DEFAULT NULL,
PRIMARY KEY (`Id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
im try to create sqllite but return me this error : Error: near "AUTO_INCREMENT": syntax error how i can fix it ?
Instead of using primary key separately, please mention it with your AUTO INCREMENT key
CREATE TABLE `Todo` (
`Id` integer primary key AUTOINCREMENT,
`Title` varchar(255) DEFAULT NULL,
`Category` varchar(255) DEFAULT NULL,
`State` varchar(255) DEFAULT NULL
)
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
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(240) NOT NULL,
`email` varchar(240) NOT NULL,
`password` varchar(240) NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
Maybe the table name has something to do.I see that you chose the name "USERS".Perhaps is a reserved word!What database are you using?
Fixed the first part:
CREATE TABLE users(
id int NOT NULL IDENTITY(1,1) PRIMARY KEY,
name VARCHAR(240) NOT NULL,
email VARCHAR(240) NOT NULL,
password VARCHAR(240) NOT NULL)
..
.
.
I have the following query
CREATE TABLE grades_gra (
id_gra INT(11) NOT NULL AUTO_INCREMENT,
identifier_gra VARCHAR(2) DEFAULT NULL,
name_gra VARCHAR(250) DEFAULT NULL
PRIMARY KEY (id_gra)
)
ENGINE = INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=UTF8;
When I execute it, it gives me an error invalid default vale for 'naes_gra'
You forgot a comma before primary key:
CREATE TABLE grades_gra (
id_gra INT(11) NOT NULL AUTO_INCREMENT,
identifier_gra VARCHAR(2) DEFAULT NULL,
name_gra VARCHAR(250) DEFAULT NULL,
PRIMARY KEY (id_gra)
)
ENGINE = INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=UTF8;
SQLFiddle demo
Put the comma after DEFAULT NULL, before PRIMARY keyword
I'm having problems trying to create the following trigger:
CREATE TRIGGER loteria_loterias AFTER UPDATE ON loteria_loterias
FOR EACH ROW BEGIN
UPDATE
loteria_loterias l
JOIN loteria_tipos t
ON l.tipo = t.id
SET
NEW.fecha_fin = NEW.fecha_ini + interval t.duracion hour
WHERE c.cID=NEW.cID;
END
I have this definitions for the tables:
CREATE TABLE `loteria_loterias` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`tipo` int(11) unsigned NOT NULL,
`fecha_ini` datetime NOT NULL,
`fecha_fin` datetime DEFAULT NULL,
`ganador` varchar(60) CHARACTER SET utf8 DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `ganador` (`ganador`),
KEY `tipo` (`tipo`),
CONSTRAINT `loteria_loterias_ibfk_2` FOREIGN KEY (`tipo`) REFERENCES `loteria_tipos` (`id`),
CONSTRAINT `loteria_loterias_ibfk_1` FOREIGN KEY (`ganador`) REFERENCES `tegm_users` (`user_login`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=latin1
CREATE TABLE `loteria_tipos` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`nombre` varchar(60) NOT NULL,
`coste` int(11) NOT NULL,
`premio` int(11) NOT NULL,
`duracion` int(11) NOT NULL COMMENT '(en horas)',
`activa` tinyint(1) NOT NULL,
`x` int(11) NOT NULL COMMENT '(coordenadas del cartel)',
`y` int(11) NOT NULL COMMENT '(coordenadas del cartel)',
`z` int(11) NOT NULL COMMENT '(coordenadas del cartel)',
UNIQUE KEY `id` (`id`),
KEY `id_2` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
According to MySQL:
#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 9
You're missing the ON keyword:
CREATE TRIGGER loteria_loterias AFTER UPDATE ON loteria_loterias
^^