sql question on autogenerating customer numbers

10 pts.
Tags:
SQL
I want to create a table that automatically assigns a customer number to every email address that is entered into a table.

Answer Wiki

Thanks. We'll let you know when a new response is added.

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>

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • GregMM
    Many DMBS now have an auto increment, integer datatype which does exactly what you want
    60 pointsBadges:
    report
  • Denny Cherry
    Check out my SQL Server blog "SQL Server with Mr Denny" for more SQL Server information.
    66,010 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following