createprocedure s1
@Rname nvarchar(50)='王小明',@Btitle nvarchar(50)output,@BorrowDatedate output,@Bauthor nvarchar(50) output
asselect@Rname=Rname,@Btitle=Btitle,@BorrowDate=BorrowDate,@Bauthor=Bauthor
from Book,Borrow,Reader where@Rname=Rname and Book.Bno=Borrow.Bno and Reader.Rno=Borrow.Rno
go
createprocedure s2
@maxpricefloat output,@minpricefloat output
asselect@maxprice=max(Bprice),@minprice=min(Bprice)from Book
go
createprocedure s3
@Rname nvarchar(50)='王小明',@Btitle nvarchar(50),@Bpricefloat output,@BorrowDatedate output,@ReturnDatedate output,@Bauthor nvarchar(50) output
asselect@Bprice=Bprice,@BorrowDate=BorrowDate,@ReturnDate=ReturnDate,@Bauthor=Bauthor
from Book,Borrow,Reader where@Rname=Rname and@Btitle=Btitle and Book.Bno=Borrow.Bno and Reader.Rno=Borrow.Rno
go
createprocedure s4
@Btitle nvarchar(50),@Borrowtotalint output
asselect@Borrowtotal=count(Borrnum)from Book,Borrow,Reader where@Btitle=Btitle and Book.Bno=Borrow.Bno and Reader.Rno=Borrow.Rno
go
declare@Btitle1 nvarchar(50),@Borrowtotal1intselect@Btitle1='数据结构'exec s4 @Btitle1,@Borrowtotal1 output
print@Borrowtotal1
go
createprocedure s5
@Btitle nvarchar(50),@Rname nvarchar(50)output,@Ragesmallint output,@Reducation nvarchar(10)output,@BorrowDatedate output,@ReturnDatedate output
asselect@Rname=Rname,@Rage=Rage,@BorrowDate=BorrowDate,@ReturnDate=ReturnDate,@Reducation=Reducation
from Book,Borrow,Reader where@Btitle=Btitle and Book.Bno=Borrow.Bno and Reader.Rno=Borrow.Rno
go
declare@Btitle1 nvarchar(50),@Rname1 nvarchar(50),@Rage1smallint,@Reducation1 nvarchar(10),@BorrowDate1date,@ReturnDate1dateselect@Btitle1='操作系统概论'exec s5 @Btitle1,@Rname1 output,@Rage1 output,@Reducation1 output,@BorrowDate1 output,@ReturnDate1 output
print@Rname1print@Rage1print@Reducation1print@BorrowDate1print@ReturnDate1
-- ================================================-- Template generated from Template Explorer using:-- Create Scalar Function (New Menu).SQL---- Use the Specify Values for Template Parameters -- command (Ctrl-Shift-M) to fill in the parameter -- values below.---- This block of comments will not be included in-- the definition of the function.-- ================================================SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================-- Author: <Author,,Name>-- Create date: <Create Date, ,>-- Description: <Description, ,>-- =============================================CREATEFUNCTION f1(@Rname nvarchar(100),@Btitle nvarchar(100))RETURNSdateASBEGIN-- Declare the return variable hereDECLARE@BorrowDatedate-- Add the T-SQL statements to compute the return value hereSELECT@BorrowDate=BorrowDate from Book,Borrow,Reader
where@Btitle=Btitle and Book.Bno=Borrow.Bno and Reader.Rno=Borrow.Rno
and Book.Btitle=@Btitleand Reader.Rname=@Rname-- Return the result of the functionRETURN(@BorrowDate)END
GO
CREATEFUNCTION f2(@Btitle nvarchar(100))RETURNS@f2table(Rname nvarchar(100),Rage smallint,Reducation nvarchar(10),BorrowDate date,ReturnDate date)ASBEGIN-- Declare the return variable hereinsert@f2-- Add the T-SQL statements to compute the return value hereSELECT Rname,Rage,Reducation,BorrowDate,ReturnDate from Book,Borrow,Reader
where@Btitle=Btitle and Book.Bno=Borrow.Bno and Reader.Rno=Borrow.Rno
and Book.Btitle=@Btitleorderby BorrowDate desc-- Return the result of the functionRETURNEND
GO
CREATEFUNCTION f3(@Btitle nvarchar(100))RETURNS@f3table(Btitle nvarchar(100),Bookcount smallint,avgRage smallint)ASBEGIN-- Declare the return variable hereinsert@f3-- Add the T-SQL statements to compute the return value hereSELECT Btitle,avg(Rage)as avgRage,count(Borrnum)as Bookcount from Book,Borrow,Reader
where@Btitle=Btitle and Book.Bno=Borrow.Bno and Reader.Rno=Borrow.Rno
and Book.Btitle=@Btitlegroupby Btitle
-- Return the result of the functionRETURNEND
GO