Automatism Generate Serial number...

来源:互联网 发布:人工智能的含义是什么 编辑:程序博客网 时间:2024/05/16 19:27
--Sql server2000 Environment
--Generate serial number for tbale tb_bh
--Section 1:
--Create a table,Table name:tb_bh

CREATE TABLE tb_bh(BH varchar(20))

--Section 2,Create a procedure as below.
 
IFEXISTS (SELECT name FROM sysobjects
           WHERE name = N'proc_tb_bh'AND type ='P')
   DROPPROCEDURE proc_tb_bh
GO
 
CREATE PROCEDURE proc_tb_bh
AS
insertinto tb_bh SELECTconvert(varchar(8),getdate(),112)+RIGHT(100001+ISNULL(RIGHT(MAX(BH),5),0),5) FROM tb_bh
GO
--Selection 2,Run the Procedure generate serial number

execute proc_tb_bh

select * from tb_bh

--Oracle9i Environment

Section 1

-- Create sequence

create sequence BH

minvalue 1

maxvalue 99999

start with 1

increment by 1

cache 20;

--Section 2

create or replace procedure proc_tb_bh

as

begin

insert into tb_bh values(bh.nextval);

commit;

end proc_tb_bh;

 

原创粉丝点击