10 pts.
 sql question on autogenerating customer numbers
SQL
I want to create a table that automatically assigns a customer number to every email address that is entered into a table.

Software/Hardware used:
ASKED: January 22, 2008  11:08 PM
UPDATED: January 24, 2008  7:29 AM

Answer Wiki:
You would need to create an automatic sequence. <pre>CREATE SEQUENCE <sequence_name> INCREMENT BY <integer> START WITH <integer> MAXVALUE <integer> / NOMAXVALUE MINVALUE <integer> / NOMINVALUE CYCLE / NOCYCLE CACHE <#> / NOCACHE ORDER / NOORDER;</pre> When entering a record, the customer number would be <sequence_name>.NEXTVAL. Insert into <table_name> values <sequence_name>.NEXTVAL, <email_address>, etc. That would be for Oracle. If you are using SQL (you didn't specify) you specify this when you create the table. It's called an IDENTITY field. <pre>CREATE TABLE MyTable (Id_Column INT IDENTITY(1,1) PRIMARY KEY, EmailAddress nvarchar(255), FullName nvarchar(255))</pre>
Last Wiki Answer Submitted:  January 24, 2008  7:29 am  by  Seashellm   150 pts.
All Answer Wiki Contributors:  Seashellm   150 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Many DMBS now have an auto increment, integer datatype which does exactly what you want

 60 pts.

 

Check out my SQL Server blog “SQL Server with Mr Denny” for more SQL Server information.

 64,520 pts.