嗨 我有一个查询如下的表
Hi I have a table whose query is given below
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]我有多个用户填写表格,数据将进入此表.问题是我必须创建唯一的表格编号.我要做的是创建自动生成编号,并在获取ID列的最大值后以no列的形式填写.但是,当多个用户在单个时间点请求时,则相同的最大数量将进入std_form_no列.然后,如何在单个时间点有多个用户请求时为每个用户生成唯一值. 在此先感谢您.
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.
推荐答案从Sequence中获取ID.. 插入记录时,将序列nextval作为ID插入. 或 您可以标识ID列 Get Id from Sequence.. Insert sequence nextval as ID while inserting records. OR you can you identity for ID column
在前端使用随机类或使用GUID形式的后端. 谢谢, Ambesha Use the random class in frontend or use GUID form backend. Thanks, Ambesha
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]
将主键添加到具有标识列的表中 这样,SQL Server将自动生成列值,并且您不必在每次插入新行时都传递它.
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.
更多推荐
在asp.net中生成序列号
发布评论