建立儲存過程student info,要求根據班級查詢學

2021-04-14 11:16:42 字數 3993 閱讀 7100

1樓:匿名使用者

建立bai

乙個根據班級查詢學生的姓

du名出生日期和zhi性別dao

儲存過程student_info如下:回

create procedure [student_info](@class varchar(4))

with

execute as caller

asselect

select 表答2.學號

,表2.姓名,表3.課程號,表3.成績 from 表2,表3 where 表2.學號=表3.學號 and 表2.班級=@class

備註:表2 student

欄位名 型別 長度 說明

學號 字元 9 學號

姓名 字元 8 姓名

姓名 字元 2 性別

班級 字元 4 系別

出生日期 日期 8 出生日期

表3 成績表

欄位名 型別 長度 說明

學號 字元 9

課程號 字元 4

建立乙個儲存過程student_info,要求根據班級查詢學生的學號、姓名、課程號和分數(表結構如表2,表3)

2樓:匿名使用者

create procedure [student_info](@class varchar(4))

with

execute as caller

asselect 表

2.學號,表2.姓名,表3.課程專號,表3.成績 from 表2,表3 where 表2.學號=表3.學號 and 表2.班級

屬=@classgo

建立乙個儲存過程,給定某學生學號,要求查詢出該學生的姓名,所選課程名和成績.(sql server)

3樓:莫道無情

/*建立儲存過程*/

create procedure proc_select--建立儲存過程

@sno char(10) output,--輸入輸出引數

@sname varchar(20) out,--輸出引數

@cno char(4) out,--輸出引數

@grade tinyint out--輸出引數

asselect @sname=sname,@sno=student.sno,@cno=cno,@grade=grade --select裡面寫輸出引數

from student,sc  --從學生表,選修表中查詢

where @sno=student.sno--where裡面寫輸入引數

/*根據給定學號查詢*/

create proc  proc_lab4 --儲存過程中含有游標

@sno char(10)

asdeclare @ssno char(10),@ssname char(20),@ccname char(20),@scg int--宣告四個變數

declare cursor_s cursor--宣告游標

forselect student.sno,sname,cname,grade

from student,course,sc--從三個表中選擇學號、姓名、課程名、成績

where student.sno=sc.sno and course.cno=sc.cno and sname=@sname;--連線

open cursor_s--開啟游標

fetch next from cursor_s into @ssno,@ssname,@ccname,@scg

while @@fetch_status=0

begin

print @ssno+@ssname+@ccname+convert(char(10),@scg)

fetch next from cursor_s into @ssno,@ssname,@ccname,@scg

endclose cursor_s--關閉游標

deallocate cursor_s--釋放游標

exec proc_lab4 '201215121'

--只帶輸入引數

create proc p2

@sno char(10)

asselect student.sno,sname,cname,grade

from student,sc,course

where student.sno=sc.sno and sc.cno=course.cno

and sname=@sname

擴充套件資料:

建立儲存過程基本語法

create procedure sp_name

@[引數名] [型別],@[引數名] [型別]

asbegin

.........

end以上格式還可以簡寫成:

create proc sp_name

@[引數名] [型別],@[引數名] [型別]

asbegin

.........

end/*注:「sp_name」為需要建立的儲存過程的名字,該名字不可以以阿拉伯數字開頭*/

4樓:匿名使用者

select name,course,grades from student s

left join course c on c.sid = s.sid

left join achievement a on a.cid = c.cid

where s.id = 10

5樓:匿名使用者

建立過程:

create procedure proc_stu@sno nchar(9)

asselect sname,cname,gradefrom s join sc on s.sno=sc.sno join c on sc.cno=c.cno

where sno=@sno

呼叫過程:

declare @sno nchar(10)set @sno='161343001'

exec proc_stu @sno

sql語句,建立學生表(學號,姓名,性別,出生,籍貫,備註) **等,急急急

6樓:

1,統計男生人數

select * from 學生表 where 姓別='男'

2,刪除年齡在20歲以上學生的全部資訊

delete 學生表 where datediff(yy,出生,getdate())>20

3,顯示姓王男生的全部資訊

select * from 學生表 where 姓別='男' and 姓名 like '王%'

4,增加乙個「簡歷」字段

alter table 學生表 add 簡歷 varchar(200) null

7樓:愛琴海之玲

create table student

(stuno nvarchar(20),

stuname nvarchar(20),stu*** nvarchar(20),

studay datetime,

stujiguan nvarchar(50),stubeizhu nvarchar(100))goselect count(*) from student where stu***='男'---1

刪除那個建議使用儲存過程比較好

select * from student where stu***='男' and stuname like '王%' ----2

新增乙個字段 就不用我說了吧

8樓:匿名使用者

1.select count(姓名) from 學生表 where 性別=『男』

2.delete from 學生表 where date-出生日期 >20

3.select * from 學生表 where name like '王%'

4.alte table 學生表 add 簡歷 string(20)

用SQL建立儲存過程的題目(SQL SERVER2019下)

set quoted identifier ongoset ansi nulls on gocreate proc a 建立儲存過程名字為a,再次執行時將create改為alter sname nvarchar 100 傳遞的引數asselect a.sno,b.cname,c.grade from...

oracle如何建立儲存過程和如何呼叫儲存過程

create or replace procedure cony create table as begin execute immediate create table cony emp id number,name varchar2 10 salary number 動態sql為ddl語句 ex...

oracle儲存過程的親們看過來,我建立了儲存過程,可是執行後,沒有達到效果。首先保證是有資料的

首先要保證傳的引數跟table裡面的字段長的不能一模一樣,要有所區別.其次看看你的date1跟傳入的兩個引數的格式是一模一樣的,你的procedure那麼簡單,應該就是這兩個問題的其中之一,後者的可能性比較大 insert 後 要commit 提交事物 oracle 儲存過程建立成功,exec執行失...