Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Creating tables in MySQL confuses me. Sometimes I'm able to get it just fine, other times it seems to yell at me for things I've done before successfully. I'm attempting to create this table with 3 columns. When I try to save the column, it tells me to please enter a valid length. I've used these lengths on these column types before, so why is it yelling at me now? I'm using a form on MySQL, so I don't know the actual SQL syntax for this, but the following is what I'm trying to do.
Create Table: Families
(
`Id` Int(11) Auto_Incriment Primary Key,
`Family` CHAR (255) Unique,
`Species` CHAR (255),
);
Why is it telling me to enter a valid length?
Remove the : after table and the , before the last ) and you misspelled auto_increment
Create Table Families
(
`Id` Int(11) auto_increment Primary Key,
`Family` CHAR (255) Unique,
`Species` CHAR (255)
);
You could "debug" such things on your own if you use a SQL tool that highlights such erros like MySQL Workbench.
Modify It as follow:
Create Table Families
(
`Id` Int(11) AUTO_INCREMENT Primary Key,
`Family` CHAR (255) Unique,
`Species` CHAR (255)
);
You should create a sql query that looks something like this, also make sure you spell attributes correctly:
Create Table: Families
(
`Id` Int(11) AUTO_INCREMENT Primary Key,
`Family` CHAR (255) Unique,
`Species` CHAR (255),
);
In the future please use the mysql guide in this link:
http://dev.mysql.com/doc/refman/5.6/en/
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I got this MySQL error 1064:
# 1064 - Something is wrong in your syntax near '' accesslogh '(
id INT (30) PRIMARY KEY AUTO_INCREMENT NOT NULL,
nam ... 'on line 1
When i ran
CREATE TABLE 'accesslogh' (
id INT(30) PRIMARY KEY AUTO_INCREMENT NOT NULL,
name VARCHAR(255),
result VARCHAR(255),
type VARCHAR(255),
code VARCHAR(255),
epoch INT(30),
timestamp DATE DEFAULT CURRENT_TIMESTAMP);
I know it is a syntax error but I have tried to solve it following the correct theory but I can't solve it.
Remove quotes around table name.
CREATE TABLE accesslogh (
id INT(30) PRIMARY KEY AUTO_INCREMENT NOT NULL,
name VARCHAR(255),
result VARCHAR(255),
type VARCHAR(255),
code VARCHAR(255),
epoch INT(30),
timestamp DATE DEFAULT CURRENT_TIMESTAMP);
You are confusing the backtick ` with the single quote '. In SQL the single quote is used for string literals, in specifically MySQL the backtick is used to denote a quoted identifier, to allow you to use special characters, white space and reserved words for identifiers. What you probably intended to do was this:
CREATE TABLE `accesslogh` (
id INT(30) PRIMARY KEY AUTO_INCREMENT NOT NULL,
name VARCHAR(255),
result VARCHAR(255),
type VARCHAR(255),
code VARCHAR(255),
epoch INT(30),
timestamp DATE DEFAULT CURRENT_TIMESTAMP);
While it's not needed for your example it's a good practice to get into if your queries are going to be generated in some other code.
This really only applies to MySQL, other SQL DBMS tend to use square brackets [ ] to enclose identifiers that use reserved words or characters not otherwise allowed.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
CREATE TABLE demos
(id INT UNSIGNED AUTO_INCREMENT PRIMARY_KEY
first_name VARCHAR NOT NULL
last_name VARCHAR NOT NULL
hometown VARCHAR NOT NULL)
You have an error in your SQL syntax; check the manual that corresponds to
your MariaDB server version for the right syntax to use near 'first_name
VARCHAR NOT NULL last_name VARCHAR NOT NULL hometown VARCHAR NOT...' at line 3
You need to
separate the field definitions with commas;
PRIMARY KEY should be two words separated by a space, not joined with an underscore;
VARCHAR fields need to have a length specified
The following works fine with both MySQL (which you said you're using) and MariaDB (which the error message says you're using):
CREATE TABLE demos
(id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(10) NOT NULL,
last_name VARCHAR(10) NOT NULL,
hometown VARCHAR(10) NOT NULL)
db<>fiddle here
You need to add commas after each field in your table, like so:
CREATE TABLE demos (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(10) NOT NULL,
last_name VARCHAR(10) NOT NULL,
hometown VARCHAR(10) NOT NULL
);
EDIT: As the other answer suggests, you also need to specify the default VARCHAR size and separate the keywords PRIMARY and KEY
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Gotta love when you get descriptive errors like
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax
Can anyone here give me any more of an idea of where I'm going wrong with
CREATE TABLE wp_nas_coffees (id MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR (100), email VARCHAR (100), company VARCHAR (100), dtime TIMESTAMP DEFAULT CURRENT_TIMESTAMP, order VARCHAR (20));
???
order is Mysql reserver word
CREATE TABLE wp_nas_coffees (
id MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR (100),
email VARCHAR (100),
company VARCHAR (100),
dtime TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
tbl_order VARCHAR (20)
);
See MySQL keywords/reserved words
https://dev.mysql.com/doc/refman/5.6/en/keywords.html
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm working on a database for my database class.
I have been trying to change the INT from SUBJECT_ID to VARCHAR.
This is the code I have been using but it keeps giving me errors:
ALTER TABLE COURSE
ALTER COLUMN SUBJECT_ID VARCHAR(11);
I also tried this:
SELECT CONVERT(VARCHAR(11),SUBJECT_ID) FROM COURSE;
and this is the table I'm working with:
CREATE TABLE COURSE
(COURSE_ID INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
SUBJECT_ID INT(11) NOT NULL,
COURSE_GRADE_LEVEL CHAR(2) NOT NULL,
FAC_ID INT NOT NULL,
FOREIGN KEY(FAC_ID) REFERENCES FACULTY(FAC_ID));
Any suggestions will be appreciated. Thanks.
Try:
ALTER TABLE COURSE MODIFY SUBJECT_ID VARCHAR(11);
select cast(subject_id as varchar(11)) as subject_id_str from course
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I'm new to this website so let me know if I'm doing something wrong.
I'm trying to make a system where every time a value is inserted into the table, it's given an ID. So the first one would be 21, next one 22, 23, and so on.
I'm fairly new at SQL so I threw this together hoping it'd work, and I figured I'd come here and ask for some help.
This is what I thought up:
CREATE TABLE _increment
(
ID int NOT NULL AUTO_INCREMENT,
user_id varchar(255) NOT NULL,
group_id varchar(255),
alias varchar(255),
notes varchar(255),
value varchar(255),
hash varchar(255),
function_id varchar(255),
PRIMARY KEY (ID)
)
INSERT INTO _increment
(`user_id`, `group_id`, `alias`, `hash`, `function_id`, `value`, `disabled`)
VALUES ('262', NULL, NULL, 'john', 'wewbsite.ca/', NULL, '0');
CREATE TABLE _increment
The main points were some syntax errors, namely a missing semicolon at the end of the CREATE TABLE statement
CREATE TABLE _increment
(
ID int NOT NULL AUTO_INCREMENT,
user_id varchar(255) NOT NULL,
group_id varchar(255),
alias varchar(255),
notes varchar(255),
value varchar(255),
hash varchar(255),
function_id varchar(255),
PRIMARY KEY (ID)
); -- this one was missing
and a wrong column name in the INSERT INTO statement
INSERT INTO _increment
(`user_id`, `group_id`, `alias`, `hash`, `function_id`, `value`, `notes`) -- not `disabled`
VALUES ('262', NULL, NULL, 'john', 'wewbsite.ca/', NULL, '0');
If one hasn't got a mysql server ready to experiment and learn then I can recommend sqlfiddle to test such statements.
I would use GO command after creating table (in SQL Server - I think there exists similar command in MySQL).
I see that in table definition you have NOTES column, but in INSERT INTO statement you have DISABLED column instead.