Integer Surrogate Key?
- by CitadelCSAlum
I need something real simple, that for some reason I am unable to accomplish to this point.
I have also been unable to Google the answer surprisingly. I need to number the entries in different tables uniquely. I am aware of AUTO INCREMENT in MySQL and that it will be involved. My situation would be as follows
If I had a table like
Table EXAMPLE
ID - INTEGER
FIRST_NAME - VARCHAR(45)
LAST_NAME - VARCHAR(45)
PHONE - VARCHAR(45)
CITY - VARCHAR(45)
STATE - VARCHAR(45)
ZIP - VARCHAR(45)
This would be the setup for the table where ID is an integer that is auto-incremented every time an entry is inserted into the table. The thing I need is that I do not want to have to account for this field when inserting data into the database. From my understanding this would be a surrogate key, that I can tell the database to automatically increment and I do not have to include it in the INSERT STATEMENT
so instead of
INSERT INTO EXAMPLE VALUES (2,'JOHN','SMITH',333-333-3333,'NORTH POLE'....
I can leave out the first ID column and just write something like
INSERT INTO EXAMPLE VALUES ('JOHN','SMITH'.....etc)
Notice I Wouldnt have to define the ID column...
I know this is a very common task to do, but for some reason I cant get to the bottom of it.
I am using MySQL, just to clarify.
Thanks alot