如何在sql server 2008中增加标识? [英] How to increment identity in sql server 2008?

查看:108
本文介绍了如何在sql server 2008中增加标识?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为ProfileMaster的表,其中有很多列。我将ProfileId添加为自动增量并将其设置为主键。



现在我有另一个名为AdvisorCode的列,这里我想在创建新配置文件时自动增加AdvisorCode 。 AdvisorCode将这样开始



V3W000000

V3W000001

V3W000002
V3W000003

V3W000004

V3W000005

........... < br $> b $ b ...........

...........

..... ......

...........这样开



那么有人可以帮我吗?

I have a table called ProfileMaster, in that many columns are there. I added ProfileId as auto increment and set it as primary key.

And now I have another column called AdvisorCode, here I want to increment AdvisorCode automatically when new profile is created. AdvisorCode will be starting like this

"V3W000000"
"V3W000001"
"V3W000002"
"V3W000003"
"V3W000004"
"V3W000005"
...........
...........
...........
...........
........... SO ON

So Can anyone help me please?

推荐答案

检查链接......并根据需要进行更改..



http://forums.asp.net/t/1608233.aspx [ ^ ]
Check the link..and change according to your need..

http://forums.asp.net/t/1608233.aspx[^]


创建一个生成id的函数



Make a function for genrating id

void Id()
       {
           string query = "select * from POS1 where Warehouse='" + Warehouse.Text + "' order by No";
           DataTable dt = conn.fill(query);
           string id = ""; int ID = 0;
           if (dt.Rows.Count > 0)
           {
               int ctr = dt.Rows.Count - 1;
               id = dt.Rows[ctr]["NO"].ToString();
               ID = int.Parse(id);
               ID++;
               string no =V3W000.ToUpper();
               id = no + "/" + ID;
           }
           else
           {
               string no = V3W000.ToUpper();
               ID = 1;
               id = no+ "/" + ID;
           }
           TextBox.Text = id;

   }


使用一些PL / SQL播放。



使用SQL Server自定义自动生成的序列 [ ^ ]
Play with some PL/SQL.

Custom Auto-Generated Sequences with SQL Server[^]


这篇关于如何在sql server 2008中增加标识?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆