sql语句来看看。。
我想把这些语句改成sql2005的。。。。谁帮帮我啊。。。。
触发器:
(1)确认产品入库:
create trigger reminder1
on 入库表
after insert,update
as
exec msdb.dbo.sp_send_dbmail
@profile_name='库存管理员',
@recipients='sunyitongdlx@163.com',
@body='入库数量发生变化,报告相关部门。',
@subject='已有商品入库'
()确认产品出库:
create trigger reminder2
on 出库表
after insert,update
as
exec msdb.dbo.sp_send_dbmail
@profile_name='库存管理员',
@recipients='sunyitongdlx@163.com',
@body='出库数量发生变化,报告相关部门。',
@subject='已有商品出库'
()设立警戒线,超出警戒线数量则报错:
create trigger 警戒线
on 库存表
after update
AS
DECLARE @num tinyint
select @num = inserted.库存数量 from inserted
IF ( @num > 10000)
BEGIN
RAISERROR ('库存越过警戒线',1,1)
ROLLBACK TRANSACTION
END
添加存储过程
查询图书的入库情况
CREATE PROCEDURE storage
@number varchar(10)
As
select 图书编号,入库数量,入库日期
from 入库表 join 库存表on 入库表.图书编号=库存表.图书编号
where 入库表.图书编号=@number
查询图书的出库情况
CREATE PROCEDURE storage1
@number varchar(10)
As
select 图书编号,出库数量,出库日期
from 出库表 join 库存表on 出库表.图书编号=库存表.图书编号
where 出库表.图书编号=@number
创建数据库的脚本:
/*==============================================================*/
/* DBMS name: Sybase AS Anywhere 9 */
/* Created on: 2010-06-11 11:52:01 */
/*==============================================================*/
if exists(select * from sys.sysforeignkey where role='FK_借条信息表_RELATIONS_库存表') then
alter table 借条信息表
delete foreign key FK_借条信息表_RELATIONS_库存表
end if;
if exists(select * from sys.sysforeignkey where role='FK_入库表_RELATIONS_员工表') then
alter table 入库表
delete foreign key FK_入库表_RELATIONS_员工表
end if;
if exists(select * from sys.sysforeignkey where role='FK_入库表_RELATIONS_库存表') then
alter table 入库表
delete foreign key FK_入库表_RELATIONS_库存表
end if;
if exists(select * from sys.sysforeignkey where role='FK_出库表_RELATIONS_员工表') then
alter table 出库表
delete foreign key FK_出库表_RELATIONS_员工表
end if;
if exists(select * from sys.sysforeignkey where role='FK_出库表_RELATIONS_库存表') then
alter table 出库表
delete foreign key FK_出库表_RELATIONS_库存表
end if;
if exists(
select * from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='Relationship_3_FK'
and t.table_name='借条信息表'
) then
drop index 借条信息表.Relationship_3_FK
end if;
if exists(
select * from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='Relationship_4_FK'
and t.table_name='入库表'
) then
drop index 入库表.Relationship_4_FK
end if;
if exists(
select * from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='Relationship_5_FK'
and t.table_name='入库表'
) then
drop index 入库表.Relationship_5_FK
end if;
if exists(
select * from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='Relationship_2_FK'
and t.table_name='出库表'
) then
drop index 出库表.Relationship_2_FK
end if;
if exists(
select * from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='Relationship_6_FK'
and t.table_name='出库表'
) then
drop index 出库表.Relationship_6_FK
end if;
if exists(
select * from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='员工表_PK'
and t.table_name='员工表'
) then
drop index 员工表.员工表_PK
end if;
if exists(
select * from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='库存表_PK'
and t.table_name='库存表'
) then
drop index 库存表.库存表_PK
end if;
if exists(
select * from sys.systable
where table_name='借条信息表'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table 借条信息表
end if;
if exists(
select * from sys.systable
where table_name='入库表'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table 入库表
end if;
if exists(
select * from sys.systable
where table_name='出库表'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table 出库表
end if;
if exists(
select * from sys.systable
where table_name='员工表'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table 员工表
end if;
if exists(
select * from sys.systable
where table_name='库存表'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table 库存表
end if;
/*==============================================================*/
/* Table: 借条信息表 */
/*==============================================================*/
create table 借条信息表
(
图书编号 varchar(10),
借出图书编号 varchar(10) not null,
借出图书名 varchar(20),
借出人 varchar(20),
借出时间 varchar(10),
借出数量 varchar(10),
还库时间 date,
constraint PK_借条信息表 primary key clustered (借出图书编号)
);
/*==============================================================*/
/* Index: Relationship_3_FK */
/*==============================================================*/
create index Relationship_3_FK on 借条信息表 (
图书编号 ASC
);
/*==============================================================*/
/* Table: 入库表 */
/*==============================================================*/
create table 入库表
(
图书编号 varchar(10),
员工编号 varchar(10),
入库编号 numeric(10) not null,
入库数量 integer
constraint CKC_入库数量_入库表 check (入库数量 is null or (入库数量>0)),
入库日期 date,
Column_6 char(10),
constraint PK_入库表 primary key clustered (入库编号)
);
/*==============================================================*/
/* Index: Relationship_4_FK */
/*==============================================================*/
create index Relationship_4_FK on 入库表 (
员工编号 ASC
);
/*==============================================================*/
/* Index: Relationship_5_FK */
/*==============================================================*/
create index Relationship_5_FK on 入库表 (
图书编号 ASC
);
/*==============================================================*/
/* Table: 出库表 */
/*==============================================================*/
create table 出库表
(
员工编号 varchar(10),
图书编号 varchar(10),
出库编号 numeric(10) not null,
出库数量 integer
constraint CKC_出库数量_出库表 check (出库数量 is null or (出库数量>0)),
出库日期 date,
Column_6 char(10),
constraint PK_出库表 primary key clustered (出库编号)
);
/*==============================================================*/
/* Index: Relationship_2_FK */
/*==============================================================*/
create index Relationship_2_FK on 出库表 (
员工编号 ASC
);
/*==============================================================*/
/* Index: Relationship_6_FK */
/*==============================================================*/
create index Relationship_6_FK on 出库表 (
图书编号 ASC
);
/*==============================================================*/
/* Table: 员工表 */
/*==============================================================*/
create table 员工表
(
员工编号 varchar(10) not null,
员工姓名 varchar(20),
性别 varchar(2),
出生日期 date,
工作日期 date,
联系电话 numeric,
constraint PK_员工表 primary key (员工编号)
);
/*==============================================================*/
/* Index: 员工表_PK */
/*==============================================================*/
create unique index 员工表_PK on 员工表 (
员工编号 ASC
);
/*==============================================================*/
/* Table: 库存表 */
/*==============================================================*/
create table 库存表
(
图书编号 varchar(10) not null,
图书名 varchar(20),
作者 varchar(10),
出版社 varchar(20),
出版日期 date,
价格 varchar(10),
图书类型 varchar(20),
库存数量 integer,
constraint PK_库存表 primary key (图书编号)
);
/*==============================================================*/
/* Index: 库存表_PK */
/*==============================================================*/
create unique index 库存表_PK on 库存表 (
图书编号 ASC
);
alter table 借条信息表
add constraint FK_借条信息表_RELATIONS_库存表 foreign key (图书编号)
references 库存表 (图书编号)
on update restrict
on delete restrict;
alter table 入库表
add constraint FK_入库表_RELATIONS_员工表 foreign key (员工编号)
references 员工表 (员工编号)
on update restrict
on delete restrict;
alter table 入库表
add constraint FK_入库表_RELATIONS_库存表 foreign key (图书编号)
references 库存表 (图书编号)
on update restrict
on delete restrict;
alter table 出库表
add constraint FK_出库表_RELATIONS_员工表 foreign key (员工编号)
references 员工表 (员工编号)
on update restrict
on delete restrict;
alter table 出库表
add constraint FK_出库表_RELATIONS_库存表 foreign key (图书编号)
references 库存表 (图书编号)
on update restrict
on delete restrict;