Error near 'BIT' when attempting to create MySql Table - mysql

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 'BIT)' at line 1
SQL:
CREATE TABLE Clients (ID nvarchar(36), Primary BIT)
I have also tried bit(1) and tinyint(1). any Ideas?

the word 'Primary' is reserved for indicating whether a column is a primary key. You need to pick a different column name.

Missing semi colon at the end.

Related

Table named 'Index'

I have a table named 'Index'. I realize that this is a keyword in MySQL, and was wondering how I can reference this table in queries?
My error:
#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 ''Index' (ID) )' at line 9
Use backticks:
references `Index` (ID)
You actually already did this when you created the Index table (and you must have used backticks or else you could not have created the table):
CREATE TABLE `Index`
You should avoid naming databases, tables, and columns using MySQL keywords.
you can use backticks instead of quotes
CONSTRAINT grants_fk_index
FOREIGN KEY (Index_fk)
references `Index` (ID)

mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL

Could someone please tell me why I am getting this error and what I should change!
mysql_exceptions.ProgrammingError: (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 'ORDER int,\n
FOREIGN KEY (ID) REFERENCES papers(ID),\n PRIMARY K' at line
4")
This is my statement:
""" CREATE TABLE Authors (
ID int NOT NULL,
AUTHOR varchar(255),
ORDER int,
FOREIGN KEY (ID) REFERENCES papers(ID),
PRIMARY KEY (ID, ORDER)
) """
Thank you I am new to sql and simply cannot spot where I have gone wrong!
"ORDER" is a reserved word and cannot be used as a field name...
Select * from Author order by order;
https://dev.mysql.com/doc/refman/5.5/en/keywords.html
If you absolutely want to use order as a field name, you must quote it, but it is better to avoid it, since you also would need to quote it in any sql sentence refering it.

MySQL "ALTER IGNORE TABLE" Error In Syntax

I am trying to run the query:
ALTER IGNORE TABLE test_table DROP PRIMARY KEY, ADD PRIMARY KEY(id);
test_table is just a temporary table I'm using for testing purposes, and id is a column in it.
The query works fine without the "IGNORE" key word, but when I add it I get the error message:
"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 'IGNORE TABLE test_table ADD PRIMARY KEY(id)' at line 1"
How do I fix this? Or how can I run that query and ignore any errors that might occur? Thanks!
As of MySQL 5.7.4, the IGNORE clause for ALTER TABLE is removed and its use produces an error. Please check your version

Tracking down basic 1064 Error

I'm working through the head first SQL book using MySQL and am encountering an error when trying to run the code in the book. I'm sure the error is very obvious but it has me stumped. The idea is to add a primary key to the table project_list by changing the name of a current column and setting it as a primary key.
ALTER TABLE project_list
CHANGE COLUMN number proj_id INT NOT NULL AUTO_INCREMENT,
ADD PRIMARY KEY ('proj_id');
Error message:
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 ''proj_id')' at line 3.
ADD PRIMARY KEY ('proj_id')
is attempting to set the primary key to a literal string rather than a column. You should either use proj_id on it's own:
... ADD PRIMARY KEY (proj_id);
or the back-tick version (with ` rather than '):
... ADD PRIMARY KEY (`proj_id`);

How to add named not null constraint

I am trying to add a NOT NULL constraint by the name 'NN_Grade' in existing column 'grade'.
but not able to do getting error -
My question is -
Add a constraint (NN_Grade) in table Empl that declares column Grade NOT NULL.
My Command which I tried-
ALTER TABLE students ADD CONSTRAINT NN_Grade NOT NULL(adm_no);
Error -
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 'NOT NULL(adm_no)' at line 1
Need guidance
ALTER TABLE students ADD CONSTRAINT NN_Grade CHECK (adm_no IS NOT NULL);
Why not just make the column not nullable, i.e.
ALTER TABLE Empl MODIFY Grade *TYPE* NOT NULL;
SqlFiddle here
Note that your question mentions table Empl whereas your answer uses students