插入新值的困惑!! 先加个id=identity(int,1,1)再right(('1000000'+id),6) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 caixia615(┌睜眼為殤.2ǒǒ6.閉眼為塵┐) 你讲的方法在哪做?是什么意思,请讲讲 用存储过程实现添加,在前端调用存储过程就行了关于id的处理可以这样declare @max varchar(10)select @max=max(cast(id as int))+1 from 表insert 表(……)select replicate('0',6-len(@max)) + @max,…… 方法很多:触发器用instead of insert 就行了 --用计算列,这里取名叫idnameCREATE 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 idSELECT TOP 10 * FROM # ORDER BY id DESC id idname colother ----------- ------------ -------------------- 1 000001 72 000002 253 000003 244 000004 105 000005 206 000006 117 000007 28 000008 179 000009 510 000010 21(10 row(s) affected)id idname colother ----------- ------------ -------------------- 2402 002402 12401 002401 22400 002400 02399 002399 12398 002398 182397 002397 192396 002396 22395 002395 172394 002394 62393 002393 8(10 row(s) affected) 增,删,改,一条语句也需要事务吗? 请问一个SQL2000导出sql脚本的问题. 备份数据库的时候如何只备份其中的几张表,而不用备份整个数据库? SQL如何用语句copy文件到DFS文件夹 SQL2000数据库损坏,请教如何恢复? 关于游标的使用问题 有没有用java实现的存储图片文件 SQL查询 模糊查询,检索所有字段,结果如何只显示中标的字段值的一段内容?就象google搜索结果页一样显示? how to transfer the following sub select to a string in view SQL Server 远程更新数据库的问题?
关于id的处理可以这样
declare @max varchar(10)
select @max=max(cast(id as int))+1 from 表
insert 表(……)select replicate('0',6-len(@max)) + @max,……
触发器用instead of insert 就行了
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)