Skip navigation links

MySQL Forums :: UDF :: variable


Advanced Search

Re: variable
Posted by: Roland Bouman ()
Date: January 28, 2006 03:28AM

Thank you!

[you didn't provide an error message]

now, when I construct the ddl string, I would get the equivalent of:

create table foo (
id int(10) not null auto increment
, name varchar(20) not null
, surename varchar(20) not null
, sex BOOLEAN
)

when i run that in the commanline, I get:

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 'auto increment

That's easily fixed, the correct syntax is

auto_increment

not

auto increment

After fixing that I (I'm using capitals to mark the fix) run the statement again:

create table foo (
id int(10) not null AUTO_INCREMENT
, name varchar(20) not null
, surename varchar(20) not null
, sex BOOLEAN
)

ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key

So, that's the error I hinted about in my first reply. Easy to fix:

create table foo (
id int(10) not null AUTO_INCREMENT PRIMARY KEY
, name varchar(20) not null
, surename varchar(20) not null
, sex BOOLEAN
)

Query OK, 0 rows affected (0.23 sec)

So, thats your correct syntax. Now you know what your generated string should look like, and you can change your code accordingly:

set @sql_text := concat('create table ',@table_name,'(id int(10) not null AUTO_INCREMENT PRIMARY KEY, name varchar(20) not null, surename varchar(20) not null, sex BOOLEAN)');

Now, we test if everything's in place at the command line:

set @table_name := 'foo';
set @sql_text := concat('create table ',@table_name,'(id int(10) not null AUTO_INCREMENT PRIMARY KEY, name varchar(20) not null, surename varchar(20) not null, sex BOOLEAN)');

select @sql_text;

create table foo(id int(10) not null AUTO_INCREMENT PRIMARY KEY, name varchar(20) not null, surename varchar(20) not null, sex BOOLEAN)

which certainly is the right statement.

Good luck!

roland

Options: ReplyQuote


Subject Views Written By Posted
variable 2941 Juraj Balaz 01/25/2006 09:37AM
Re: variable 2223 Roland Bouman 01/26/2006 10:52AM
Re: variable 2082 Juraj Balaz 01/27/2006 05:46PM
Re: variable 2050 Roland Bouman 01/27/2006 06:01PM
Re: variable 2096 Juraj Balaz 01/27/2006 07:01PM
Re: variable 3628 Roland Bouman 01/28/2006 03:28AM
Re: variable 2095 Juraj Balaz 01/28/2006 06:14AM
Re: variable 2725 Roland Bouman 01/28/2006 07:37AM
Re: variable 1957 Juraj Balaz 01/28/2006 06:24PM
Re: variable 2095 Roland Bouman 01/29/2006 06:49AM
Re: variable 2065 Juraj Balaz 01/29/2006 12:00PM
Re: variable 2084 Roland Bouman 01/29/2006 12:58PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.