| 发表于:2007-05-30 11:04:44 楼主 |
-- insert into a(id,name) select 'maxid ',name from b --关键是这个 'maxid ' 不在b表中,我是用这个存储过程 计算的id ----------------------------------------------------------- alter procedure dbo.alloc_id @tbnamevarchar(32) as begin begin transaction update table_alloc_id set id = id + 1 where tablename = @tbname if @@rowcount = 0 begin insert into table_alloc_id values(@tbname, 1) end select id from table_alloc_id where tablename = @tbname commit transaction end ------------------------------------------------------------------ 比如b表中有50条数据,那么上面这个alloc_id 存储过程就应该循环计算id,并插入到a表中? 请问该怎么写sql 语句? |
|
|
|
|