首页 > 数据库 >数据库原理第二次实验报告

数据库原理第二次实验报告

时间:2024-05-23 23:51:13浏览次数:26  
标签:Shopper 数据库 Orders Order cursor 第二次 实验报告 declare select

目录

写在前面

因为任务四说的实在是太说得道理了如果没有欧内的手很难做这个尊尼获加的哈利路大旋风,于是就去找了老师:

另外本次实验报告的生成用了 Keldos-Li_typora-latex-theme_ 将Typora伪装成LaTeX的中文样式主题,本科生轻量级课程论文撰写的好帮手。This is a theme disguising Typora into Chinese LaTeX style,超级好用,强推!

实验报告要求

  1. 列出所有的SQL语句和源代码;
  2. PL/SQL程序可以有适当的注释。
  3. 实验报告中需给出代码、结果截图和对分析结果的文字描述。

任务一(数据库CAP)

初始化 CAP

按照课件所示进行表的建立:

Use CAP;

CREATE TABLE MONTH
(
    Rank int PRIMARY KEY NOT NULL,
    Month char(8)
);

CREATE TABLE CUSTOMERS
(
	Cid char(8)  PRIMARY KEY NOT NULL,
	Cname varchar(8) NOT NULL,
	City varchar(8),
	Discnt numeric(10,2)
);
CREATE TABLE AGENTS
(
	Aid char(8)  PRIMARY KEY NOT NULL,
	Aname varchar(8) NOT NULL,
	City varchar(8),
	AgentsPercent int
);
CREATE TABLE PRODUCTS
(
	Pid char(8) PRIMARY KEY NOT NULL,
	Pname varchar(8) NOT NULL,
	City varchar(8), 
	Quantity int,
	Price numeric(10,2)
);
CREATE TABLE ORDERS
(
	Ordno char(8)  PRIMARY KEY NOT NULL,
	OrdersMonth varchar(8),
	cid varchar(8) NOT NULL,
	aid varchar(8) NOT NULL,
	pid varchar(8) NOT NULL,
	Qty int,
	Dollars numeric(10, 2)
);

插入一些数据,并对 MONTH 进行初始化:

Use CAP;

INSERT INTO CUSTOMERS VALUES('C001',' TipTip','Duluth', 10.00);
INSERT INTO AGENTS VALUES('A01',' smith','New York', 6);
INSERT INTO PRODUCTS VALUES('P01',' comb','Dallas', 111400, 0.50);

INSERT INTO MONTH VALUES(1, 'Jan.');
INSERT INTO MONTH VALUES(2, 'Feb.');
INSERT INTO MONTH VALUES(3, 'Mar.');
INSERT INTO MONTH VALUES(4, 'Apr.');
INSERT INTO MONTH VALUES(5, 'May.');
INSERT INTO MONTH VALUES(6, 'Jun.');
INSERT INTO MONTH VALUES(7, 'Jul.');
INSERT INTO MONTH VALUES(8, 'Aug.');
INSERT INTO MONTH VALUES(9, 'Sept.');
INSERT INTO MONTH VALUES(10, 'Oct.');
INSERT INTO MONTH VALUES(11, 'Nov.');
INSERT INTO MONTH VALUES(12, 'Dec.');

1

写一段程序,向表Orders中增加50000条记录,要求订单尽可能均匀地分布在12个月中。

需要保证数据的合法性,考虑首先从 CUSTOMERSAGENTSPRODUCTSMONTH 中各选出一行数据作为插入订单的参数,实现方法为将上述各表随机排序后取第一行。

然后按照数字递增地构造 50000 条数据的编号 00001 ~ 50000,再随机地构造其他参数后插入。

declare @i int
set @i = 0
while @i < 50000
begin
    declare @cid varchar(8)
    select top 1 @cid = Cid
    from CUSTOMERS
    order by newid()

    declare @aid varchar(8)
    select top 1 @aid = Aid
    from AGENTS
    order by newid()

    declare @pid varchar(8)
    select top 1 @pid = Pid
    from PRODUCTS
    order by newid()

    declare @mon varchar(8)
    select top 1 @mon = Month
    from MONTH
    order by newid()

    declare @oid varchar(8)
    set @oid = @i
    while len(@oid) < 5
        begin
            set @oid = '0' + @oid
        end

    insert into ORDERS values(@oid, @mon, @cid, @aid, @pid, rand() * 10, rand() * 10);
    set @i = @i + 1
end

执行结果:

2

假设在表Orders上经常要执行的一个查询是“根据给定的月份,查询该月订单的总金额”。写出该查询的SQL语句,尝试通过创建索引提高查询的速度,并对比创建索引前后执行查询所消耗的时间。

查询语句:

select sum(Dollars) sum
from ORDERS
where OrdersMonth = 'Jan.'

建立索引语句:

create index OrdersIndexOnMonth
on ORDERS(OrdersMonth)

在(1)建立的表上的执行结果前后时间差异:

[2024-05-22 10:48:22] 在 71 ms (execution: 37 ms, fetching: 34 ms) 内检索到从 1 开始的 1 行 \(\rightarrow\) [2024-05-22 10:47:58] 在 60 ms (execution: 11 ms, fetching: 49 ms) 内检索到从 1 开始的 1 行

任务二:视图(数据库GlobalToyz)

1

假设GlobalToyz数据库的用户经常需要查询某个购物者(shopper)的所有已收货订单的编号和待收货订单的编号。请通过定义视图解决这个问题。

视图中需要包含 ShopperIdOrderNocDeliveryStatus

create view ViewShopper(cShopperId, cDeliveryStatus, cOrderNo)
as select Shopper.cShopperId, cDeliveryStatus, Orders.cOrderNo
    from Shopper
    left join Orders
    on Shopper.cShopperId = Orders.cShopperId
    left join Shipment
    on Orders.cOrderNo = Shipment.cOrderNo

测试语句:

select cDeliveryStatus, cOrderNo
from ViewShopper
where cShopperId = '000002'

执行结果:

2

基于(1)中定义的视图,根据给定的购物者Id查询该购物者所有待收货玩具的Id,名称和描述。

假设给定购物者 cShopperId = '000008

select VS.cOrderNo, T.vToyName, T.vToyDescription
from ViewShopper VS
left join Orders O
on VS.cOrderNo = O.cOrderNo
left join ShoppingCart SC
on O.cCartId = SC.cCartId
left join Toys T
on SC.cToyId = T.cToyId
where VS.cShopperId = '000002' and VS.cDeliveryStatus = 's'

执行结果:

3

假设当系统中新增一个购物者(Shopper)的时候,需要为该购物者创建一个账号,并通过授权机制限制该购物者不能访问其他购物者的私有信息,例如其他购物者的订单、购物者的姓名、地址、邮件等个人信息。请给出解决的方案。

考虑在系统新增购物者的同时,为每个购物者单独建立查询视图,其中仅包含该购物者的信息。每次购物者访问数据库时,仅允许在该视图中进行查询,若尝试访问其他购物者的信息直接抛出错误。

任务三:触发器(数据库GlobalToyz)

1

PickofMonth这张表是一张统计表,按年月统计某个玩具的销售总量。当用户下订单的时候,需要自动维护PickofMonth这张表。请利用触发器实现这个功能。

使用游标枚举 inserted 表中对应订单的购物车中的所有物品的 cToyIdsiQty,并根据 dOrderDate 修改 PickofMonth 中的数据,若对应的年份月份不存在则新建一行。

create trigger updatePickOfMonth on Orders
after insert
as
    select year(inserted.dOrderDate) dOrderYear, month(inserted.dOrderDate) dOrderMonth,
           ShoppingCart.cToyId, ShoppingCart.siQty into T
    from inserted
    left join ShoppingCart
    on inserted.cCartId = ShoppingCart.cCartId

--     select *
--     from T

    declare cursor_toy cursor for
    select dOrderYear, dOrderMonth, cToyId, siQty from T
    open cursor_toy;

    declare @year int
    declare @month int
    declare @toy char(6)
    declare @qty smallint
    fetch next from cursor_toy into @year, @month, @toy, @qty;
    WHILE @@FETCH_STATUS = 0
        BEGIN
--             PRINT 'toyid:' + @toy + ',qty:' + CAST(@qty AS varchar(10));
            if exists(select * from PickOfMonth
                               where @year = PickOfMonth.iYear and
                                     @month = PickOfMonth.siMonth and
                                     @toy = PickOfMonth.cToyId)
                begin
                    update PickOfMonth
                    set iTotalSold = iTotalSold + @qty
                    where cToyId = @toy and
                          iYear = @year and
                          siMonth = @month
                end
            else
                begin
                    insert into PickOfMonth values(@toy, @month, @year, @qty)
                end

            FETCH NEXT FROM cursor_toy INTO @year, @month, @toy, @qty;
        END;
    close cursor_toy;
    deallocate cursor_toy;

    drop table T
    go

2

Orders表是GlobalToyz数据库里的一张核心的表,对这张表上做的任何更新动作(增、删、改)都需要记录下来,这是数据库审计(Audit)的基本思想。要求设计一张表存储对Orders表的更新操作,包括操作者、操作时间、操作类型、更新前的数据、更新后的数据。请通过设计触发器实现对Orders表的审计。

为了记录更新操作与历史对象,首先建立如下两张表:

create table HistoryOrders
(
    historyOrderNo   bigint  not null primary key identity(1, 1),
    cOrderNo         char(6)  not null,
    dOrderDate       datetime not null,
    cCartId          char(6)  not null,
    cShopperId       char(6)  not null,
    cShippingModeId  char(2),
    mShippingCharges money,
    mGiftWrapCharges money,
    cOrderProcessed  char,
    mTotalCost       money,
    dExpDelDate      datetime
)

-- 操作者、操作时间、操作类型、更新前的数据、更新后的数据
create table AuditOrders
(
    Aid bigint PRIMARY KEY NOT NULL identity(1, 1),
    Operator varchar(16) NOT NULL,
    Datetime datetime,
    Type varchar(16),
    BeforeOrderNo bigint,
    AfterOrderNo bigint
)

然后建立如下三个触发器,分别用于处理增删改:

  • InsertOrders:将新增数据插入 HistoryOrders,然后将其在 HistoryOrders 中的编号作为参数,将 insert 操作插入 AuditOrders
  • DeleteOrders:将被删除数据插入 HistoryOrders,然后将其在 HistoryOrders 中的编号作为参数,将 delete 操作插入 AuditOrders
  • UpdateOrders:将被删除数均插入 HistoryOrders,然后将它们在 HistoryOrders 中的编号作为参数,将 update 操作插入 AuditOrders

特别地,若操作非法,没有对数据库造成影响,仍会记录一次空操作。

-- 增、删、改
create trigger InsertOrders on Orders
    after insert
    as
    declare @after bigint
    if (select count(*) from inserted) > 0
        begin
            insert into HistoryOrders select * from inserted
            select @after = max(historyOrderNo) from HistoryOrders
        end

    insert into AuditOrders(Operator, Datetime, Type, BeforeOrderNo, AfterOrderNo)
    values (user, getdate(), 'insert', null, @after)
    go


create trigger DeleteOrders on Orders
    after delete
    as
    declare @before bigint
    if (select count(*) from deleted) > 0
        begin
            insert into HistoryOrders select * from deleted
            select @before = max(historyOrderNo)from HistoryOrders
        end

    insert into AuditOrders(Operator, Datetime, Type, BeforeOrderNo, AfterOrderNo)
    values (user, getdate(), 'delete', @before, null)
    go

create trigger UpdateOrders on Orders
    after update
    as
    declare @before bigint
    declare @after bigint
    if (select count(*) from deleted) > 0
        begin
            insert into HistoryOrders select * from deleted
            select @before = max(historyOrderNo) from HistoryOrders

            insert into HistoryOrders select * from inserted
            select @after = max(historyOrderNo) from HistoryOrders
        end

    insert into AuditOrders(Operator, Datetime, Type, BeforeOrderNo, AfterOrderNo)
    values (user, getdate(), 'update', @before, @after)
    go

测试

INSERT INTO GlobalToyz.dbo.Orders (cOrderNo, dOrderDate, cCartId, cShopperId,
                                   cShippingModeId, mShippingCharges, mGiftWrapCharges,
                                   cOrderProcessed, mTotalCost, dExpDelDate)
        VALUES (N'111111', N'2024-05-22 13:38:02.000', N'000002',
                N'000002', N'01', 6.0000, 1.0000, N'Y', 2.0000, N'2024-05-22 13:38:28.000')

update Orders
set mTotalCost = mTotalCost + 1
where Orders.cOrderNo = '95'

delete from Orders
where cOrderNo = '111111'

update Orders
set mTotalCost = mTotalCost + 1
where Orders.cOrderNo = '95'

执行结果:

任务四:存储过程与事务(数据库GlobalToyz)

1

当用户确认了一笔订单的时候,需要对数据库进行一系列的操作,例如向表Orders、表OrderDetail中添加记录、对表Toys中玩具的库存数量的修改等,请首先画出相应的处理流程,然后将处理流程定义为一个事务,通过一个存储过程来实现,存储过程以购物车ID(cCartId)和购物者ID(cShopperId)为参数。(这道题请充分考虑确认订单的各个环节)

最折磨的一集。

只使用购物车 ID 和购物者 ID 为参数显然不太充分,所以额外地随机生成了如下参数:

  • 运输种类
  • 对于每个物品:
    • 是否进行礼物包装
    • 礼物包装种类
    • 礼物消息

以下是一些用于生成随机数据的函数:

create view v_rand
as
select rand() as val;
go

create or alter function getRandNum(@n int)
    returns int
as begin
    select @n = @n * val from v_rand
    return floor(@n)
end;
go

create or alter function getRandomString(
    @num int,
    @chars varchar(1024) = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
) returns varchar(1024)
as begin
    declare @res_str VARCHAR(1024) = ''
    declare @i int=0
    while (@i < @num) begin
        set @res_str = @res_str + substring(@chars, dbo.getRandNum(len(@chars))+ 1, 1)
        set @i = @i + 1
    end
    return @res_str
end;
go

然后考虑添加一笔订单后的过程:

  1. 枚举每个物品,在 OrderDetail 插入数据:
    • 随机参数(是否包装,包装种类,礼物消息)。
    • 计算礼物包装费用、根据重量计算运输费用、计算总花费。
    • 将所有花费累计。
  2. Orders 中插入数据:
    • PickOfMonth 更新销量(续用任务三的触发器)。
    • Toys 更新现有量 Qoh(quantity on hand)(触发器实现)
  3. Recipient 插入数据(触发器实现)
  4. Shipment 插入数据(触发器实现)
    • 仅插入包含 OrderNo 的空行。
create or alter function getShippingCost(
    @shopperId char(6),
    @modeId char(2),
    @pound smallint
) returns money
as begin
    declare @countryId char(3)
    declare @ratePerPound money
    select @countryId = cCountryID
    from Shopper
    where cShopperId = @shopperId

    select @ratePerPound = mRatePerPound
    from ShippingRate
    where cCountryID = @countryId and cModeId = @modeId

    return convert(money, @ratePerPound * @pound)
end
go

create procedure AddOrder
(
    @shopperId char(6),
    @cartId char(6)
)
as begin
    declare @maxNo int
    select @maxNo = max(cOrderNo) + 1 from Orders

    declare @orderNo char(6)
    declare @shippingModeId char(2)
    declare @shippingCharges money = 0
    declare @giftWrapCharges money = 0
    declare @totalToyCost money = 0
    declare @OrderDate datetime = getdate()
    declare @expDelDate datetime

    set @orderNo = RIGHT('000000' + CAST(@maxNo AS VARCHAR), 6);
    select top 1 @shippingModeId = cModeId,
                 @expDelDate = dateadd(day, iMaxDelDays, @OrderDate)
    from ShippingMode
    order by newid()

    alter table OrderDetail
    nocheck constraint FK__OrderDeta__cOrde__534D60F1

    declare toy_cursor cursor for
    select ShoppingCart.cToyId as cToyId,
           ShoppingCart.siQty as siQty,
           Toys.mToyRate as mToyRate,
           Toys.siToyWeight as siToyWeight
    from ShoppingCart
    left join Toys
    on ShoppingCart.cToyId = Toys.cToyId
    where cCartId = @cartId
    open toy_cursor

    declare @toy char(6)
    declare @qty smallint
    declare @rate money
    declare @weight smallint
    fetch next from toy_cursor into @toy, @qty, @rate, @weight
    while @@fetch_status = 0 begin
        declare @giftWrap char(1) = 'N'
        declare @wrapId char(3)
        declare @message char(256)
        declare @toyCost money = @qty * @rate
        declare @toyWrapCost money = 0
        declare @toyShippingCost money = 0

        if (rand() < 0.5) begin
            select top 1 @wrapId = cWrapperId, @toyWrapCost = mWrapperRate
            from Wrapper
            order by newid()

            set @giftWrap = 'Y'
            set @toyWrapCost = @toyWrapCost * @qty
            set @message = dbo.getRandomString(10,DEFAULT)
            set @toyShippingCost = dbo.getShippingCost(@shopperId,
                                                      @shippingModeId, @qty * @weight)
        end

        print convert(char(6), @orderNo) + ' ' + @toy + ' ' + convert(char(6), @qty) + ' ' +
              @giftWrap + ' ' + @wrapId + ' ' + @message + ' ' +
              convert(char, @toyShippingCost)

        set @shippingCharges = @shippingCharges + @toyShippingCost
        set @giftWrapCharges = @giftWrapCharges + @toyWrapCost
        set @totalToyCost = @totalToyCost + @toyCost

        insert into OrderDetail(cOrderNo, cToyId, siQty, cGiftWrap, cWrapperId,
                                vMessage, mToyCost)
            values (@orderNo, @toy, @qty, @giftWrap, @wrapId,
                    @message, @toyCost)

        fetch next from toy_cursor into @toy, @qty, @rate, @weight
    end
    close toy_cursor
    deallocate toy_cursor

    alter table OrderDetail
    check constraint FK__OrderDeta__cOrde__534D60F1




    insert into Orders(cOrderNo, dOrderDate, cCartId, cShopperId, cShippingModeId,
                       mShippingCharges, mGiftWrapCharges, cOrderProcessed,
                       mTotalCost, dExpDelDate)
    values (@orderNo, @OrderDate, @cartId, @shopperId, @shippingModeId,
            @shippingCharges, @giftWrapCharges, 'Y',
            @totalToyCost + @shippingCharges + @giftWrapCharges, @expDelDate)
end;
go

create trigger updateToysQoh on OrderDetail
after insert as
    declare @toyId char(6)
    declare @toyQty smallint
    select @toyId = cToyId, @toyQty = siQty
    from inserted

    if exists(select * from Toys where Toys.cToyId = @toyId and
                                       Toys.siToyQoh >= @toyQty) begin
        update Toys
        set siToyQoh = siToyQoh - @toyQty
        where cToyId = @toyId
    end
go

create trigger insertRecipient on Orders after insert as
    insert into Recipient
    select cOrderNo, vFirstName, vLastName, vAddress, cCity, cState, cCountryId, cZipCode, cPhone
    from inserted
    left join Shopper
    on inserted.cShopperId = Shopper.cShopperId
go

create trigger insertShipment on Orders after insert as
    insert into Shipment
    select cOrderNo, null, null, null
    from inserted
go

测试

exec AddOrder @shopperId = '000002', @cartId = '000001'

执行结果:

Orders 中的变化:

OrderDetail 中的变化:

Recipient 中的变化:

Shippment 中的变化:

PickofMonth 中的变化:

任务五:游标与SQL(数据库GlobalToyz)

1

基于表Orders和Shopper,以下列格式生成报表:(要求用游标实现)

     购货人ID   XXX    购货人姓名   XXX    
     购货人地址  XXXXXX 
     定单号XXX  定单时间XXX  定单金额XXX
     定单号XXX  定单时间XXX  定单金额XXX

使用两层循环,枚举所有购物者,再枚举 Orders 中该购物者的所有订单,输出要求的信息即可。

注意若某购物者没有下过订单,则不输出。

declare shopper_cursor cursor for
select cShopperId, vFirstName, vLastName, vAddress from Shopper
open shopper_cursor

declare @shopper char(6)
declare @firstname varchar(20)
declare @lastname varchar(20)
declare @address varchar(40)
fetch next from shopper_cursor into @shopper, @firstname, @lastname, @address

while @@fetch_status = 0
    begin
        select cOrderNo, dOrderDate, mTotalCost into TempOrders
        from Orders
        where @shopper = Orders.cShopperId

        declare order_cursor cursor for
        select cOrderNo, dOrderDate, mTotalCost from TempOrders
        open order_cursor

        declare @no char(6)
        declare @date datetime
        declare @cost money
        fetch next from order_cursor into @no, @date, @cost

        if @@fetch_status = 0
            begin
                print 'Shopper Id: ' + @shopper + ' Shopper Name: ' + @firstname + ' ' + @lastname
                print 'Shopper Address: ' + @address
                while @@fetch_status = 0
                    begin
                        print 'Order Id: ' + @no + ' Order Datetime: ' + convert(varchar, @date) + ' Order Cost: ' + convert(varchar, @cost)
                        fetch next from order_cursor into @no, @date, @cost
                    end
                print ''
                print ''
            end
        close order_cursor
        deallocate order_cursor
        drop table TempOrders
        fetch next from shopper_cursor INTO @shopper, @firstname, @lastname, @address
    end

close shopper_cursor
deallocate shopper_cursor

执行结果:

Shopper Id: 000002 Shopper Name: Barbara Johnson
Shopper Address: 227 Beach Ave.
Order Id: 000001 Order Datetime: 05 20 2021 12:00AM Order Cost: 62.22
Order Id: 000005 Order Datetime: 05 21 2021 12:00AM Order Cost: 231.68
Order Id: 000011 Order Datetime: 05 23 2024  8:27PM Order Cost: 53.97


Shopper Id: 000003 Shopper Name: Betty Williams
Shopper Address: 1 Tread Road
Order Id: 000010 Order Datetime: 05 22 2021 12:00AM Order Cost: 67.97


Shopper Id: 000005 Shopper Name: Catherine Roberts
Shopper Address: 5508 Aquiline Court
Order Id: 000002 Order Datetime: 05 20 2021 12:00AM Order Cost: 96.50


Shopper Id: 000006 Shopper Name: Charles Brown
Shopper Address: 7822 S. Glitzy Avenue
Order Id: 000004 Order Datetime: 05 20 2021 12:00AM Order Cost: 40.99


Shopper Id: 000007 Shopper Name: Christopher Davis
Shopper Address: 4896 11th ST
Order Id: 000003 Order Datetime: 05 20 2021 12:00AM Order Cost: 83.97


Shopper Id: 000008 Shopper Name: Cynthia Miller
Shopper Address: 98066 Weary Storm Street
Order Id: 000007 Order Datetime: 05 22 2021 12:00AM Order Cost: 16.99


Shopper Id: 000009 Shopper Name: Daniel Wilson
Shopper Address: 4642 Peripheral Drive
Order Id: 000008 Order Datetime: 05 22 2021 12:00AM Order Cost: 53.98


Shopper Id: 000010 Shopper Name: David Moore
Shopper Address: 8808 Joviality Drive
Order Id: 000009 Order Datetime: 05 22 2021 12:00AM Order Cost: 26.99


Shopper Id: 000012 Shopper Name: Donna Anderson
Shopper Address: 7930 Orange St.
Order Id: 000006 Order Datetime: 05 21 2021 12:00AM Order Cost: 97.97

2

编写代码,分析购物者、玩具和地域的关系,例如哪个城市的购买者对哪一种、哪一类或哪一个品牌的玩具更有兴趣。这道题是个开放的题目,同学们可以按照自己的理解从不同的角度进行分析。

探究玩具品牌与购买者所在州的关系。

考虑分析每种品牌在各个州的销售额在总销售额的占比,并按照降序排序:

-- 计算每种品牌玩具销售量总和
select Toys.cBrandId, convert(money, sum(siQty)) sum into T
from Toys
left join OrderDetail OD on Toys.cToyId = OD.cToyId
group by Toys.cBrandId

-- 求销售额在各州占比
select Toys.cBrandId, Shopper.cState,
       convert(money, sum(siQty)) / (select sum from T where Toys.cBrandId = T.cBrandId) sum
from OrderDetail OD
left join Orders O on OD.cOrderNo = O.cOrderNo
left join Toys on Toys.cToyId = OD.cToyId
left join Shopper on O.cShopperId = Shopper.cShopperId
group by Shopper.cState, Toys.cBrandId
order by Toys.cBrandId, sum desc

drop table T

执行结果:

发现每种玩具均在加州的销售额的占比最高。你们加州可真是人才辈出啊(赞美之心

不行了提到加州就想到睦月跳那个铸币 California Girls 我草

参考

主要参考:数据库原理及应用教程 第4版︱微课版 (陈志泊 许福 韩慧 崔晓晖 路贺俊 阮豫红编著)

语句参考:

写法参考:

捉虫参考:

实验报告格式:

标签:Shopper,数据库,Orders,Order,cursor,第二次,实验报告,declare,select
From: https://www.cnblogs.com/rainycolor/p/18209661

相关文章

  • PowerShell 中重置SQL SERVER数据库的 SA(System Administrator)密码可以通过 SQL Serve
    PowerShell中重置数据库的SA(SystemAdministrator)密码可以通过SQLServerManagementObjects(SMO)来完成。以下是一个基本的PowerShell脚本,可以用来重置SA用户的密码:powershellCopyCode#导入SQLServer模块Import-ModuleSQLPS-DisableNameChecking#设置SQL......
  • 数据库视图
    学生表:Student(Sno,Sname,Ssex,Sage,Sdept)学号,姓名,性别,年龄,所在系Sno为主键students|CREATETABLE`students`(`Sno`intNOTNULL,`Sname`char(30)DEFAULTNULL,`Ssex`char(10)DEFAULTNULL,`Sage`intDEFAULTNULL,`Sdept`char(20)DEFAULT'......
  • 数据库连表查询
    sql的join功能如上图所示当a表joinb表时想要a表的内容不损失就使用leftjoin建表语句:1.创建student和score表CREATE TABLEstudent(id INT(10) NOTNULL UNIQUE PRIMARYKEY,name VARCHAR(20) NOTNULL,sex VARCHAR(4),birth YEAR,departme......
  • Liquibase中的约束与索引,让你的数据库管理如丝般顺滑
    哈喽,大家好,我是木头左!一、引言在软件开发的过程中,数据库的管理是至关重要的一环。随着项目的不断迭代,数据库的结构也会发生变化。如何在不丢失数据的情况下,快速地修改数据库结构呢?Liquibase是一个非常实用的工具,它可以帮助轻松地管理数据库的变更。本文将详细介绍Liquibase中......
  • 20211317李卓桐 Exp7 网络欺诈防范 实验报告
    Exp7网络欺诈防范基础问题回答(1)通常在什么场景下容易受到DNSspoof攻击DNSspoof攻击,也称为DNS欺骗或DNS欺瞒,是一种网络攻击手法,其中攻击者通过伪造DNS(域名系统)应答来误导互联网用户,使得他们访问恶意网站或服务器,而不是他们原本想要访问的真实网站或服务。以下场景可能会容易......
  • 2023 年上半年数据库系统工程师考试
    基础知识●计算机中,系统总线用于(1)。(1)A.接口和外设​B.运算器、控制器和寄存器​C.CPU、主存及外设部件​D.DMA控制器和中断控制器参考答案:(1)C系统总线通常用来连接计算机中的各个部件(如CPU、内存和I/O设备)寄存器和运算器部件主要用片内总线连......
  • 第三期【数据库主题文档上传激励活动】已开启!快来上传文档赢奖励
    2023年9月、11月,墨天轮社区相继举办了第一期与第二期【数据库主题文档上传激励活动】,众多用户积极参与、上传了大量优质的数据库主题干货文档,在记录经验的同时也为其他从业者带来了参考帮助,这正实现了“乐知乐享、共同成长”的活动初衷。为进一步壮大数据库资源“宝库”、向广大......
  • 阿里oceanbase数据库安装步骤-windows-docker
    打开阿里的安装教程:OceanBase分布式数据库-海量数据笔笔算数找到方案3:容器-docker。https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000000639587 下载docker-desktop:https://www.docker.com/https://www.docker.com/products/docker-desktop/......
  • 使用链接服务器 从A数据库访问B数据库的表 或者建立视图
    通过SQLServer从A服务器访问B服务器表的方法场景:访问不同电脑上的数据库,且经常访问或数据量大,建议用链接服务器(位置:MicrosoftSQLServerManagementStudio->服务器对象->链接服务器)解决:1.创建链接服务器execsp_addlinkedserver'192.168.1.1','','SQLOLEDB','10.......
  • .net 直接在DataGridView控件中修改单元格数据,并保存到数据库
    1.获取datagridview单元格修改的内容//单元格的值发生改变时触发事件privatevoiddataGridView1_CellValueChanged(objectsender,DataGridViewCellEventArgse){//获取当前行绑定的内容AppraisalBasesitem=(AppraisalBases)dataGridView1.Rows[e.RowIndex].Da......