zoukankan      html  css  js  c++  java
  • 0904 存储过程、触发器、事务、视图、生成脚本

    create database lianxi0904
    go
    use lianxi0904
    go

    create table gong
    (
      gcode int primary key identity(1001,1),
      gname varchar(20),
      gtel int
    )
    go
    insert into gong values('可口可乐公司',1234567)
    insert into gong values('日用品公司',1234567)
    insert into gong values('名鞋公司',1234567)
    insert into gong values('文具公司',1234567)
    go

    create table cang
    (
      ccode int primary key identity(10001,1),
      cname varchar(20),
      cshu int,
      cprice decimal(18,2),
      cg int
    )
    go

    insert into cang values('可口可乐',4,5,1001)
    insert into cang values('牙刷',5,5.5,1002)
    insert into cang values('阿迪',2,225,1003)
    insert into cang values('毛笔',15,5,1004)
          
    insert into cang values('芬达',15,4.5,1001)
    insert into cang values('牙膏',3,9.5,1002)
    insert into cang values('耐克',2,995,1003)
    insert into cang values('钢笔',12,10.5,1004)
          
    insert into cang values('雪碧',4,3.5,1001)
    insert into cang values('杯子',6,10,1002)
    insert into cang values('乔丹',3,345,1003)
    insert into cang values('铅笔',12,2,1004)
          
    insert into cang values('可乐',22,5,1001)
    insert into cang values('洗衣粉',12,8,1002)
    insert into cang values('鸿星尔克',2,145,1003)
    insert into cang values('中性笔',6,2,1004)
    go
          

    create table piao
    (
      pcode int primary key identity(1000001,1),
      pname varchar(20),
      pshu int,
      pprice decimal(18,2),
      pzong decimal(18,2),
      pc int
    )
    go

    create proc cun
    @a varchar(20),
    @b int
    as
    begin
    update cang set cshu=cshu+@b where cname=@a
    end
    go
    exec cun '可口可乐',1
    select cshu from cang where cname='可口可乐'


    create proc chu
    @c int,
    @e varchar(20)
    as
    declare @d int
    select @d=cshu from cang where cname=@e
    declare @f decimal(18,2)
    select @f=cprice from cang where cname=@e
    declare @g decimal(18,2)
    set @g=@f*@c
    declare @h int
    select @h=ccode from cang where cname=@e
    begin
    if @c<=@d
     begin
     update cang set cshu=cshu-@c
     insert into piao values(@e,@c,@f,@g,@h)
     select *from piao
     end
    else
    print '您需要进货'+cast((@c-@d) as varchar(20))+'个'+@e
    end
    go
    exec chu 10,'芬达'

  • 相关阅读:
    response.redirect on asp.net is a 302 jump action
    什么吃掉了我的硬盘?
    百度流量统计将会影响搜索的排名
    发邮件 python
    bottle template usage
    想提神,喝中药,咖啡可可没用的
    企业退信的常见问题?
    用UnixBench测试VPS性能 判别是否值得购买
    域名注册及免费空间and企业邮箱
    LNMP一键安装包是什么?
  • 原文地址:https://www.cnblogs.com/a12110303043/p/5839702.html
Copyright © 2011-2022 走看看