Making a sql column UNIQUE [duplicate] - mysql

This question already has answers here:
MySQL - Make an existing Field Unique
(7 answers)
Closed 9 years ago.
Is there anyway to make a column in mysql UNIQUE with out removing it and adding it again ?
I know how to add it but i would need to remove it first but i want to edit the current column and make it UNIQUE
I do
ALTER TABLE users
ADD UNIQUE (username)
But tells me that the column username is all ready there . When i want to edit it and not add it...

Could it be that the unique index is already there?
Could it be that there already are duplicates in that column?
Check MySQL - Make a Field Unique as it might fix your problem.

Related

What is the effect of having empty tables in your database? [duplicate]

This question already has answers here:
Unused Database Table Effects
(5 answers)
Closed 3 years ago.
I have a few temporary tables that I use for a second, then clear out the data. Should I delete these tables after I finish using them or would it be okay to leave them?
It is OK to leave them.
You may wish from time to time to check the file size and run a Compact & Repair.

how to add comment to existing view in mysql [duplicate]

This question already has answers here:
Create comments for views in mysql
(4 answers)
Closed 6 years ago.
I want to ask you how add comment to view ( not table ) in MySQL. I tried something like this:
ALTER VIEW VIEWNAME COMMENT comment
but this not working.
You have to script the entire view, add the column to your query, and execute the change. You can't just add a field to the view like you would a table because it doesn't know where it should come from.

Need to remove numeric data from row in MySQL [duplicate]

This question already has answers here:
remove all numeric characters from column mysql
(2 answers)
Closed 9 years ago.
I have millions of data in MySQL table, now I need to update one particular column of the table with only non-numeric characters. That is I need to remove all numbers from that column. The row wont be deleted, only updated with only non-numeric values.
I need some efficient way to achieve this.
Calling 10 times replace doesn't look good.
Thanks,
Ashish
For mysql, you just have to replace everything:
Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(column,'9',''),'8',''),'7',''),'6',''),'5',''),'4',''),'3',''),'2',''),'1',''),'0','');

mysql - auto-increment (how to auto-increment by 5) [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
mysql auto_increment by 5?
I have a table that will have a column that needs to have a primary key. I want to set it to auto-increment, but it should increment by 5 or 10. I have been searching it, but it is hard to find the resource.
Does anybody know how to do it?
Thank you.
There is a server configuration setting called auto_increment_increment. Note however that this will be for all tables.

Adding comments to columns [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Alter MYSQL Table To Add Comments on Columns
Hi Guys,
I googled all over the place but I can't find the answer. I know you can add comments to your database columns. I already created a table but now i want to add comments to certain columns, my database programma (sequel pro) doesn't have a function to alter the columns with comments.
Is there an 'update' or 'alter' query to add comments to your columns? The database is in mysql.
Thanks!
UPDATE: found this. Now Trying if it's working
Just add
COMMENT "comment"
after your
ALTER TABLE xxx CHANGE xxx...