Hi
I need a field in my database (which is the primary key) such as:
prefix + autoincrement
So for example:
New01 New02 New03...etc
I know how to do the autoincrement, but how do you create a datatype where there's a prefix before the autoincrement?
AFAIK, you can't. Why do you need the prefix?
You can do this easily enough in Postgres:
CREATE SEQUENCE seq;
CREATE TABLE test (a VARCHAR DEFAULT 'New' || NEXTVAL('seq'));
Chris
I need the prefix because I'm going to have several tables, and they'll all have the same autoincrement - but with a different prefix, primary key.
What's Postgres...I'm a complete newbie here, please help me out.
Thanks.
postgres would be the way to go here then. You can share the sequence among the tables.
http://postgresql.org Postgres is another RDMS. It's a lot more robust than MySQL....
Hmm...okay, I spent some time learning about MySQL, is postgres similar, I don't want to spend a lot of time relearning stuff, if I can get away with MySQL. Is there no way to get around this in MySQL? How else can I define my primary keys?
Postgres is a bit different, and if you're not strong with RDMS's, could take soem time to learn. With MySQL, I think you'll need to store the prefix in another column. Then when you grab it, you can just concat the two columns together.
Oh I see, so I can define the primary key as a combination of two columns?
I'm very new to this, so I'm going to stay away from postgre.
Actually, if you're new to this, you might want to give postgresql a try, as now is the time to learn proper relational theory.
I'd highly suggest a good database book either way. The ones by Celko are quite good.