Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I have a table whose query is given below
SQL
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tbl_stud_detail]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tbl_stud_detail]
GO

CREATE TABLE [dbo].[tbl_stud_detail] (
	[id] [int] NULL ,
	[std_form_no] [nvarchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[std_name] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[std_dob] [datetime] NULL ,
	[std_religion] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[std_sex] [nvarchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[std_father_name] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY]


I have a multiple user that fill the form and data will go into this table. Problem is that I have to create form number unique. What I did I am creating auto genrate number and fill it in the form no column after getting max value of id column. But when multiple user request at single point of time then same max number will go into the std_form_no column. Then how to generate unique value for each user when multiple user request at single point of time.
Thanks in advance.
Posted
Comments
vivektiwari97701 19-Oct-12 5:08am    
u can use GUID for genrate unique no every time .
singh7pankaj 19-Oct-12 5:20am    
But I want Sequential number e.g 0001,0002,0003,0004 etc. But Guid give different number.

Get Id from Sequence..
Insert sequence nextval as ID while inserting records.
OR
you can you identity for ID column
 
Share this answer
 
v2
Comments
singh7pankaj 19-Oct-12 5:29am    
Sequence is not working in sql server 2008 and identity column may get problem when fetching the record because when 4 user request for the identity value at that single point of time then identity value for all the user is same. at that time what I'll have to do?
Ambesha 19-Oct-12 5:31am    
identity number for n number of user can't be same.. :)
manak chand 19-Oct-12 6:33am    
sql server will insert record one by one. you can save the ID while inserting Record...
If you want to get values before inserting record Sequence will work... I had user it..
manak chand 19-Oct-12 6:34am    
for more precautions, you can set ID column as Primary key
Use the random class in frontend or use GUID form backend.

Thanks,
Ambesha
 
Share this answer
 
Comments
singh7pankaj 19-Oct-12 5:26am    
when I am using GUID then it gives different number but What my no is in sequential way e.g 0001,0002,0003,0004 etc.
Ambesha 19-Oct-12 5:30am    
in this case create identity colomn and give the seed value as you required.

Thanks,
Ambesha
SQL
CREATE TABLE [dbo].[tbl_stud_detail] (
    [id] [int] IDENTITY(1,1) PRIMARY,
    [std_form_no] [nvarchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [std_name] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [std_dob] [datetime] NULL ,
    [std_religion] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [std_sex] [nvarchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [std_father_name] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]


Add a primary key to the table having identity column
so that the SQL server will auto-generate the column value and you dont need to pass it everytime you insert a new row.
 
Share this answer
 
you can use this code in aspx.cs page>>>>
C#
string id = System.DateTime.Now.ToFileTime().ToString().Substring(5, 9);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900