alter table alter column syntax problem

This is a discussion on alter table alter column syntax problem within the MySQL Database forums, part of the Database Forums category; I am trying to set the charset and collation for all of my database table columns to Collation - latin1_general_ci When ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-04-2006
Chuck Anderson
 
Posts: n/a
Default alter table alter column syntax problem

I am trying to set the charset and collation for all of my database
table columns to
Collation - latin1_general_ci

When I try to execute the following Query (using Php mysql_query()) I
get a syntax error

"ALTER TABLE `table_name` ALTER COLUMN `column_name COLLATE
latin1_general_ci"

I get the following mysql 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 'COLLATE
latin1_general_ci' at line 1"

I can't figure out what the problem is (the column is a varchar).

Using MySQL 4.1.14

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
*****************************
Reply With Quote
  #2 (permalink)  
Old 09-05-2006
Jerry Stuckle
 
Posts: n/a
Default Re: alter table alter column syntax problem

Chuck Anderson wrote:
> I am trying to set the charset and collation for all of my database
> table columns to
> Collation - latin1_general_ci
>
> When I try to execute the following Query (using Php mysql_query()) I
> get a syntax error
>
> "ALTER TABLE `table_name` ALTER COLUMN `column_name COLLATE
> latin1_general_ci"
>
> I get the following mysql 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 'COLLATE
> latin1_general_ci' at line 1"
>
> I can't figure out what the problem is (the column is a varchar).
>
> Using MySQL 4.1.14
>


The problem is your command is incorrect. Try:

ALTER TABLE `table_name` CHANGE `column_name` COLLATE latin1_bin

If that doesn't work, set all the attributes, i.e.

ALTER TABLE `table_name` CHANGE `column_name` `column_name` VARCHAR(60)
CHARACTER SET latin1 COLLATE latin1_bin NOT NULL

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #3 (permalink)  
Old 09-05-2006
Chuck Anderson
 
Posts: n/a
Default Re: alter table alter column syntax problem

Jerry Stuckle wrote:
> Chuck Anderson wrote:
>
>> I am trying to set the charset and collation for all of my database
>> table columns to
>> Collation - latin1_general_ci
>>
>> When I try to execute the following Query (using Php mysql_query()) I
>> get a syntax error
>>
>> "ALTER TABLE `table_name` ALTER COLUMN `column_name COLLATE
>> latin1_general_ci"
>>
>> I get the following mysql 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 'COLLATE
>> latin1_general_ci' at line 1"
>>
>> I can't figure out what the problem is (the column is a varchar).
>>
>> Using MySQL 4.1.14
>>
>>

>
> The problem is your command is incorrect. Try:
>
> ALTER TABLE `table_name` CHANGE `column_name` COLLATE latin1_bin
>
> If that doesn't work, set all the attributes, i.e.
>
> ALTER TABLE `table_name` CHANGE `column_name` `column_name` VARCHAR(60)
> CHARACTER SET latin1 COLLATE latin1_bin NOT NULL
>
>

Thanks.

CHANGE with all the attributes is the only one that works.

Annnnnnnd now ... reading a little closer (duh) I found CONVERT, which
does exactly what I need to do. ALTER TABLE tbl_name CONVERT TO
CHARACTER SET charset_name;

(For anyone else reading this: There are some caveats, so be sure and
read the manual.)


--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
*****************************
Reply With Quote
  #4 (permalink)  
Old 09-05-2006
Lee Peedin
 
Posts: n/a
Default Re: alter table alter column syntax problem

On Mon, 04 Sep 2006 15:56:11 -0600, Chuck Anderson
<websiteaddress@seemy.sig> wrote:

>I am trying to set the charset and collation for all of my database
>table columns to
>Collation - latin1_general_ci
>
>When I try to execute the following Query (using Php mysql_query()) I
>get a syntax error
>
>"ALTER TABLE `table_name` ALTER COLUMN `column_name COLLATE
>latin1_general_ci"
>
>I get the following mysql 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 'COLLATE
>latin1_general_ci' at line 1"
>
>I can't figure out what the problem is (the column is a varchar).
>
>Using MySQL 4.1.14


Looks like you're missing a backtick after column_name.

Lee
Reply With Quote
  #5 (permalink)  
Old 09-05-2006
Chuck Anderson
 
Posts: n/a
Default Re: alter table alter column syntax problem

Lee Peedin wrote:
> On Mon, 04 Sep 2006 15:56:11 -0600, Chuck Anderson
> <websiteaddress@seemy.sig> wrote:
>
>
>> I am trying to set the charset and collation for all of my database
>> table columns to
>> Collation - latin1_general_ci
>>
>> When I try to execute the following Query (using Php mysql_query()) I
>> get a syntax error
>>
>> "ALTER TABLE `table_name` ALTER COLUMN `column_name COLLATE
>> latin1_general_ci"
>>
>> I get the following mysql 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 'COLLATE
>> latin1_general_ci' at line 1"
>>
>> I can't figure out what the problem is (the column is a varchar).
>>
>> Using MySQL 4.1.14
>>

>
> Looks like you're missing a backtick after column_name.
>
> Lee
>

Thanks. That was not the problem, though, ... rather my own sloppy cut
and paste.

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
*****************************
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:27 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0