Error in creating tables using mysql? - mysql

I dont know what mistake i made in creating the following table?
create table users(Time int(11) not NULL,
userid text,group text,
jobs_running int(11),
jobs_pending int(11),
job_limit int(11),
run_failures int(11),
queues text,
ATP int(11),
pend_reasons int(11));

Just do a simple quotes and this will make your query run , no need to change your column name
Below is running query
Note
create table users(Time int(11) not NULL,userid text,`group` text,jobs_running int(11),jobs_pending int(11),job_limit int(11),run_failures int(11),queues text,ATP int(11),pend_reasons int(11));

This is general problem and many time generate when we use some mysql or any database management system related word like e.g. group, by, date etc for table field.
Here problem is you use "group" word for table field. You just need to backtick(`). please note below query:
create table users(Time int(11) not NULL,userid text,`group` text,jobs_running int(11),jobs_pending int(11),job_limit int(11),run_failures int(11),queues text,ATP int(11),pend_reasons int(11))

Rename the column name group to any other name. It's a keyword hence giving error.
Try this.
create table users(Time int(11) not NULL,
userid text,
groups text,
jobs_running int(11),
jobs_pending int(11),
job_limit int(11),
run_failures int(11),
queues text,
ATP int(11),
pend_reasons int(11));

Here is what Mimer SQL-2003 Validator said:
create table users(Time int(11) not NULL,userid text,group text,jobs_running
^---- ^---
int(11),jobs_pending int(11),job_limit int(11),run_failures int(11),queues
text,ATP int(11),pend_reasons int(11));
syntax error: Time
correction: <identifier>
syntax error: group
correction: <identifier>

Related

Getting error in my mysql code: You have an error in your SQL syntax

I am trying to solve error but i dont have any idea how to solve please help me.
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 'create table jobseeker(j_id first_name varchar(20),last_name varchar(20),phone_' at line 5
create table admin(primary key,admin_name varchar(20),admin_password varchar(20));
create table jobseeker(j_id int primary key,first_name varchar(20),last_name varchar(20),phone_no int(11),email_id varchar(20),address1 varchar(30), address2 varchar(30),qualification varchar(20),birthday_date date,gender varchar(10),field varchar(50),year of passing int(11), board varchar(20),zip int(11),city varchar(20),state varchar(20),username varchar(20),password varchar(20));
create table job seeker job(id int primary key,j_id int(10),c_name varchar(20),post varchar(20),foreign key references(j_id int foregin key references job seeker(id)));
create table company news(n_id int primary key,c_id int(11)primary key,information varchar(50),link varchar(50));
create table company(c_id int primary key,c_name varchar(20),phone_no int(11),address varchar(20),email_id varchar(20),password varchar(20));
Well, you have some errors, but as Bill Karwin said, run SQL statemets one at a time.
In your first statement you dont have a name and a type for your primary key.
create table admin(id int primary key,admin_name varchar(20),admin_password varchar(20));
In your second statement you have a column named 'year of passing'. It's not allowed, you should use underscore.
create table jobseeker(j_id int primary key,first_name varchar(20),last_name varchar(20),phone_no int(11),email_id varchar(20),address1 varchar(30), address2 varchar(30),qualification varchar(20),birthday_date date,gender varchar(10),field varchar(50),year_of_passing int(11), board varchar(20),zip int(11),city varchar(20),state varchar(20),username varchar(20),password varchar(20));
Again, check every statement and I recommend you to use some editor with syntax highlighting.
Because j_id did not have the data type. Which is int.
Also, the year of passing int(11) can not have spaces. Well, it can f that is what you really want to do. I will recomend you do not. Rather use underscore "_"
Write it like below if you need your spaces for your column name: year of passing` int(11)
create table jobseeker(
j_id int primary key,
first_name varchar(20),
last_name varchar(20),
phone_no int(11),
email_id varchar(20),
address1 varchar(30),
address2 varchar(30),
qualification varchar(20),
birthday_date date,
gender varchar(10),
field varchar(50),
`year of passing` int(11),
board varchar(20),
zip int(11),
city varchar(20),
state varchar(20),
username varchar(20),
password varchar(20)
);
notice that I also have spaces for year of passing, this is not recommended. I recommend that you one of the following for that column.
year_of_passing int(11)
or
yearOfPassing int(11)

Phpmyadmin sql command isn't working, what is wrong?

I tried to setup a table in my database:
CREATE TABLE products(
id INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255),
info TEXT,
price DOUBLE(10)
);
and got the error #1064, but I think there is no error in my SQL syntax.
This is due to Wrong Datatype specification while creating Table.
You can use FLOAT(10) if required, if you want to use Double, you have to mention the precision value as DOUBLE(10,0).

Issue Converting varchar to nvarchar mysql

Sorry if this is an easy question, I am coming to MySQL from SQL Server.
When I execute my create statement it contains nvarchar but commits to the database as varchar. Even in my alter statement afterwards the column does not change at all. Does the collation or DB engine make a difference?
During execution I am not encountering any issues in results, other than the fact the column changes datatype. I attached a screencast of my activity http://screencast.com/t/wc94oei2
I have not been able to find anyone with similar issues through my Google searches
Did you mean, this..
CREATE TABLE stars (
idstars int(11) NOT NULL AUTO_INCREMENT,
Name nvarchar(200) DEFAULT NULL,
PRIMARY KEY (idstars),
UNIQUE KEY Name_UNIQUE (Name)
)
----turns to---
CREATE TABLE stars (
idstars int(11) NOT NULL AUTO_INCREMENT,
Name varchar(200) DEFAULT NULL,
PRIMARY KEY (idstars),
UNIQUE KEY Name_UNIQUE (Name)
)

Mysql alter table error message

I am trying to alter MySQL table to add columns to the end of existing columns. But for some reasons MySQL does not like the query I am running.
Here is my query below.
alter table hdds add
hdd1 VARCHAR(100),
hdd2 VARCHAR(100),
hdd3 VARCHAR(100),
hdd4 VARCHAR(100),
hdd5 VARCHAR(50),
hdd6 VARCHAR(100),
hdd6 VARCHAR(100),
hdd7 VARCHAR(100),
hdd8 VARCHAR(100),
hdd9 VARCHAR(100),
hdd10 VARCHAR(100),
hdd11 VARCHAR(100),
hdd12 VARCHAR(100),
hdd13 VARCHAR(100),
hdd14 VARCHAR(100),
hdd15 VARCHAR(100),
hdd16 VARCHAR(100),
hdd17 VARCHAR(100),
hdd18 VARCHAR(100),
hdd19 VARCHAR(100),
after comments;
I am getting following error message.
#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 'hdd2 VARCHAR(100),
hdd3 VARCHAR(100),
hdd4 VARCHAR(100),
hdd5 ' at line 3
Don't know where I have gone wrong.
works like a charm:
create table t111
( id int auto_increment primary key,
comments varchar(1000) not null
);
alter table t111
add column hdd19 VARCHAR(100) after comments,
add column hdd18 VARCHAR(100) after comments,
add column hdd17 VARCHAR(100) after comments,
add column hdd16 VARCHAR(100) after comments,
add column hdd15 VARCHAR(50) after comments,
add column hdd14 VARCHAR(100) after comments,
add column hdd13 VARCHAR(100) after comments,
add column hdd12 VARCHAR(100) after comments,
add column hdd11 VARCHAR(100) after comments,
add column hdd10 VARCHAR(100) after comments,
add column hdd9 VARCHAR(100) after comments,
add column hdd8 VARCHAR(100) after comments,
add column hdd7 VARCHAR(100) after comments,
add column hdd6 VARCHAR(100) after comments,
add column hdd5 VARCHAR(100) after comments,
add column hdd4 VARCHAR(100) after comments,
add column hdd3 VARCHAR(100) after comments,
add column hdd2 VARCHAR(100) after comments,
add column hdd1 VARCHAR(100) after comments;
describe t111;
Plus you had a typo, trying to add hdd6 twice.
Edit:
I reversed the order of the columns from 19 to 1 so they all lined up after the comments bubbling them down (as seen in the describe t111;)
As I see it, you have 2 choices to line up the ordering visually after comments from 1 to 19.
1. You can do it the way I did, with 19 first after comments, then 18 after comments (shoving down 19 below it), then 17 after comments shoving down 18 and 19 ... 1 after comments shoving down 2 thru 19.
or
2. You can do it 1 thru 19, and have to modify the after comments chunk individually in the `comments part' and it would look like this:
create table t111
( id int auto_increment primary key,
comments varchar(1000) not null
);
alter table t11
add column hdd1 VARCHAR(100) after comments,
add column hdd2 VARCHAR(100) after hdd1,
add column hdd3 VARCHAR(100) after hdd2,
...
add column hdd19 VARCHAR(100) after hdd18;
I chose choice 1., maybe not the best and fastest, but it satisfied my thirst for bubble-down curiosity.
And all of this hinges on anyone caring in the least how they look, but in your case it probably should, since you have so many and error-prone.
NO, you can't add multiple columns like that in a single ALTER statement. That's wrong as it's not same as CREATE statement and so the error you are receiving. You will have to make it separate ALTER statement like
alter table hdds add hdd1 VARCHAR(100) after comments;
alter table hdds add hdd2 VARCHAR(100) after comments;

I have to write an SQL statement to create a table skill using DDL commands. the field description can be NULL and the default value is NULL

CREATE TABLE skill
(
id BIGINT(20),
description VARCHAR(255) DEFAULT NULL,
name VARCHAR(255),
PRIMARY KEY(id)
);
The portal says wrong answer. I don't understand what is wrong in this code.
After execution, it says'0 rows affected'.
DDL statements do not affect any records, they affect objects, so a successful execution of a DDL statement is expected to return "0 rows affected".
Your DDL seems correct, although explicitly stating default null is a tad overly robust. Many (most?) DBAs I've worked with would omit it and simply use something like this:
CREATE TABLE skill
(
id BIGINT(20),
description VARCHAR(255),
name VARCHAR(255),
PRIMARY KEY(id)
);
Try this.
CREATE TABLE skill
(
id BIGINT(20) NOT NULL,
description VARCHAR(255),
name VARCHAR(255),
PRIMARY KEY(id)
);
CREATE table skill
(
id BIGINT(20),
description varchar(255) NULL,
name varchar(255) NOT NULL,
primary key(id)
);
Please use the above query.