先加个id=identity(int,1,1)
再right(('1000000'+id),6)

解决方案 »

  1.   

    caixia615(┌睜眼為殤.2ǒǒ6.閉眼為塵┐) 你讲的方法在哪做?是什么意思,请讲讲
      

  2.   

    用存储过程实现添加,在前端调用存储过程就行了
    关于id的处理可以这样
    declare @max varchar(10)
    select @max=max(cast(id as int))+1 from 表
    insert 表(……)select replicate('0',6-len(@max)) + @max,……
      

  3.   

    方法很多:
    触发器用instead of insert 就行了
      

  4.   

    --用计算列,这里取名叫idname
    CREATE TABLE dbo.#
    (id Int identity(1,1) ,
    idname AS Right('000000'+CONVERT(varchar(100),id),6),
    colother VARCHAR(20))--插入数据
    INSERT INTO #(colother)
    SELECT colid 
    FROM syscolumns--看看idname是否满足格式要求
    SELECT TOP 10 * FROM # ORDER BY id
    SELECT TOP 10 * FROM # ORDER BY id DESC id          idname       colother             
    ----------- ------------ -------------------- 
    1           000001       7
    2           000002       25
    3           000003       24
    4           000004       10
    5           000005       20
    6           000006       11
    7           000007       2
    8           000008       17
    9           000009       5
    10          000010       21(10 row(s) affected)id          idname       colother             
    ----------- ------------ -------------------- 
    2402        002402       1
    2401        002401       2
    2400        002400       0
    2399        002399       1
    2398        002398       18
    2397        002397       19
    2396        002396       2
    2395        002395       17
    2394        002394       6
    2393        002393       8(10 row(s) affected)