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.
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 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/
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 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 8 years ago.
Improve this question
I'm getting this error while developing a javaEE application with MariaDB.
The error is:
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 'STARTING DATE, TITLE VARCHAR(255), CREATOR VARCHAR(255), LOCATION BIGINT, FORECA' at line 1
This is the problematic query:
CREATE TABLE EVENT
(
ID VARCHAR(255) NOT NULL,
DESCRIPTION VARCHAR(255),
ENDING DATE,
ISALLDAY TINYINT(1) default 0,
PUBLICEVENT TINYINT(1) default 0,
STARTING DATE,
TITLE VARCHAR(255),
CREATOR VARCHAR(255),
LOCATION BIGINT,
FORECAST BIGINT,
PRIMARY KEY (ID);
I can't figure out what is the problem...
You have a two typos:
STARTING - is a reserved word - use backticks
you forget closing parenthesis
This script should work:
CREATE TABLE EVENT
(
ID VARCHAR(255) NOT NULL,
DESCRIPTION VARCHAR(255),
ENDING DATE,
ISALLDAY TINYINT(1) default 0,
PUBLICEVENT TINYINT(1) default 0,
`STARTING` DATE,
TITLE VARCHAR(255),
CREATOR VARCHAR(255),
LOCATION BIGINT,
FORECAST BIGINT,
PRIMARY KEY (ID)
);
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 8 years ago.
Improve this question
CREATE TABLE IF NOT EXISTS ax_storage
(PID INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(PID),
Playername VARCHAR(32),
Time INT(10), Type INT(6),
World VARCHAR(32);
What is wrong with this SQL statement?
You are missing to close a paranthesis at the end of the query
CREATE TABLE IF NOT EXISTS ax_storage
(
PID INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(PID), Playername VARCHAR(32),
Time INT(10),
Type INT(6),
World VARCHAR(32)
); -- <- you were missing this one
you forgot ) in the end of query
CREATE TABLE IF NOT EXISTS ax_storage (PID INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(PID), Playername VARCHAR(32), Time INT(10), Type INT(6), World VARCHAR(32));