Intermediate SQLSQL المتوسطة
مقدمة الفصل
ماذا ستتعلم في هذا الفصل
- Join expressions: inner join, natural join, and left, right and full outer joins.
- Views: definition, views defined using other views, view expansion, updates through views and materialized views.
- Transactions, and integrity constraints: not null, unique, check, referential integrity and cascading actions.
- SQL data types and schemas: date, time, timestamp, interval, indices, user-defined types, domains and large objects.
- Authorization: privileges, grant and revoke, roles, authorization on views.
أقسام الفصل
- 1Joined relations and inner joinالربط والربط الداخلي
- 2Outer joinsالربط الخارجي
- 3Viewsالعروض
- 4Views defined using other views; view expansionالعروض المبنية على عروض وتوسيع العرض
- 5Updates through views; materialized viewsالتحديث عبر العروض والعروض المجسّدة
- 6Transactionsالمعاملات
- 7Integrity constraints on a single relationقيود السلامة على علاقة واحدة
- 8Referential integrity and cascading actionsالسلامة المرجعية والإجراءات المتتالية
- 9SQL data types, indices, user-defined types and domainsأنواع البيانات والفهارس والأنواع والنطاقات
- 10Authorization: privileges, grant and revokeالصلاحيات: الامتيازات وgrant وrevoke
- 11Roles and other authorization featuresالأدوار وميزات أخرى للصلاحيات
تلميح: استخدم أسهم لوحة المفاتيح للتنقل بين الشرائح.
Join operationsعمليات الربط
Joined relations and inner join
Takes two relations and returns another relation: a Cartesian product which requires that tuples in the two relations match (under some condition), and specifies the attributes present in the result.
Defines which tuples in the two relations match, and what attributes are present in the result.
Defines how tuples that do not match any tuple in the other relation are treated.
Join typesأنواع الربط
- inner join
- left outer join
- right outer join
- full outer join
Join conditionsشروط الربط
- natural
- on <predicate>
- using (A1, A2, …, An)
- The join operations are typically used as subquery expressions in the from clause (slides 3 and 9).
| course_id | title | dept_name | credits |
|---|---|---|---|
| BIO-301 | Genetics | Biology | 4 |
| CS-190 | Game Design | Comp. Sci. | 4 |
| CS-315 | Robotics | Comp. Sci. | 3 |
| course_id | prereq_id |
|---|---|
| BIO-301 | BIO-101 |
| CS-190 | CS-101 |
| CS-347 | CS-101 |
- prereq information is missing for CS-315 and course information is missing for CS-347.
Inner joinالربط الداخلي
Returns rows only when there is at least one row from both tables that matches the join condition.
| course_id | title | dept_name | credits | prereq_id | course_id |
|---|---|---|---|---|---|
| BIO-301 | Genetics | Biology | 4 | BIO-101 | BIO-301 |
| CS-190 | Game Design | Comp. Sci. | 4 | CS-101 | CS-190 |
Outer joins: left, right, fullالربط الخارجي
An extension of the join operation that avoids loss of information: it computes the join and then adds tuples from one relation that do not match tuples in the other, using null values.
| Join typeنوع الربط | Rows retrievedالصفوف المسترجعة |
|---|---|
| Inner join | Only rows that match in both tables |
| Left outer join | All rows from the left table |
| Right outer join | All rows from the right table |
| Full outer join | All rows from both tables |
- Outer joins return all rows from at least one of the tables or views mentioned in the FROM clause, as long as those rows meet any WHERE or HAVING search conditions (slide 5).
Outer join resultsنتائج الربط الخارجي
Outer joins
| course_id | title | dept_name | credits | prereq_id |
|---|---|---|---|---|
| BIO-301 | Genetics | Biology | 4 | BIO-101 |
| CS-190 | Game Design | Comp. Sci. | 4 | CS-101 |
| CS-315 | Robotics | Comp. Sci. | 3 | null |
| course_id | title | dept_name | credits | prereq_id |
|---|---|---|---|---|
| BIO-301 | Genetics | Biology | 4 | BIO-101 |
| CS-190 | Game Design | Comp. Sci. | 4 | CS-101 |
| CS-315 | Robotics | Comp. Sci. | 3 | null |
| CS-347 | null | null | null | CS-101 |
Join syntax examplesصيغ الربط
Outer joins
| course_id | title | dept_name | credits | prereq_id | course_id |
|---|---|---|---|---|---|
| BIO-301 | Genetics | Biology | 4 | BIO-101 | BIO-301 |
| CS-190 | Game Design | Comp. Sci. | 4 | CS-101 | CS-190 |
| CS-315 | Robotics | Comp. Sci. | 3 | null | null |
| course_id | title | dept_name | credits | prere_id |
|---|---|---|---|---|
| BIO-301 | Genetics | Biology | 4 | BIO-101 |
| CS-190 | Game Design | Comp. Sci. | 4 | CS-101 |
| CS-315 | Robotics | Comp. Sci. | 3 | null |
| CS-347 | null | null | null | CS-101 |
- on gives the join condition explicitly (the matched attribute appears from both relations); natural matches all attributes with the same name; using (course_id) names the attribute to match.
- Slide 15: to list all students with the courses they have taken — including students who took none — use student natural left outer join takes (or takes natural right outer join student).
Example: student and takesمثال student وtakes
Outer joins
| ID | name | dept_name | tot_cred |
|---|---|---|---|
| 00128 | Zhang | Comp. Sci. | 102 |
| 12345 | Shankar | Comp. Sci. | 32 |
| 19991 | Brandt | History | 80 |
| 23121 | Chavez | Finance | 110 |
| 44553 | Peltier | Physics | 56 |
| 45678 | Levy | Physics | 46 |
| 54321 | Williams | Comp. Sci. | 54 |
| 55739 | Sanchez | Music | 38 |
| 70557 | Snow | Physics | 0 |
| 76543 | Brown | Comp. Sci. | 58 |
| 76653 | Aoi | Elec. Eng. | 60 |
| 98765 | Bourikas | Elec. Eng. | 98 |
| 98988 | Tanaka | Biology | 120 |
| ID | course_id | sec_id | semester | year | grade |
|---|---|---|---|---|---|
| 00128 | CS-101 | 1 | Fall | 2009 | A |
| 00128 | CS-347 | 1 | Fall | 2009 | A- |
| 12345 | CS-101 | 1 | Fall | 2009 | C |
| 12345 | CS-190 | 2 | Spring | 2009 | A |
| 12345 | CS-315 | 1 | Spring | 2010 | A |
| 12345 | CS-347 | 1 | Fall | 2009 | A |
| 19991 | HIS-351 | 1 | Spring | 2010 | B |
| 23121 | FIN-201 | 1 | Spring | 2010 | C+ |
| 44553 | PHY-101 | 1 | Fall | 2009 | B- |
| 45678 | CS-101 | 1 | Fall | 2009 | F |
| 45678 | CS-101 | 1 | Spring | 2010 | B+ |
| 45678 | CS-319 | 1 | Spring | 2010 | B |
| 54321 | CS-101 | 1 | Fall | 2009 | A- |
| 54321 | CS-190 | 2 | Spring | 2009 | B+ |
| 55739 | MU-199 | 1 | Spring | 2010 | A- |
| 76543 | CS-101 | 1 | Fall | 2009 | A |
| 76543 | CS-319 | 2 | Spring | 2010 | A |
| 76653 | EE-181 | 1 | Spring | 2009 | C |
| 98765 | CS-101 | 1 | Fall | 2009 | C- |
| 98765 | CS-315 | 1 | Spring | 2010 | B |
| 98988 | BIO-101 | 1 | Summer | 2009 | A |
| 98988 | BIO-301 | 1 | Summer | 2010 | null |
student natural join takesالربط الطبيعي
Outer joins
Slide 15: to display a list of all students, with their ID, name, dept_name and tot_cred, along with the courses they have taken: select * from student natural join takes; Its result is slide 16.
| ID | name | dept_name | tot_cred | course_id | sec_id | semester | year | grade |
|---|---|---|---|---|---|---|---|---|
| 00128 | Zhang | Comp. Sci. | 102 | CS-101 | 1 | Fall | 2009 | A |
| 00128 | Zhang | Comp. Sci. | 102 | CS-347 | 1 | Fall | 2009 | A- |
| 12345 | Shankar | Comp. Sci. | 32 | CS-101 | 1 | Fall | 2009 | C |
| 12345 | Shankar | Comp. Sci. | 32 | CS-190 | 2 | Spring | 2009 | A |
| 12345 | Shankar | History | 32 | CS-315 | 1 | Spring | 2010 | A |
| 12345 | Shankar | Finance | 32 | CS-347 | 1 | Fall | 2009 | A |
| 19991 | Brandt | Music | 80 | HIS-351 | 1 | Spring | 2010 | B |
| 23121 | Chavez | Physics | 110 | FIN-201 | 1 | Spring | 2010 | C+ |
| 44553 | Peltier | Physics | 56 | PHY-101 | 1 | Fall | 2009 | B- |
| 45678 | Levy | Physics | 46 | CS-101 | 1 | Fall | 2009 | F |
| 45678 | Levy | Physics | 46 | CS-101 | 1 | Spring | 2010 | B+ |
| 45678 | Levy | Physics | 46 | CS-319 | 1 | Spring | 2010 | B |
| 54321 | Williams | Comp. Sci. | 54 | CS-101 | 1 | Fall | 2009 | A- |
| 54321 | Williams | Comp. Sci. | 54 | CS-190 | 2 | Spring | 2009 | B+ |
| 55739 | Sanchez | Music | 38 | MU-199 | 1 | Spring | 2010 | A- |
| 76543 | Brown | Comp. Sci. | 58 | CS-101 | 1 | Fall | 2009 | A |
| 76543 | Brown | Comp. Sci. | 58 | CS-319 | 2 | Spring | 2010 | A |
| 76653 | Aoi | Elec. Eng. | 60 | EE-181 | 1 | Spring | 2009 | C |
| 98765 | Bourikas | Elec. Eng. | 98 | CS-101 | 1 | Fall | 2009 | C- |
| 98765 | Bourikas | Elec. Eng. | 98 | CS-315 | 1 | Spring | 2010 | B |
| 98988 | Tanaka | Biology | 120 | BIO-101 | 1 | Summer | 2009 | A |
| 98988 | Tanaka | Biology | 120 | BIO-301 | 1 | Summer | 2010 | null |
Slide 19
- select * from student join takes using (ID); is equivalent to select * from student inner join takes using (ID);
- Similarly, natural join is equivalent to natural inner join.
Natural left and right outer joins of student and takesالربط الخارجي
| ID | name | dept_name | tot_cred | course_id | sec_id | semester | year | grade |
|---|---|---|---|---|---|---|---|---|
| 00128 | Zhang | Comp. Sci. | 102 | CS-101 | 1 | Fall | 2009 | A |
| 00128 | Zhang | Comp. Sci. | 102 | CS-347 | 1 | Fall | 2009 | A- |
| 12345 | Shankar | Comp. Sci. | 32 | CS-101 | 1 | Fall | 2009 | C |
| 12345 | Shankar | Comp. Sci. | 32 | CS-190 | 2 | Spring | 2009 | A |
| 12345 | Shankar | History | 32 | CS-315 | 1 | Spring | 2010 | A |
| 12345 | Shankar | Finance | 32 | CS-347 | 1 | Fall | 2009 | A |
| 19991 | Brandt | Music | 80 | HIS-351 | 1 | Spring | 2010 | B |
| 23121 | Chavez | Physics | 110 | FIN-201 | 1 | Spring | 2010 | C+ |
| 44553 | Peltier | Physics | 56 | PHY-101 | 1 | Fall | 2009 | B- |
| 45678 | Levy | Physics | 46 | CS-101 | 1 | Fall | 2009 | F |
| 45678 | Levy | Physics | 46 | CS-101 | 1 | Spring | 2010 | B+ |
| 45678 | Levy | Physics | 46 | CS-319 | 1 | Spring | 2010 | B |
| 54321 | Williams | Comp. Sci. | 54 | CS-101 | 1 | Fall | 2009 | A- |
| 54321 | Williams | Comp. Sci. | 54 | CS-190 | 2 | Spring | 2009 | B+ |
| 55739 | Sanchez | Music | 38 | MU-199 | 1 | Spring | 2010 | A- |
| 70557 | Snow | Physics | 0 | null | null | null | null | null |
| 76543 | Brown | Comp. Sci. | 58 | CS-101 | 1 | Fall | 2009 | A |
| 76543 | Brown | Comp. Sci. | 58 | CS-319 | 2 | Spring | 2010 | A |
| 76653 | Aoi | Elec. Eng. | 60 | EE-181 | 1 | Spring | 2009 | C |
| 98765 | Bourikas | Elec. Eng. | 98 | CS-101 | 1 | Fall | 2009 | C- |
| 98765 | Bourikas | Elec. Eng. | 98 | CS-315 | 1 | Spring | 2010 | B |
| 98988 | Tanaka | Biology | 120 | BIO-101 | 1 | Summer | 2009 | A |
| 98988 | Tanaka | Biology | 120 | BIO-301 | 1 | Summer | 2010 | null |
| ID | course_id | sec_id | semester | year | grade | name | dept_name | tot_cred |
|---|---|---|---|---|---|---|---|---|
| 00128 | CS-101 | 1 | Fall | 2009 | A | Zhang | Comp. Sci. | 102 |
| 00128 | CS-347 | 1 | Fall | 2009 | A- | Zhang | Comp. Sci. | 102 |
| 12345 | CS-101 | 1 | Fall | 2009 | C | Shankar | Comp. Sci. | 32 |
| 12345 | CS-190 | 2 | Spring | 2009 | A | Shankar | Comp. Sci. | 32 |
| 12345 | CS-315 | 1 | Spring | 2010 | A | Shankar | History | 32 |
| 12345 | CS-347 | 1 | Fall | 2009 | A | Shankar | Finance | 32 |
| 19991 | HIS-351 | 1 | Spring | 2010 | B | Brandt | Music | 80 |
| 23121 | FIN-201 | 1 | Spring | 2010 | C+ | Chavez | Physics | 110 |
| 44553 | PHY-101 | 1 | Fall | 2009 | B- | Peltier | Physics | 56 |
| 45678 | CS-101 | 1 | Fall | 2009 | F | Levy | Physics | 46 |
| 45678 | CS-101 | 1 | Spring | 2010 | B+ | Levy | Physics | 46 |
| 45678 | CS-319 | 1 | Spring | 2010 | B | Levy | Physics | 46 |
| 54321 | CS-101 | 1 | Fall | 2009 | A- | Williams | Comp. Sci. | 54 |
| 54321 | CS-190 | 2 | Spring | 2009 | B+ | Williams | Comp. Sci. | 54 |
| 55739 | MU-199 | 1 | Spring | 2010 | A- | Sanchez | Music | 38 |
| 70557 | null | null | null | null | null | Snow | Physics | 0 |
| 76543 | CS-101 | 1 | Fall | 2009 | A | Brown | Comp. Sci. | 58 |
| 76543 | CS-319 | 2 | Spring | 2010 | A | Brown | Comp. Sci. | 58 |
| 76653 | EE-181 | 1 | Spring | 2009 | C | Aoi | Elec. Eng. | 60 |
| 98765 | CS-101 | 1 | Fall | 2009 | C- | Bourikas | Elec. Eng. | 98 |
| 98765 | CS-315 | 1 | Spring | 2010 | B | Bourikas | Elec. Eng. | 98 |
| 98988 | BIO-101 | 1 | Summer | 2009 | A | Tanaka | Biology | 120 |
| 98988 | BIO-301 | 1 | Summer | 2010 | null | Tanaka | Biology | 120 |
Viewsالعروض
In some cases it is not desirable for all users to see the entire logical model. A person who needs an instructor's name and department, but not the salary, should see: select ID, name, dept_name from instructor.
Any relation that is not of the conceptual model but is made visible to a user as a "virtual relation". A view provides a mechanism to hide certain data from the view of certain users. Defined with create view v as < query expression >.
- View definition is not the same as creating a new relation by evaluating the query expression.
- Rather, a view definition causes the saving of an expression; the expression is substituted into queries using the view.
Example viewsأمثلة العروض
View dependencies and view expansionتوسيع العرض
Views defined using other views; view expansion
v1 depends directly on v2 if v2 is used in the expression defining v1.
v1 depends on v2 if v1 depends directly on v2 or there is a path of dependencies from v1 to v2.
A view relation v is recursive if it depends on itself.
View expansion (slide 26)
- 1
repeat: find any view relation vi in e1
- 2
Replace the view relation vi by the expression defining vi
- 3
until no more view relations are present in e1
- As long as the view definitions are not recursive, this loop will terminate.
Updating through viewsالتحديث عبر العرض
Updates through views; materialized views
المسألة
insert into faculty values ('30765', 'Green', 'Music'); — faculty shows ID, name, dept_name of instructor. (slide 27)
خطوات الحل
- The view has no salary column.
- The insertion must be represented in instructor, with the missing attribute set to null.
النتيجة
Insert ('30765', 'Green', 'Music', null) into instructor.
Some updates cannot be translated uniquely (slide 28)
- instructor_info shows ID, name, building from instructor and department. Inserting ('69987', 'White', 'Taylor'): which department, if multiple departments are in Taylor? What if no department is in Taylor?
Most SQL implementations allow updates only on simple views
- The from clause has only one database relation.
- The select clause contains only attribute names of the relation — no expressions, aggregates or distinct.
- Any attribute not listed in select can be set to null.
- The query has no group by or having clause.
Updating through a view: what the slides showتحديث العروض
Updates through views; materialized views
Slide 29 ("Updates") shows the two relations after the tuple ('69987', 'White', 'Taylor') of slide 28 is given to the view instructor_info: a new instructor 69987 White with null dept_name and salary, and a new department tuple (null, Taylor, null).
| ID | name | dept_name | salary |
|---|---|---|---|
| 10101 | Srinivasan | Comp. Sci. | 65000 |
| 12121 | Wu | Finance | 90000 |
| 15151 | Mozart | Music | 40000 |
| 22222 | Einstein | Physics | 95000 |
| 32343 | El Said | History | 60000 |
| 33456 | Gold | Physics | 87000 |
| 45565 | Katz | Comp. Sci. | 75000 |
| 58583 | Califieri | History | 62000 |
| 76543 | Singh | Finance | 80000 |
| 76766 | Crick | Biology | 72000 |
| 83821 | Brandt | Comp. Sci. | 92000 |
| 98345 | Kim | Elec. Eng. | 80000 |
| 69987 | White | null | null |
| dept_name | building | budget |
|---|---|---|
| Biology | Watson | 90000 |
| Comp. Sci. | Taylor | 100000 |
| Elec. Eng. | Taylor | 85000 |
| Finance | Painter | 120000 |
| History | Painter | 50000 |
| Music | Packard | 80000 |
| Physics | Watson | 70000 |
| null | Taylor | null |
And some not at all (slide 30)
- create view history_instructors as select * from instructor where dept_name = 'History';
- What happens if we insert ('25566', 'Brown', 'Biology', 100000) into history_instructors? (The slide asks the question and gives no answer.)
Materialized viewsالعروض المجسّدة
Create a physical table containing all the tuples in the result of the query defining the view.
- If the relations used in the query are updated, the materialized view result becomes out of date.
- The view must be maintained — updated whenever the underlying relations are updated.
Transactions in SQLالمعاملات
- A transaction is a unit of work.
- Atomic transaction: either fully executed or rolled back as if it never occurred.
- Isolation from concurrent transactions.
- Transactions begin implicitly and are ended by commit work or rollback work.
- Default on most databases: each SQL statement commits automatically; auto commit can be turned off for a session (e.g., using an API).
- SQL:1999: begin atomic … end — not supported on most databases.
not null, unique and checkunique وcheck
Integrity constraints on a single relation
Guard against accidental damage to the database, by ensuring that authorized changes do not result in a loss of data consistency.
Examples (slide 33)
- A checking account must have a balance greater than $10,000.00.
- A salary of a bank employee must be at least $4.00 an hour.
- A customer must have a (non-null) phone number.
Constraints on a single relation (slide 34)
- not null
- primary key
- unique
- check (P)
- unique (A1, …, Am): the attributes form a candidate key; candidate keys are permitted to be null (in contrast to primary keys).
- check (P), P a predicate — e.g., check (semester in ('Fall', 'Winter', 'Spring', 'Summer')).
Referential integrityالسلامة المرجعية
Ensures that a value that appears in one relation for a given set of attributes also appears for a certain set of attributes in another relation — e.g., if "Biology" appears in instructor, there is a "Biology" tuple in department.
- If A is the primary key of S, A is a foreign key of R if every value of A appearing in R also appears in S.
- Alternative actions to cascade: set null, set default.
A foreign key between course and departmentمثال المفتاح الأجنبي
Referential integrity and cascading actions
| course_id | title | dept_name | credits |
|---|---|---|---|
| BIO-101 | Intro. to Biology | Biology | 4 |
| BIO-301 | Genetics | Biology | 4 |
| BIO-399 | Computational Biology | Biology | 3 |
| CS-101 | Intro. to Computer Science | Comp. Sci. | 4 |
| CS-190 | Game Design | Comp. Sci. | 4 |
| CS-315 | Robotics | Comp. Sci. | 3 |
| CS-319 | Image Processing | Comp. Sci. | 3 |
| CS-347 | Database System Concepts | Comp. Sci. | 3 |
| EE-181 | Intro. to Digital Systems | Elec. Eng. | 3 |
| FIN-201 | Investment Banking | Finance | 3 |
| HIS-351 | World History | History | 3 |
| MU-199 | Music Video Production | Music | 3 |
| PHY-101 | Physical Principles | Physics | 4 |
| DEPT_NAME | BUILDING | BUDGET |
|---|---|---|
| Biology | Watson | 90000 |
| Comp. Sci. | Taylor | 100000 |
| Elec. Eng. | Taylor | 85000 |
| Finance | Painter | 120000 |
| History | Painter | 50000 |
| Music | Packard | 80000 |
| Physics | Watson | 70000 |
Constraint violations and complex checksانتهاك القيود
Referential integrity and cascading actions
المسألة
person(name, spouse), primary key (name), foreign key spouse references person. Insert John (spouse Mary) and Mary (spouse John). (slide 40)
خطوات الحل
- When the first tuple is inserted, its spouse does not exist yet.
- When the second tuple is inserted, both spouses exist.
النتيجة
The first insertion violates the foreign-key constraint, regardless of which tuple is inserted first; after the second insertion the constraint holds again.
- How to insert a tuple without causing constraint violation? (slide 40 asks this; it gives no answer)
Complex check clauses (slide 41)
- check (time_slot_id in (select time_slot_id from time_slot)).
- Subquery in check clause: not supported by pretty much any database; alternative: triggers.
- create assertion <assertion-name> check <predicate> — also not supported by anyone.
Questions on slide 41
- check (time_slot_id in (select time_slot_id from time_slot)) — why not use a foreign key here?
- Every section has at least one instructor teaching the section — how to write this?
Date and time types, defaults and indicesالأنواع والفهارس
SQL data types, indices, user-defined types and domains
| Typeالنوع | Meaningالمعنى | Exampleمثال |
|---|---|---|
| date | 4-digit year, month and date | date '2005-7-27' |
| time | Time of day: hours, minutes and seconds | time '09:00:30', time '09:00:30.75' |
| timestamp | Date plus time of day | timestamp '2005-7-27 09:00:30.75' |
| interval | Period of time | interval '1' day |
- Subtracting a date/time/timestamp value from another gives an interval value; interval values can be added to date/time/timestamp values.
- default: tot_cred numeric(3,0) default 0.
- create index studentID_index on student(ID) — indices are data structures used to speed up access to records with specified values for index attributes; select * from student where ID = '12345' can find the record without looking at all records.
User-defined types, domains and large objectsالأنواع والنطاقات
SQL data types, indices, user-defined types and domains
- Types and domains are similar. Domains can have constraints, such as not null, specified on them.
Large objects (photos, videos, CAD files, etc.) are stored as a large object (slide 46).
Binary large object — a large collection of uninterpreted binary data, whose interpretation is left to an application outside the database system.
Character large object — a large collection of character data.
- When a query returns a large object, a pointer is returned rather than the large object itself.
Forms of authorizationأشكال الصلاحيات
Authorization: privileges, grant and revoke
On parts of the databaseعلى البيانات
- Read — reading, but not modification of data.
- Insert — insertion of new data, but not modification of existing data.
- Update — modification, but not deletion of data.
- Delete — deletion of data.
To modify the schemaعلى المخطط
- Index — creation and deletion of indices.
- Resources — creation of new relations.
- Alteration — addition or deletion of attributes in a relation.
- Drop — deletion of relations.
grant and revokegrant وrevoke
grant <privilege list> on <relation name or view name> to <user list> — the user list is a user-id, public (all valid users), or a role.
- Granting a privilege on a view does not imply granting any privileges on the underlying relations.
- The grantor must already hold the privilege on the item (or be the database administrator).
- Privileges: select (read access, or querying using the view), insert, update, delete, all privileges.
- Example: grant select on instructor to U1, U2, U3
revoke <privilege list> on <relation name or view name> from <user list> — e.g., revoke select on branch from U1, U2, U3; the list may be all.
- Revoking from public: all users lose the privilege except those granted it explicitly.
- If the same privilege was granted twice by different grantees, the user may retain it after the revocation.
- All privileges that depend on the privilege being revoked are also revoked.
Roles and other authorization featuresالأدوار
- Privileges can be granted to roles; roles can be granted to users, as well as to other roles.
- After grant teaching_assistant to instructor, instructor inherits all privileges of teaching_assistant (a chain of roles).
- references privilege to create a foreign key: grant reference (dept_name) on department to Mariano.
- Transfer of privileges: grant select on department to Amit with grant option; revoke … from Amit, Satoshi cascade or restrict.
Authorization on views and the authorization graphرسم الصلاحيات
Roles and other authorization features
What if (slide 52)
- geo_staff does not have permissions on instructor?
- creator of view did not have some permissions on instructor?
- references privilege to create foreign key — why is this required? (slide 53)
| From | To |
|---|---|
| DBA | U1 |
| DBA | U2 |
| DBA | U3 |
| U1 | U4 |
| U1 | U5 |
| U2 | U5 |
الخلاصة
أنهيت الدرس
الخطوة التالية: ثبّت المعلومات بالبطاقات، ثم اختبر نفسك بالأسئلة.
ما راجعته في هذا الدرس
- Joined relations and inner joinالربط والربط الداخلي
- Outer joinsالربط الخارجي
- Viewsالعروض
- Views defined using other views; view expansionالعروض المبنية على عروض وتوسيع العرض
- Updates through views; materialized viewsالتحديث عبر العروض والعروض المجسّدة
- Transactionsالمعاملات
- Integrity constraints on a single relationقيود السلامة على علاقة واحدة
- Referential integrity and cascading actionsالسلامة المرجعية والإجراءات المتتالية
- SQL data types, indices, user-defined types and domainsأنواع البيانات والفهارس والأنواع والنطاقات
- Authorization: privileges, grant and revokeالصلاحيات: الامتيازات وgrant وrevoke
- Roles and other authorization featuresالأدوار وميزات أخرى للصلاحيات