How to Generate Random Number using Asp.Net with SQL Server.
Please Tell me with Examples.
For Example EmpNO:100 , Random Number 12876 for each Employee different Random Numbers.
Thank&Regs
Manavalan
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
SenthilkumarPosted Feb 28, 2012, 9:22 AM
Its not good practice to generate the random number on the ID column. It should be auto generated number. SQL Server helps it make easier.
when you create the table you have to do like this.
create table Employee
(
EmployeeID INT PRIMARY KEY IDENTITY(1,1)
, EmployeeName VARCHAR(100),
etc..,
)
What it does, it will not allow you to insert the value on the identity column until unless you set identity off.
When you try to insert the record, it will start from 1 and incremented by one (first value is starting and second one is incremental value).
Even when you delete the record it will not affect. But when you truncate the table then it will reset the value.
Suthish NairPosted Feb 13, 2012, 11:30 AM