华工版SQL Server数据库实验二:安全与完整性约束

3星 · 超过75%的资源 需积分: 10 13 下载量 201 浏览量 更新于2024-07-29 收藏 649KB DOCX 举报
在本次华工版数据库实验二中,主要涉及的是使用Microsoft SQL Server 2008进行数据库的安全和完整性约束管理。实验的核心内容围绕创建数据库、表以及实施视图,同时强调了数据安全和规范性的重要性和实践操作。 首先,实验开始时通过SQL脚本检查并处理已存在的名为"Student"的数据库,如果存在则先删除(`if exists`语句),确保实验环境整洁。接下来,创建一个新的数据库"Student"(`create database`)并切换到该数据库(`use Student`)。 在数据库中,一个关键步骤是创建名为"Students"的表,这个表包含了学生的个人信息,如学号(SNO)、姓名(SNAME)、性别(SEX)、出生日期(BDATE)、身高(HEIGHT)、专业(DEPARTMENT)等字段。表设计中特别注意了数据完整性,设置了主键约束(`primary key`)为SNO,并添加了一个校验约束(`check`子句),确保性别字段仅限于"男"或"女"的值。 插入了几条学生记录来演示如何在实际环境中操作数据,每个记录都是一个`insert into`语句,包含了各个字段的具体值。这些操作展示了如何在SQL Server中维护数据的准确性和一致性。 安全性方面,虽然没有直接提及,但在实践中创建数据库和表的操作都需要对用户权限进行管理和控制,确保只有授权的用户才能访问和修改数据。此外,为了防止SQL注入攻击,应当使用参数化查询或存储过程来执行敏感操作,确保数据的保护。 总结来说,这个实验让学生们熟悉了SQL Server 2008的数据库管理,包括创建、使用和维护数据库结构,理解主键和约束在保证数据完整性和一致性的关键作用,以及基本的数据录入和管理。通过这个实验,参与者将能够增强自己的数据库设计与管理技能,为今后在IT行业中处理大量数据打下坚实的基础。
2018-05-20 上传
Requirement: I. Query database with SQL Server. (30’, 2’ for each) 1. Create a table named Student using command Create Table. The table structure is as follows: Column Type Length Note ID Varchar 20 Student’s ID Name Varchar 10 Student’s Name Age Int Student’s Age Department Varchar 30 Student’s Dept. 2. Create a table named Course using command Create Table. The table structure is as follows: Column Type Length Note CourseID Varchar 15 Course’s ID CourseName Varchar 30 Course’s Name CourseBefore Varchar 15 Previous Course 3. Create a table named Choose using command Create Table. The table structure is as follows: Column Type Length Note ID Varchar 20 Student’s ID CourseID Varchar 15 Course’s ID Score Dec 5,2 Student’s Score 4. Insert 3 records into table Student using command Insert. ID Name Age Department 00001 ZhangSan 20 Computer Science 00002 LiSi 19 Computer Science 00003 WangWu 21 Computer Science 5. Insert 3 records into table Course using command Insert CourseID CourseName CourseBefore C1 Introduction to Computer - C2 PASCAL Programming Language C1 C3 Data Structure C2 6. Insert 7 records into table Choose using command Insert ID CourseID Score 00001 C1 95 00001 C2 80 00001 C3 84 00002 C1 80 00002 C2 85 00003 C1 78 00003 C3 70 7. Select the students’ ID and Name in Computer Science department using command select. 8. Select the students’ ID, Name, CourseName and Score using command select. 9. Select all students’ Information in descending order of the students’ ID. 10. Select every student’s average score. 11. Select the number of courses a student has chosen. 12. Select the number of students choosing a specific course. 13. Select the students’ ID who have chosen course C1 and got score over 80. 14. Select the students’ ID who have chosen course C2. 15. Select the average age of students in every department. II. Design a MIS for Computer Science college of SCUT. (45’) It is used to manage the information about course