如果商品启用序列号管理数据库设计如何实现?

lulesheng1983 2004-04-22 10:33:01
如何在记录商品出入库的同时记录每一个商品唯一的序列号
...全文
123 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
qinqin198037 2004-09-15
  • 打赏
  • 举报
回复
那你的问题是什么?
lulesheng1983 2004-04-23
  • 打赏
  • 举报
回复
这是我的错
我没有说清楚

序列号是厂家根据具体算法规定得出的
就象网卡有一个唯一的物理地址一样
birchsilver 2004-04-23
  • 打赏
  • 举报
回复
我以前曾经做过一个类似的项目,这个功能不是一两句话能说清楚的,我们在QQ上聊吧
QQ:99191628
了缘 2004-04-23
  • 打赏
  • 举报
回复
設置一個類似id遞增的列,如table_id
select @numRow=isnull(max(table_id),0)+1 from table
在提交時update進去
了缘 2004-04-23
  • 打赏
  • 举报
回复
那你用identity列不是更好嗎
lulesheng1983 2004-04-22
  • 打赏
  • 举报
回复
如果
a 商品的数量是3的话就应该有3个序列号分别记录
lulesheng1983 2004-04-22
  • 打赏
  • 举报
回复
序列号是单据录入的时候指定的而不是自动生成的
zjcxc 2004-04-22
  • 打赏
  • 举报
回复
--类似这个,自己写个函数实现自动编号

--自动编号的例子.材料编号=类别编号+流水号

--创建自定义函数,得到新的ID
create function f_getid(
@类别编号 varchar(3))
returns int
as
begin
declare @re int
select @re=right(id,4) from(
select id=max(材料编号) from tb where 类别编号=@类别编号
) a
set @re=isnull(@re,0)+1
return(@re)
end
go

--创建测试表
create table tb(材料编号 varchar(7) primary key default '',类别编号 varchar(3),材料名称 varchar(10))
go

--创建触发器,自动生成材料编号
create trigger t_insert on tb
instead of insert
as
select * into #t from inserted order by 类别编号
declare @类别编号 varchar(3),@id int
update #t set @id=case when @类别编号=类别编号 then @id+1 else dbo.f_getid(类别编号) end
,材料编号=类别编号+right('0000'+cast(@id as varchar),4)
,@类别编号=类别编号
insert into tb select * from #t
go

--插入数据测试
insert into tb(类别编号,材料名称)
select '101','A材料'
union all select '101','B材料'
union all select '302','C材料'

--显示结果
select * from tb order by 材料编号

go
--删除测试环境
drop table tb
drop function f_getid

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧