First and foremost, I am a total novice when it comes to SQL, and I'm trying to build a database for my web design course. Having tried a thorough google search and exploring some of the answers here, I'm still no closer to figuring out what my problem is. The error that keeps getting thrown out is the title of this question, but this is the code I have so far:
Table structure for table `members`
create database glasgowboys;
use glasgowboys;
CREATE TABLE `members`
(`ID` int(11) NOT NULL AUTO_INCREMENT,
`Email` varchar(255) NOT NULL,
`Password` varchar(50) NOT NULL,
`FirstName` varchar(255) NOT NULL,
`LastName` varchar(255) NOT NULL,)
ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
I've been through several similar questions on stackoverflow, following their advice on replacing quotes with backticks, but with no luck.
When using auto_increment, make the field primary key. Also, remove the extra , after the last field definition.
Try this:
CREATE TABLE `members`
(`ID` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`Email` varchar(255) NOT NULL,
`Password` varchar(50) NOT NULL,
`FirstName` varchar(255) NOT NULL,
`LastName` varchar(255) NOT NULL)
ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Around table or field names, you must put "[]", not "'" and certainly not "`".
This should be
CREATE TABLE members
([ID] int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
[Email] varchar(255) NOT NULL,
[Password] varchar(50) NOT NULL,
[FirstName] varchar(255) NOT NULL,
[LastName] varchar(255) NOT NULL)
ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
(Maybe still not exactly correct, I only have Sql Server for testing around just now)
Related
newbie and appreciate your help.
So I have the below employee table with emp_id as primary and auto incremental. I would like to avoid users from inserting new record when the combination of first_name and last_name already exists.
I am connecting the DB to windows from (VB.net), ultimately I would like to display a message saying that the user's first and last name already exists. I could do it progrmaticly by vb code, however i am wondering if I can setup this check at the database level.
CREATE TABLE `employee` (
`emp_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`first_name` varchar(20) NOT NULL,
`middle_name` varchar(30) DEFAULT NULL,
`last_name` varchar(20) NOT NULL,
`date_of_birth` varchar(45) NOT NULL,
`gender` char(6) NOT NULL,
PRIMARY KEY (`emp_id'),
UNIQUE KEY `employee_id_UNIQUE` (`emp_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8
You can make constraints on sets of columns like this:
CREATE TABLE `employee` (
`emp_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`first_name` varchar(20) NOT NULL,
`middle_name` varchar(30) DEFAULT NULL,
`last_name` varchar(20) NOT NULL,
`date_of_birth` varchar(45) NOT NULL,
`gender` char(6) NOT NULL,
PRIMARY KEY (`emp_id'),
UNIQUE KEY `employee_name_UNIQUE` (`first_name`, `last_name`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8
That means if the combination of first_name and last_name already exists in the database, if you try to insert a new row with the same values, it results in a duplicate key error.
You need to write code in your application to handle that error, and then display an appropriately helpful message to the user.
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
)
I'm new to sql, currently I am using phpMyAdmin via XAMP, I think that uses mysql so correct me if I'm wrong by saying that. Anywhos, I'm trying to import a schema.sql data file into my database I created called "test" but I got an error upon importing it:
It says
Import has been successfully finished, 1 queries executed.
(schema.sql)
But then it also gives me an error message:
CREATE TABLE `population` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`location` varchar(150) NOT NULL,
`slug` varchar(150) NOT NULL,
`population` int(10) unsigned NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
MySQL said: Documentation
1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key
and :
Notice in .\import.php#704 Undefined variable: import_text Backtrace
I'm not sure what the issue is. The database I created is completely and has nothing in it.
Column id is the auto-column in question; auto-columns need to be defined as a key, for example as a unique key or a primary key. In your case, a primary key is a good idea because - well, it's your id-column.
CREATE TABLE `population` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`location` varchar(150) NOT NULL,
`slug` varchar(150) NOT NULL,
`population` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
I am trying to make a table but every time I type my sql code I get an error "Missing value in form". I am sure there is no problem with the code rather something else.
Here is my code
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`),
UNIQUE KEY `email` (`email`)
)
ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
I have the default User model in django as per below:
delimiter $$
CREATE TABLE `auth_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(30) NOT NULL,
`first_name` varchar(30) NOT NULL,
`last_name` varchar(30) NOT NULL,
`email` varchar(75) NOT NULL,
`password` varchar(128) NOT NULL,
`is_staff` tinyint(1) NOT NULL,
`is_active` tinyint(1) NOT NULL,
`is_superuser` tinyint(1) NOT NULL,
`last_login` datetime NOT NULL,
`date_joined` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=latin1$$
I tried to add full text searching by alter table 'auth_user' add fulltext(first_name), last_name, email), and I keep getting the error Error Code: 1214. The used table type doesn't support FULLTEXT indexes. Is there a reason why this doesn't support full text searching? I'm thinking it may be because I extended the model and added my own table?
Fulltext indices only work on MyISAM tables, and yours is InnoDB. source
You may want to use Django-Sphinx for full text search or look at their implementation. https://github.com/dcramer/django-sphinx