• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • Last Modified:

Need direction on inserting a unique value for new record in MSSQL database

I have a page called Main_info.aspx that has a DropDownList box that pulls the class_name from CLASSES table.  It also has a Calendar control and a text box.  All of these values are written to the INFO table.  With each record in the INFO table needs to be a unique id, info_id is the Primary Key and this needs to be a unique id.  
How do I make it so each New record inserted into the INFO table will have a unique ID?  
It can start at 1 and go to infinity, it really doesn't matter to me.
Also, what does the Data Type need to be in the database for this unique id, i.e. info_id?
0
jettman26
Asked:
jettman26
  • 4
  • 3
1 Solution
 
tusharashahCommented:
Make info_id Identity column(auto increment) and Primary Key.. so it'll be unique and 1+ everytime you insert a new record automatically.. ( you do not need to write down Info_Id in your Insert statement)

If you have any further question, which database are you using?

-tushar
0
 
jettman26Author Commented:
I am using MS SQL for a database.
Would this be 'uniqueidentifier' for the DataType in MS SQL?
0
 
tusharashahCommented:
Keep DataType to int

& if you're using Enterprise Manager to manage your Data, when you click on your Field Name you'll see Columns on the bottom, select like following:

Identity: Yes
Identity Seed: 1
Identity Increment: 1

-tushar
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
jettman26Author Commented:
Got it.

Since I added this info_id field, does it make the following statement not work anymore since the order of my columns in my Info table is:
info_id
class_name
info_date
notes

myCommand.CommandText = "INSERT INTO INFO VALUES ('" & classDownList.SelectedValue & "', '" & calendar.SelectedDate & "', '" & notesText.Text & "')"
0
 
tusharashahCommented:
You'll need to modify it like following:

"INSERT INTO INFO(class_name, info_date, notes) VALUES ('" & classDownList.SelectedValue & "', '" & calendar.SelectedDate & "', '" & notesText.Text & "')"

-tushar
0
 
jettman26Author Commented:
Works great!
Now I have one more question for now that I am posting if you want it?
0
 
tusharashahCommented:
I'll pass it now... will check it out tomorrow morning if it'll be open..
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now