I'm attempting to run the below query to produce a table in mysql and i'm getting a mistake.

create table newtable ( 
       version_id int(11) auto_increment not null, 
       test_id int(11)   default version_id, 
       primary key(version_id) 
 );

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 'version_id not null, primary key(version_id), unique key(test_id) )' at line 1

I get above error.

I believe the issue is setting test_id default as version_id, since it works otherwise.

Thanks
Bala

-- Update

Here's what I needed to complete,

After i produce a new row, I wish to make use of the version_id because the key. After I update, I wish to use the need for existing record because the key. Observe that test_id isn't the primary key.

I do not think you should use "variables" as defaults. They most likely need to be constants. If you wish to understand this effect, you can most likely get it done inside a saved procedure / trigger "before Place" so that when the trial_id isn't provided it will get designated exactly the same value because the version_id...

Here's a tutorial that can help you toward that finish.

I believe your trigger would look something similar to:

mysql> CREATE TRIGGER myTrigger
    -> BEFORE INSERT ON newtable
    -> FOR EACH ROW
    -> BEGIN
    ->      IF NEW.trial_id IS NULL THEN
    ->         SET NEW.trial_id = NEW.version_id;
    ->      END IF;
    -> END$$