5.23 Views in SQL 155
select name from STC where cno =’cs110’;
In reality, SQL combines this select phrase with the query just shown and executes the modified query:
select STUDENTS.name from STUDENTS, GRADES where STUDENTS.stno = GRADES.stno and GRADES.cno =’cs110’;
The previous example shows that views in SQL play a role similar to the role played by macros in programming languages. Views are important for data security. A user who needs to have access only to list of names of students and the courses they are taking needs to be aware only of the existence of STC. If the user is authorized to use only select constructs, then the user can ignore whether STC is a table or a view. Confidential data (such as grades obtained in specific courses) can be completely protected in this manner. Also, the queries that this limited-access user may write are simpler and easier to understand. No space is wasted with the view STC, and the view remains current always, reflecting the contents of the tabular variables STUDENTS and GRADES. SQL treats views exactly as it treats the tabular variables as far as retrieval is concerned. We can also delegate the select privilege to a view in exactly the same way as we did for a tabular variable. For instance, if the user george created the view STC, then he can give the select right to vanda by writing:
grant select on STC to vanda;
Consider now another example of view: Example 5.23.2 The view SNA that contains the student number and the names of students can be created by:
create view SNA as select stno, name from STUDENTS
The purpose of this view is to insure privacy to students. Any user who has access only to this view can retrieve the student number and name of a student, but not the address of the student. There is a fundamental difference between the views introduced in Examples 5.23.1 and 5.23.2, and this refers to the ways in which these two views behave with respect to updates. Suppose that the user wishes to insert the pair (7799, ’Jane Jones’) in the view SNA. The user may ignore entirely the fact that SNA is not a base tabular variable. On the other hand, the effect on the base tabular variable of this insertion is unequivocally determined: the system inserts in the tabular variable STUDENTS the tuple (7799, ’Jane Jones’, null, null, null). On the other hand, we cannot insert a tuple in a meaningful way in the view STC introduced in Example 5.23.1. Indeed if we attempt to insert a pair (s,c) in STC, then we have to define the effect of this insertion on the base tabular variable. This is clearly
5.23 ครั้งใน SQL 155
เลือกชื่อจากเอสทีซีที่ CNO = 'cs110';
ในความเป็นจริงนี้ SQL รวมวลีเลือกด้วยแบบสอบถามแสดงเพียงและดำเนิน Fi Modi เอ็ดแบบสอบถาม:
เลือก STUDENTS.name จากนักเรียน, การเรียนที่ STUDENTS.stno = เรียน stno และ GRADES.cno = 'cs110';
ตัวอย่างก่อนหน้านี้แสดงให้เห็นว่ามุมมองใน SQL มีบทบาทคล้ายกับบทบาทของแมโครในการเขียนโปรแกรมภาษา ผู้ชมมีความสำคัญต่อความปลอดภัยของข้อมูล ผู้ใช้ที่ต้องการให้มีการเข้าถึงเฉพาะรายชื่อนักเรียนและหลักสูตรที่พวกเขามีการตอบสนองความต้องการที่จะทราบเพียงอย่างเดียวของการดำรงอยู่ของเอสทีซี หากผู้มีอำนาจที่จะใช้สร้างเลือกเท่านั้นจากนั้นผู้ใช้สามารถละเว้นไม่ว่าจะเป็นเอสทีซีเป็นตารางหรือมุมมอง Con Fi ข้อมูล dential (เช่นเกรดที่ได้รับในหลักสูตรคที่ระบุไว้) ได้รับความคุ้มครองอย่างสมบูรณ์ในลักษณะนี้ นอกจากนี้คำสั่งที่ว่านี้ผู้ใช้ จำกัด การเข้าถึงอาจเขียนเป็นง่ายและง่ายต่อการเข้าใจ ไม่มีพื้นที่จะสูญเสียกับเอสทีซีมุมมองและมุมมองยังคงเป็นปัจจุบันเสมออีกชั้น ecting เนื้อหาของตัวแปรตารางนักเรียนและการเรียน SQL ปฏิบัติต่อมุมมองที่ตรงตามที่ให้การปฏิบัติต่อตัวแปรตารางเท่าที่ดึงความกังวล นอกจากนี้เรายังสามารถมอบหมายสิทธิ์เลือกไปยังมุมมองในตรงทางเดียวกับที่เราทำสำหรับตัวแปรตาราง ตัวอย่างเช่นหากผู้ใช้สร้างมุมมองที่จอร์จเอสทีซีแล้วเขาสามารถให้สิทธิเลือกเพื่อแวนด้าโดยการเขียน:
ทุนเลือกใน STC เพื่อแวนด้า;
พิจารณาในขณะนี้ตัวอย่างของมุมมองอื่น: ตัวอย่าง 5.23.2 SNA มุมมองที่มีจำนวนนักเรียน และชื่อของนักเรียนที่สามารถสร้างขึ้นโดย:
สร้างมุมมอง SNA เป็น stno เลือกชื่อจากนักเรียน
วัตถุประสงค์ของมุมมองนี้คือการประกันความเป็นส่วนตัวให้กับนักเรียน ผู้ใช้ที่มีการเข้าถึงเฉพาะมุมมองนี้สามารถดึงข้อมูลจำนวนนักเรียนและชื่อของนักเรียน แต่ไม่ได้อยู่ของนักเรียน มีการตั้งดิ ff พื้นฐานระหว่างมุมมองที่นำมาใช้ในตัวอย่าง 5.23.1 และ 5.23.2 เป็นและนี้หมายถึงวิธีการที่ทั้งสองมุมมองที่มีพฤติกรรมเกี่ยวกับการปรับปรุง สมมติว่าผู้ใช้มีความประสงค์จะใส่คู่ (7799, 'เจนโจนส์) ในมุมมอง SNA ผู้ใช้อาจไม่สนใจทั้งหมดความจริงที่ว่า SNA ไม่ตัวแปรตารางฐาน ในทางตรงกันข้าม, อี ff ect บนฐานตัวแปรตารางแทรกนี้จะถูกกำหนดอย่างแจ่มแจ้ง: แทรกระบบในนักเรียนตัวแปรตาราง tuple (7799, 'เจนโจนส์', null, null, null) ในทางกลับกันเราไม่สามารถแทรก tuple ในทางที่มีความหมายในมุมมอง STC นำมาใช้ในตัวอย่าง 5.23.1 อันที่จริงถ้าเราพยายามที่จะแทรกคู่ (s ค) ในเอสทีซีแล้วเรามีให้กับสายตะวันออกเฉียงเหนือจ ff ect แทรกนี้บนตัวแปรตารางฐาน นี้จะชัดเจน
การแปล กรุณารอสักครู่..
