Error in Create Table Syntax MYSQL - mysql

This is my create table syntax:
Create table Recipe(
Recipename varchar(30),
Cuisine varchar(20),
Skilllevel varchar(13),
Ingredients varchar(400),
Procedure varchar(1000),
Cookingtime int(30),
Category varchar(10),
Restrictions varchar(15)
);
I'm not able to identify the error in this. Please do help. Thanks

Procedure is a reserved word. Need another name or surround it with backticks.

INT doesn't need a (30) value + you cant use word Procedure. Changed it to Procedures
Create table Recipe(
Recipename varchar(30),
Cuisine varchar(20),
Skilllevel varchar(13),
Ingredients varchar(400),
Procedures varchar(1000),
Cookingtime int,
Category varchar(10),
Restrictions varchar(15));

Looks like Isaiah answered your question but I wanted to add: depending on what kind of format you want the Cookingtime to be in, you could use the time datatype for long cook times (several hours) or keep using int if you are using minutes.

Related

How to create a Generated Column in MYSQL Version(6.0.11-alpha-community)

I create a table with Generated Column in MYSQL Version(6.0.11-alpha-community)
Like below I modified the structure of the Generated Column
One :
CREATE TABLE tbl_MAE_Customers(
ID INT AUTO_INCREMENT PRIMARY KEY,
CustomerName VARCHAR(30),
PhoneNmbr VARCHAR(15),
Email VARCHAR(30),
TCSShares INT,
InfosysShares INT,
TechmShares INT,
TotalShares INT GENERATED ALWAYS AS (TCSShares+InfosysShares+TechmShares),
Remarks VARCHAR(200)
)
Two :
CREATE TABLE tbl_MAE_Customers(
ID INT AUTO_INCREMENT PRIMARY KEY,
CustomerName VARCHAR(30),
PhoneNmbr VARCHAR(15),
Email VARCHAR(30),
TCSShares INT,
InfosysShares INT,
TechmShares INT,
TotalShares INT AS (TCSShares+InfosysShares+TechmShares),
Remarks VARCHAR(200)
)
Third :
CREATE TABLE tbl_MAE_Customers(
ID INT AUTO_INCREMENT PRIMARY KEY,
CustomerName VARCHAR(30),
PhoneNmbr VARCHAR(15),
Email varchar(30),
TCSShares int,
InfosysShares int,
TechmShares int,
TotalShares as (TCSShares+InfosysShares+TechmShares),
Remarks varchar(200)
)
This many ways I try to modify the structure of the Generated Column and when I execute the query I'm getting this below error:
Query: CREATE TABLE tbl_MAE_Customers(ID INT AUTO_INCREMENT PRIMARY KEY, CustomerName VARCHAR(30), PhoneNmbr VARCHAR(15), Email varchar...
Error Code: 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 'GENERATED ALWAYS as (TCSShares+InfosysShares+TechmShares), Remarks varchar(200))' at line 2
Execution Time : 0 sec
Transfer Time : 0 sec
Total Time : 0.001 sec
I'm new to MYSQL.
Suggest me how to achieve this with out an any error.
You're using an alpha version of MySQL 6.0 from May 2009. The 6.0 branch never made it out of alpha status. It was canceled because of code performance issues. It's honestly surprising you could even find a copy of it!
Further development of MySQL continued, but the version became 5.6. I know it's confusing, but 5.6 is more advanced than 6.0. But even 5.6 is so old now that it is past its end of life.
The GENERATED syntax for expression columns was introduced in MySQL 5.7. MySQL 6.0 and 5.6 do not support generated columns. You will have to use a current version to get support for that feature.

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)

Error in creating tables using 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>

SQL query doesn't work?

I want to create a table in the database and below is the query that I wrote; does anyone have any idea why it doesn't work?
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 'sname varchar(255), city varchar(255), avg int(20), clg# int(20) )' at line 4`
CREATE TABLE stud
(
s# int,
sname varchar(255),
city varchar(255),
avg int(20),
clg# int(20)
);
The # is not a valid character for an identifier. Just remove it:
CREATE TABLE stud (
s int,
sname varchar(255),
city varchar(255),
avg int(20),
clg int(20)
);
You can review the rules for identifiers here. Note you could also put the name in backticks:
`s#` int,
However, I strongly discourage you from using names that need to be escaped.
You cannot use the '#' character in column names.
you cant have # in your table names, change your script to this one and try again.
CREATE TABLE stud ( s int,
sname varchar(255),
city varchar(255),
avg int(20),
clg int(20) );
It's not recommended to use '#' to name your identifiers. This is ambiguous for you and other developers on your team. Use this instead
CREATE TABLE stud (
sNo int,
sname varchar(255),
city varchar(255),
avg int(20),
clgNo int(20)
);
By naming your identifiers descriptively it easier for everyone to understand. However mysql qouted identifier naming rules allow ASCII: U+0001 .. U+007F
see here.
MySQL Schema object naming Rules

SQL Server throwing errors on Drop

I am trying to create a database in SQL Server but it keeps throwing errors. Could you look at the script and see if I am messing it up somehow?
drop database if exists cptc;
create database cptc;
use cptc;
drop table if exists staff;
create table staff (
staffID int not null auto_increment,
fname varchar(25),
lname varchar(25),
title varchar(50),
phone varchar(10),
building varchar(10),
room varchar(10),
PRIMARY KEY(staffID),
FULLTEXT (fname,lname)
)ENGINE = MYISAM;
INSERT INTO staff VALUES ('','michael','herrera','doctor','2539703420','B14','122');
INSERT INTO staff VALUES ('','holly','herrera','teacher','2534667896','B35','116');
INSERT INTO staff VALUES ('','jesse','kirsch','professor','2534567890','B12','112');
INSERT INTO staff VALUES ('','mark','wahlberg','professor','5552345678','B01','112');
INSERT INTO staff VALUES ('','philip','spears','technician','2065672345','B12','123');
INSERT INTO staff VALUES ('','andrew','jackson','teacher','2061234567','B32','101');
INSERT INTO staff VALUES ('','annie','smith','mechanic','2533345609','B23','102');
INSERT INTO staff VALUES ('','alfred','hills','teacher','2535821513','B14','103');
INSERT INTO staff VALUES ('','bobby','jones','nurse','5559876056','B10','104');
INSERT INTO staff VALUES ('','tiffany','jones','janitor','2539981265','B02','108');
UPDATE: I think I was having Errors because it is MySQL and NOT SQL. Thanks everyone For Your (Really Quick) Answers!
This part is MYSQL not SQL Server ENGINE = MYISAM;
here is what the table would look like in SQL Server (sans the fulltext index, you first need to enable fulltext search in order to create a full text index))
create table staff (
staffID int not null identity,
fname varchar(25),
lname varchar(25),
title varchar(50),
phone varchar(10),
building varchar(10),
room varchar(10),
PRIMARY KEY(staffID)
)
The drop and create database will look like this
USE [master]
GO
IF EXISTS (SELECT name FROM sys.databases
WHERE name = N'cptc')
DROP DATABASE cptc
GO
CREATE DATABASE [cptc]
The drop table will look like this
IF EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'staff') AND type in (N'U'))
DROP TABLE staff
GO
Finally, you need to ommit the column for the identity while inserting, example
INSERT INTO staff VALUES ('michael','herrera','doctor','2539703420','B14','122');
If you don't ommit the column, you will get the following error
Msg 8101, Level 16, State 1, Line 1
An explicit value for the identity column in table 'staff' can only be specified when a column list is used and IDENTITY_INSERT is ON.
auto_increment should be identity(1,1)
ENGINE = MYISAM; doesnt exist what do you expect with it?
FULLTEXT (fname, lname) is not correct. What do you want, implement full text serach?
The question was not clear. You were creating a table not database.
It would be helpful if you provide the actual error detail.
BTW, you shouldn't put any value for the autoincrement column which will be assigned by server automatically. I guess this was causing the issue.