MySQL Forums
Forum List  »  UDF

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
3533
January 25, 2006 09:37AM
2571
January 26, 2006 10:52AM
2455
January 27, 2006 05:46PM
2343
January 27, 2006 06:01PM
2450
January 27, 2006 07:01PM
Re: variable
4146
January 28, 2006 03:28AM
2447
January 28, 2006 06:14AM
3085
January 28, 2006 07:37AM
2331
January 28, 2006 06:24PM
2403
January 29, 2006 06:49AM
2401
January 29, 2006 12:00PM
2401
January 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.