views:

52

answers:

1

Hi.

It might sound complicated, but it's not. I have a table called "orders", with fields:

id INT(11) auto_increment,
realid INT(14)

Now, I want at every insert into this table, do something like:

INSERT INTO orders VALUES (null, id+1000);

However I'll be doing it on shop which is currently online, and I want to change everything in 5 minutes. Will something like this work? If not, how do I do that?

+5  A: 

I would think a simpler solution would be a calculated column presuming your DBMS supports it (This is using SQL Server syntax, although the MySql syntax should be nearly identical except that you would use AUTO_INCREMENT instead of Identity(1,1)):

Create Table Foo    (
                    Id int not null identity(1,1)
                    , Name varchar(50)
                    , Bar As Id + 1000 
                    )

Of course, you could also just do it in the presentation or business tier instead of the database.

Thomas