存储过程与触发器的应用
一、实验目的 1、掌握创建存储过程的方法和步骤; 2.掌握存储过程的使用方法; 3.掌握创建触发器的方法和步骤; 4.掌握触发器的使用方法。 二、实验内容 1、存储过程的创建、执行和删除; 2、触发器的创建、执行和删除。 三、实验步骤 1、存储过程的创建
一、实验目的
1、掌握创建存储过程的方法和步骤;
2.掌握存储过程的使用方法;
3.掌握创建触发器的方法和步骤;
4.掌握触发器的使用方法。
二、实验内容
1、存储过程的创建、执行和删除;
2、触发器的创建、执行和删除。
三、实验步骤
1、存储过程的创建、执行和删除。
1)使用S_C数据库中的S表、C表、SC表创建一个带参数的存储过程—cjjicx。该存储过程的作用是: 当任意输入一个学生的姓名时,将从三个表中返回该学生的学号、选修的课程名称和课程成绩。
cjjicx的创建语句:
CREATE PROCEDURE cjjicx
@name char(6)
AS
BEGIN
SELECT S.sno, C.cname, SC.grade FROM S, C, SC
WHERE S.sname = @name AND S.sno = SC.sno AND SC.cno = C.cno
END
2)执行cjjicx存储过程,查询“刘晨”的学号、选修课程和课程成绩。
执行语句:
EXEC cjjicx @name = '刘晨'
结果描述:
3)使用系统存储过程sp_helptext查看存储过程cjjicx的文本信息。
查看结果描述:
sp_helptext cjjicx
4)使用S-C数据库中的S表,为其创建一个加密的存储过程—jmxs。该存储过程的作用是:当执行该 存储过程时,将返回计算机系学生的所有信息。
jmxs创建语句:
CREATE PROCEDURE mxs WITH ENCRYPTION
AS
BEGIN
SELECT * FROM S
END
5)执行jmxs存储过程,查看计算机系学生的情况。
执行语句:
EXEC mxs
结果描述:
SP_HELPTEXT mxs
6)删除jmxs存储过程。
删除语句:
DROP PROCEDURE mxs
2、触发器的创建、执行和删除。
1)在S_C数据库中建立一个名为insert_xh的INSERT触发器,存储在SC表中。该触发器的作用是: 当用户向SC表中插入记录时,如果插入了在S表中没有的学生学号sno,则提示用户不能插入记录, 否则提示记录插入成功。
insert_xh的创建语句:
CREATE TRIGGER insert_xh ON SC
AFTER INSERT
AS
BEGIN
IF(SELECT COUNT(*) FROM inserted JOIN S ON S.sno = inserted.sno) = 0
BEGIN
ROLLBACK TRAN
PRINT '用户不能插入记录'
END
ELSE
PRINT '记录插入成功'
END
2)为S_C数据库中的S表创建一个名为dele_stu的DELETE触发器,该触发器的作用是禁止删除S 表中的记录。
dele_stu的创建语句:
CREATE TRIGGER dele_stu ON S
AFTER DELETE
AS
BEGIN
ROLLBACK TRAN
PRINT '禁止删除'
END
3)为S_C数据库中的SC表创建一个名为update_grade的UPDATE触发器,该触发器的作用是禁止更 新SC表中的grade字段的内容。
update_grade的定义语句:
CREATE TRIGGER update_grade ON SC
FOR INSERT, UPDATE
AS
DECLARE @grade1 INT;
DECLARE @grade2 INT;
SELECT @grade1 = inserted.grade FROM inserted
SELECT @grade2 = deleted.grade FROM deleted
BEGIN
IF(@grade1 != @grade2)
BEGIN
PRINT '不能修改分数'
ROLLBACK TRAN
END
END
4)删除update_grade触发器。
删除update_grade触发器的命令:
DROP TRIGGER update_grade
四、实验总结
最最基础的

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Deleted something important from your home screen and trying to get it back? You can put app icons back on the screen in a variety of ways. We have discussed all the methods you can follow and put the app icon back on the home screen. How to Undo Remove from Home Screen in iPhone As we mentioned before, there are several ways to restore this change on iPhone. Method 1 – Replace App Icon in App Library You can place an app icon on your home screen directly from the App Library. Step 1 – Swipe sideways to find all apps in the app library. Step 2 – Find the app icon you deleted earlier. Step 3 – Simply drag the app icon from the main library to the correct location on the home screen. This is the application diagram

The role and practical application of arrow symbols in PHP In PHP, the arrow symbol (->) is usually used to access the properties and methods of objects. Objects are one of the basic concepts of object-oriented programming (OOP) in PHP. In actual development, arrow symbols play an important role in operating objects. This article will introduce the role and practical application of arrow symbols, and provide specific code examples to help readers better understand. 1. The role of the arrow symbol to access the properties of an object. The arrow symbol can be used to access the properties of an object. When we instantiate a pair

Title: Realme Phone Beginner’s Guide: How to Create Folders on Realme Phone? In today's society, mobile phones have become an indispensable tool in people's lives. As a popular smartphone brand, Realme Phone is loved by users for its simple and practical operating system. In the process of using Realme phones, many people may encounter situations where they need to organize files and applications on their phones, and creating folders is an effective way. This article will introduce how to create folders on Realme phones to help users better manage their phone content. No.

The Linuxtee command is a very useful command line tool that can write output to a file or send output to another command without affecting existing output. In this article, we will explore in depth the various application scenarios of the Linuxtee command, from entry to proficiency. 1. Basic usage First, let’s take a look at the basic usage of the tee command. The syntax of tee command is as follows: tee[OPTION]...[FILE]...This command will read data from standard input and save the data to

Git is a fast, reliable, and adaptable distributed version control system. It is designed to support distributed, non-linear workflows, making it ideal for software development teams of all sizes. Each Git working directory is an independent repository with a complete history of all changes and the ability to track versions even without network access or a central server. GitHub is a Git repository hosted on the cloud that provides all the features of distributed revision control. GitHub is a Git repository hosted on the cloud. Unlike Git which is a CLI tool, GitHub has a web-based graphical user interface. It is used for version control, which involves collaborating with other developers and tracking changes to scripts and

With the popularity of Douyin, more and more individuals and companies have begun to pay attention to the Douyin account matrix. The Douyin account matrix refers to the creation of multiple related accounts to form an organic whole to achieve the purpose of expanding brand influence and improving user stickiness. So, what are the benefits of Douyin account matrix? What is the purpose of making a Douyin account matrix? This article explores these issues in detail. 1. What are the benefits of Douyin account matrix? Increase brand exposure: By creating multiple Douyin accounts, brand information can reach more potential users, helping to increase the brand's visibility and reputation. Improve content exposure: Using Douyin’s recommendation algorithm to publish content through multiple accounts can increase the exposure opportunities of brands and products and improve their visibility on the platform. 3. Achieve precision

The Go language is an open source programming language developed by Google and first released in 2007. It is designed to be a simple, easy-to-learn, efficient, and highly concurrency language, and is favored by more and more developers. This article will explore the advantages of Go language, introduce some application scenarios suitable for Go language, and give specific code examples. Advantages: Strong concurrency: Go language has built-in support for lightweight threads-goroutine, which can easily implement concurrent programming. Goroutin can be started by using the go keyword

Do you know how to create an online word document? Online word documents can enable multiple people to collaborate and edit online documents. It has large-capacity cloud storage space. Documents can be stored centrally and can be logged in from multiple devices. It can be said that no matter which device you are on, you can view and edit it. The most important thing is that it supports one-click sharing, which is particularly convenient for sharing your documents with colleagues. Today we will introduce how to create an online word document. In fact, the method is very simple. Friends in need can refer to it. 1. First open the wpsoffice software on your computer, then on the new file page, open the text item bar, and then select the new online document option. 2. Then the new document page will open, where we can choose an online document template or a blank document.
