SQL Error 1062 Duplicate Entry [closed] - mysql

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 5 years ago.
Improve this question
I'm having an MYSQL error when someone registers, not everyone though, only for some users. Why is that?
Error:
SQL ERROR: 1062 Duplicate entry 'Fedot_Pulemiot' for key 'username'

To avoid duplicate entry we can add unique constrain to the column, sql as follows
ALTER TABLE `user` ADD UNIQUE(`user_name`);
But in your case i think already unique is set so drop the unique value as follows
ALTER TABLE tb_name DROP INDEX user_name;

Related

MYSQL Duplicate entry '0' for key Primary' [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am trying to move a MYSQL database from one computer to another.
I did a dump file on the computer with the database, I created the database on the second
computer and duplicated the table definitions and checked it make sure they are the same many times. When I use Load data infile I get the duplicate'0' key primary error.
I am using Windows 10 pro MYSQL 5.7.9
This error might indicate that the table's PRIMARY KEY is not set to auto-increment.
Solution:
Check that there is a PRIMARY KEY set on your table, and that the PRIMARY KEY is set to AUTO-INCREMENT.

Syntax error 1064 (42000) when adding foreign key in SQL [closed]

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 2 years ago.
Improve this question
I'm trying to add some foreign keys to some tables.
First, I added a foreign key to table "Room" so that column roomtype was referencing table Roomtype, column ID.
ALTER TABLE room ADD FOREIGN KEY (roomtype) REFERENCES roomtype(ID);
This worked fine. However, when I used the exact same formatting to add a foreign key to another table so that column "position" in table Nurse was referencing column ID in table Position:
ALTER TABLE nurse ADD FOREIGN KEY (position) REFERENCES position(ID);
I get an error:
ERROR 1064 (42000) 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 'Position(ID)' at line 2
I don't know how to transfer the result onto here, but I did a SHOW CREATE TABLE query for tables nurse and position, and it doesn't seem to be due to a spelling error.
I know the names are confusing, but I was required to use these names.
I changed your tags: the error message clearly says you're using mySql (not MSSQL).
I suspect the problem is with the column name, "position". Try this syntax instead:
ALTER TABLE nurse ADD FOREIGN KEY (`position`) REFERENCES `position`(ID);

How to rename a column in MySQL [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am trying to rename a column in a table in my DB. I already tried
ALTER TABLE TableName RENAME COLUMN OldColumnName TO NewColumnName
and i am getting an error reply saying - You have an error in your SQL syntax; Please whats the right syntax for this? Thanks.
Try using this syntax:
ALTER TABLE TableName CHANGE OldColumnName NewColumnName varchar(10) ;

Syntax error when adding SQL column [closed]

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 have a database called "members" and in that there's a table called "test". I'm trying to add a column to the table "test" but am getting the following error
MySQL Error 1064: You have an error in your SQL syntax.
My SQL code:
ALTER TABLE 'test'
ADD COLUMN 'Email' VARCHAR(25)
NULL AFTER 'LastName';
alter table classtest add column Email varchar(25);

Can a stored procedure call truncate veiw table and enter data to the view table in MySql [closed]

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
How to truncate a view table from a stored procedure in MySql.First tried executing the following query which failed what can be the error "TRUNCATE TABLE tester ". Tester is a view table which I created from create view in mysql. I want to truncate the view table and enter new rows via a stored procedure.
TRUNCATE TABLE does not work for views.
You can DELETE FROM tester and if the view is an updatable view it will apply the DELETE to the underlying table. But DELETE is slower than TRUNCATE, because DELETE has to do some bookkeeping to make sure it can be rolled back, whereas TRUNCATE cannot be rolled back.
You can instead do TRUNCATE TABLE table_tester_is_based_on, but as #fancyPants mentions, be sure this is what you want to do, because it will dispose of all the data in the base table. MySQL views don't store a copy of the base table, they are more like an alias for a query against the base table.