Intermediate SQLSQL المتوسطة

الشريحة 1 من 27

مقدمة الفصل

ماذا ستتعلم في هذا الفصل

  1. Join expressions: inner join, natural join, and left, right and full outer joins.
  2. Views: definition, views defined using other views, view expansion, updates through views and materialized views.
  3. Transactions, and integrity constraints: not null, unique, check, referential integrity and cascading actions.
  4. SQL data types and schemas: date, time, timestamp, interval, indices, user-defined types, domains and large objects.
  5. Authorization: privileges, grant and revoke, roles, authorization on views.
تفاصيل المصدرالفصل 4 · الشريحة ⁦2⁩
المصدر
الفصل 4 · الشريحة ⁦2⁩

Join operationsعمليات الربط

Joined relations and inner join

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.
Join conditionشرط الربط
Defines which tuples in the two relations match, and what attributes are present in the result.
Join typeنوع الربط
Defines how tuples that do not match any tuple in the other relation are treated.
Join types and join conditions (slide 9)

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 (slide 4)
course_idtitledept_namecredits
BIO-301GeneticsBiology4
CS-190Game DesignComp. Sci.4
CS-315RoboticsComp. Sci.3
prereq (slide 4)
course_idprereq_id
BIO-301BIO-101
CS-190CS-101
CS-347CS-101
  • prereq information is missing for CS-315 and course information is missing for CS-347.

What does the join type of a joined relation define?

تفاصيل المصدرالفصل 4 · الشرائح ⁦3, 4, 9⁩
المصدر
الفصل 4 · الشرائح ⁦3, 4, 9⁩

Inner joinالربط الداخلي

Inner join
Returns rows only when there is at least one row from both tables that matches the join condition.
course inner join prereq on course.course_id = prereq.course_id (slide 11)
course_idtitledept_namecreditsprereq_idcourse_id
BIO-301GeneticsBiology4BIO-101BIO-301
CS-190Game DesignComp. Sci.4CS-101CS-190

course has CS-315 with no prereq row, and prereq has CS-347 with no course row. Which course_id values appear in course inner join prereq on course.course_id = prereq.course_id?

تفاصيل المصدرالفصل 4 · الشرائح ⁦5, 11⁩
المصدر
الفصل 4 · الشرائح ⁦5, 11⁩

Outer joins: left, right, fullالربط الخارجي

Outer join
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.
Which rows are kept (slide 5)
Join typeنوع الربطRows retrievedالصفوف المسترجعة
Inner joinOnly rows that match in both tables
Left outer joinAll rows from the left table
Right outer joinAll rows from the right table
Full outer joinAll 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).

Which join returns all rows from both tables?

تفاصيل المصدرالفصل 4 · الشرائح ⁦5–6⁩
المصدر
الفصل 4 · الشرائح ⁦5–6⁩

Outer join resultsنتائج الربط الخارجي

Outer joins

course natural left outer join prereq (slide 7)
course_idtitledept_namecreditsprereq_id
BIO-301GeneticsBiology4BIO-101
CS-190Game DesignComp. Sci.4CS-101
CS-315RoboticsComp. Sci.3null
course natural full outer join prereq (slide 10)
course_idtitledept_namecreditsprereq_id
BIO-301GeneticsBiology4BIO-101
CS-190Game DesignComp. Sci.4CS-101
CS-315RoboticsComp. Sci.3null
CS-347nullnullnullCS-101

How many rows does course natural full outer join prereq return?

تفاصيل المصدرالفصل 4 · الشرائح ⁦7, 10⁩
المصدر
الفصل 4 · الشرائح ⁦7, 10⁩

Join syntax examplesصيغ الربط

Outer joins

من الشرائح

  • course inner join prereq on course.course_id = prereq.course_id
  • course left outer join prereq on course.course_id = prereq.course_id
  • course natural right outer join prereq
  • course full outer join prereq using (course_id)
  • select * from student natural join takes;
  • select * from student natural left outer join takes;
  • select * from takes natural right outer join student;
course left outer join prereq on course.course_id = prereq.course_id (slide 11)
course_idtitledept_namecreditsprereq_idcourse_id
BIO-301GeneticsBiology4BIO-101BIO-301
CS-190Game DesignComp. Sci.4CS-101CS-190
CS-315RoboticsComp. Sci.3nullnull
course full outer join prereq using (course_id) (slide 12)
course_idtitledept_namecreditsprere_id
BIO-301GeneticsBiology4BIO-101
CS-190Game DesignComp. Sci.4CS-101
CS-315RoboticsComp. Sci.3null
CS-347nullnullnullCS-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).

You want to list ALL students with the courses they have taken, including students who have not taken any course. Which query does this?

تفاصيل المصدرالفصل 4 · الشرائح ⁦11, 12, 15⁩
المصدر
الفصل 4 · الشرائح ⁦11, 12, 15⁩

Example: student and takesمثال student وtakes

Outer joins

Student (slide 13)
IDnamedept_nametot_cred
00128ZhangComp. Sci.102
12345ShankarComp. Sci.32
19991BrandtHistory80
23121ChavezFinance110
44553PeltierPhysics56
45678LevyPhysics46
54321WilliamsComp. Sci.54
55739SanchezMusic38
70557SnowPhysics0
76543BrownComp. Sci.58
76653AoiElec. Eng.60
98765BourikasElec. Eng.98
98988TanakaBiology120
Takes (slide 13)
IDcourse_idsec_idsemesteryeargrade
00128CS-1011Fall2009A
00128CS-3471Fall2009A-
12345CS-1011Fall2009C
12345CS-1902Spring2009A
12345CS-3151Spring2010A
12345CS-3471Fall2009A
19991HIS-3511Spring2010B
23121FIN-2011Spring2010C+
44553PHY-1011Fall2009B-
45678CS-1011Fall2009F
45678CS-1011Spring2010B+
45678CS-3191Spring2010B
54321CS-1011Fall2009A-
54321CS-1902Spring2009B+
55739MU-1991Spring2010A-
76543CS-1011Fall2009A
76543CS-3192Spring2010A
76653EE-1811Spring2009C
98765CS-1011Fall2009C-
98765CS-3151Spring2010B
98988BIO-1011Summer2009A
98988BIO-3011Summer2010null
تفاصيل المصدرالفصل 4 · الشريحة ⁦13⁩
المصدر
الفصل 4 · الشريحة ⁦13⁩

student natural join takesالربط الطبيعي

Outer joins

من الشرائح

  • select * from student join takes on student.ID = takes.ID;
  • select * from student, takes where student.ID = takes.ID;
  • select student.ID as ID, name, dept_name, tot_cred, course_id, sec_id, semester, year, grade from student join takes on student.ID = takes.ID;

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.

student natural join takes (slide 16)
IDnamedept_nametot_credcourse_idsec_idsemesteryeargrade
00128ZhangComp. Sci.102CS-1011Fall2009A
00128ZhangComp. Sci.102CS-3471Fall2009A-
12345ShankarComp. Sci.32CS-1011Fall2009C
12345ShankarComp. Sci.32CS-1902Spring2009A
12345ShankarHistory32CS-3151Spring2010A
12345ShankarFinance32CS-3471Fall2009A
19991BrandtMusic80HIS-3511Spring2010B
23121ChavezPhysics110FIN-2011Spring2010C+
44553PeltierPhysics56PHY-1011Fall2009B-
45678LevyPhysics46CS-1011Fall2009F
45678LevyPhysics46CS-1011Spring2010B+
45678LevyPhysics46CS-3191Spring2010B
54321WilliamsComp. Sci.54CS-1011Fall2009A-
54321WilliamsComp. Sci.54CS-1902Spring2009B+
55739SanchezMusic38MU-1991Spring2010A-
76543BrownComp. Sci.58CS-1011Fall2009A
76543BrownComp. Sci.58CS-3192Spring2010A
76653AoiElec. Eng.60EE-1811Spring2009C
98765BourikasElec. Eng.98CS-1011Fall2009C-
98765BourikasElec. Eng.98CS-3151Spring2010B
98988TanakaBiology120BIO-1011Summer2009A
98988TanakaBiology120BIO-3011Summer2010null

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.
تفاصيل المصدرالفصل 4 · الشرائح ⁦14, 15, 16, 19⁩
المصدر
الفصل 4 · الشرائح ⁦14, 15, 16, 19⁩
ملاحظات حول المصدر (1)
  • جداول الشرائح 16–18 تطبع قسم Shankar في صفّين History ثم Finance، وقسم Brandt «Music»، وقسم Chavez «Physics»، بينما جدول student في الشريحة 13 يعطي Comp. Sci. وHistory وFinance. نُقلت الجداول كما طُبعت.

Natural left and right outer joins of student and takesالربط الخارجي

select * from student natural left outer join takes; (slide 17) — Snow kept with nulls
IDnamedept_nametot_credcourse_idsec_idsemesteryeargrade
00128ZhangComp. Sci.102CS-1011Fall2009A
00128ZhangComp. Sci.102CS-3471Fall2009A-
12345ShankarComp. Sci.32CS-1011Fall2009C
12345ShankarComp. Sci.32CS-1902Spring2009A
12345ShankarHistory32CS-3151Spring2010A
12345ShankarFinance32CS-3471Fall2009A
19991BrandtMusic80HIS-3511Spring2010B
23121ChavezPhysics110FIN-2011Spring2010C+
44553PeltierPhysics56PHY-1011Fall2009B-
45678LevyPhysics46CS-1011Fall2009F
45678LevyPhysics46CS-1011Spring2010B+
45678LevyPhysics46CS-3191Spring2010B
54321WilliamsComp. Sci.54CS-1011Fall2009A-
54321WilliamsComp. Sci.54CS-1902Spring2009B+
55739SanchezMusic38MU-1991Spring2010A-
70557SnowPhysics0nullnullnullnullnull
76543BrownComp. Sci.58CS-1011Fall2009A
76543BrownComp. Sci.58CS-3192Spring2010A
76653AoiElec. Eng.60EE-1811Spring2009C
98765BourikasElec. Eng.98CS-1011Fall2009C-
98765BourikasElec. Eng.98CS-3151Spring2010B
98988TanakaBiology120BIO-1011Summer2009A
98988TanakaBiology120BIO-3011Summer2010null
select * from takes natural right outer join student; (slide 18) — Snow kept with nulls
IDcourse_idsec_idsemesteryeargradenamedept_nametot_cred
00128CS-1011Fall2009AZhangComp. Sci.102
00128CS-3471Fall2009A-ZhangComp. Sci.102
12345CS-1011Fall2009CShankarComp. Sci.32
12345CS-1902Spring2009AShankarComp. Sci.32
12345CS-3151Spring2010AShankarHistory32
12345CS-3471Fall2009AShankarFinance32
19991HIS-3511Spring2010BBrandtMusic80
23121FIN-2011Spring2010C+ChavezPhysics110
44553PHY-1011Fall2009B-PeltierPhysics56
45678CS-1011Fall2009FLevyPhysics46
45678CS-1011Spring2010B+LevyPhysics46
45678CS-3191Spring2010BLevyPhysics46
54321CS-1011Fall2009A-WilliamsComp. Sci.54
54321CS-1902Spring2009B+WilliamsComp. Sci.54
55739MU-1991Spring2010A-SanchezMusic38
70557nullnullnullnullnullSnowPhysics0
76543CS-1011Fall2009ABrownComp. Sci.58
76543CS-3192Spring2010ABrownComp. Sci.58
76653EE-1811Spring2009CAoiElec. Eng.60
98765CS-1011Fall2009C-BourikasElec. Eng.98
98765CS-3151Spring2010BBourikasElec. Eng.98
98988BIO-1011Summer2009ATanakaBiology120
98988BIO-3011Summer2010nullTanakaBiology120
تفاصيل المصدرالفصل 4 · الشرائح ⁦17–18⁩
المصدر
الفصل 4 · الشرائح ⁦17–18⁩
ملاحظات حول المصدر (1)
  • جداول الشرائح 16–18 تطبع قسم Shankar في صفّين History ثم Finance، وقسم Brandt «Music»، وقسم Chavez «Physics»، بينما جدول student في الشريحة 13 يعطي Comp. Sci. وHistory وFinance. نُقلت الجداول كما طُبعت.

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.

View
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.

What does a create view statement store?

تفاصيل المصدرالفصل 4 · الشرائح ⁦20–21⁩
المصدر
الفصل 4 · الشرائح ⁦20–21⁩

Example viewsأمثلة العروض

من الشرائح

  • create view faculty as select ID, name, dept_name from instructor
  • select name from faculty where dept_name = 'Biology'
  • create view departments_total_salary(dept_name, total_salary) as select dept_name, sum (salary) from instructor group by dept_name;
  • create view physics_fall_2009_watson as select course_id, room_number from physics_fall_2009 where building = 'Watson';

Why is the view faculty defined as select ID, name, dept_name from instructor?

تفاصيل المصدرالفصل 4 · الشرائح ⁦22–23⁩
المصدر
الفصل 4 · الشرائح ⁦22–23⁩

View dependencies and view expansionتوسيع العرض

Views defined using other views; view expansion

Depends directlyيعتمد مباشرة
v1 depends directly on v2 if v2 is used in the expression defining v1.
Depends onيعتمد على
v1 depends on v2 if v1 depends directly on v2 or there is a path of dependencies from v1 to v2.
Recursive viewعرض تكراري
A view relation v is recursive if it depends on itself.

View expansion (slide 26)

  1. 1

    repeat: find any view relation vi in e1

  2. 2

    Replace the view relation vi by the expression defining vi

  3. 3

    until no more view relations are present in e1

  • As long as the view definitions are not recursive, this loop will terminate.

When is the view-expansion loop guaranteed to terminate?

تفاصيل المصدرالفصل 4 · الشرائح ⁦24–26⁩
المصدر
الفصل 4 · الشرائح ⁦24–26⁩

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)

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.

Which view would most SQL implementations allow you to update?

تفاصيل المصدرالفصل 4 · الشرائح ⁦27, 28, 30⁩
المصدر
الفصل 4 · الشرائح ⁦27, 28, 30⁩

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).

instructor (slide 29)
IDnamedept_namesalary
10101SrinivasanComp. Sci.65000
12121WuFinance90000
15151MozartMusic40000
22222EinsteinPhysics95000
32343El SaidHistory60000
33456GoldPhysics87000
45565KatzComp. Sci.75000
58583CalifieriHistory62000
76543SinghFinance80000
76766CrickBiology72000
83821BrandtComp. Sci.92000
98345KimElec. Eng.80000
69987Whitenullnull
department (slide 29)
dept_namebuildingbudget
BiologyWatson90000
Comp. Sci.Taylor100000
Elec. Eng.Taylor85000
FinancePainter120000
HistoryPainter50000
MusicPackard80000
PhysicsWatson70000
nullTaylornull

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.)
تفاصيل المصدرالفصل 4 · الشرائح ⁦29–30⁩
المصدر
الفصل 4 · الشرائح ⁦29–30⁩

Materialized viewsالعروض المجسّدة

Materializing a view
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.

What is the main drawback of a materialized view?

تفاصيل المصدرالفصل 4 · الشريحة ⁦31⁩
المصدر
الفصل 4 · الشريحة ⁦31⁩

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.

By default, on most databases, when is an SQL statement committed?

تفاصيل المصدرالفصل 4 · الشريحة ⁦32⁩
المصدر
الفصل 4 · الشريحة ⁦32⁩

not null, unique and checkunique وcheck

Integrity constraints on a single relation

Integrity constraints
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')).

من الشرائح

  • Declare name and budget to be not null: name varchar(20) not null, budget numeric(12,2) not null
  • Ensure that semester is one of fall, winter, spring or summer: create table section (course_id varchar (8), sec_id varchar (8), semester varchar (6), year numeric (4,0), building varchar (15), room_number varchar (7), time slot id varchar (4), primary key (course_id, sec_id, semester, year), check (semester in ('Fall', 'Winter', 'Spring', 'Summer')));

Which statement about the unique constraint is correct?

تفاصيل المصدرالفصل 4 · الشرائح ⁦33–36⁩
المصدر
الفصل 4 · الشرائح ⁦33–36⁩

Referential integrityالسلامة المرجعية

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.

من الشرائح

  • create table course (course_id char(5) primary key, title varchar(20), dept_name varchar(20) references department)

من الشرائح

  • dept_name varchar(20) references department
  • foreign key (dept_name) references department on delete cascade on update cascade
  • Alternative actions to cascade: set null, set default.

Which are the alternative actions to cascade that can be declared on a foreign key?

تفاصيل المصدرالفصل 4 · الشرائح ⁦37–38⁩
المصدر
الفصل 4 · الشرائح ⁦37–38⁩

A foreign key between course and departmentمثال المفتاح الأجنبي

Referential integrity and cascading actions

course (slide 39) — dept_name is marked FK
course_idtitledept_namecredits
BIO-101Intro. to BiologyBiology4
BIO-301GeneticsBiology4
BIO-399Computational BiologyBiology3
CS-101Intro. to Computer ScienceComp. Sci.4
CS-190Game DesignComp. Sci.4
CS-315RoboticsComp. Sci.3
CS-319Image ProcessingComp. Sci.3
CS-347Database System ConceptsComp. Sci.3
EE-181Intro. to Digital SystemsElec. Eng.3
FIN-201Investment BankingFinance3
HIS-351World HistoryHistory3
MU-199Music Video ProductionMusic3
PHY-101Physical PrinciplesPhysics4
department (slide 39) — DEPT_NAME is marked PK; the arrow goes from course.dept_name to it
DEPT_NAMEBUILDINGBUDGET
BiologyWatson90000
Comp. Sci.Taylor100000
Elec. Eng.Taylor85000
FinancePainter120000
HistoryPainter50000
MusicPackard80000
PhysicsWatson70000
تفاصيل المصدرالفصل 4 · الشريحة ⁦39⁩
المصدر
الفصل 4 · الشريحة ⁦39⁩

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)

  • 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?

person(name, spouse) has foreign key spouse references person. John and Mary are inserted, each with the other as spouse. What happens?

تفاصيل المصدرالفصل 4 · الشرائح ⁦40–41⁩
المصدر
الفصل 4 · الشرائح ⁦40–41⁩

Date and time types, defaults and indicesالأنواع والفهارس

SQL data types, indices, user-defined types and domains

Built-in data types (slide 42)
TypeالنوعMeaningالمعنىExampleمثال
date4-digit year, month and datedate '2005-7-27'
timeTime of day: hours, minutes and secondstime '09:00:30', time '09:00:30.75'
timestampDate plus time of daytimestamp '2005-7-27 09:00:30.75'
intervalPeriod of timeinterval '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.

Subtracting one date value from another gives a value of which type?

تفاصيل المصدرالفصل 4 · الشرائح ⁦42–43⁩
المصدر
الفصل 4 · الشرائح ⁦42–43⁩

User-defined types, domains and large objectsالأنواع والنطاقات

SQL data types, indices, user-defined types and domains

من الشرائح

  • create type Dollars as numeric (12,2) final
  • create table department (dept_name varchar (20), building varchar (15), budget Dollars);
  • create domain person_name char(20) not null
  • create domain degree_level varchar(10) constraint degree_level_test check (value in ('Bachelors', 'Masters', 'Doctorate'));
  • create domain YearlySalary numeric(8,2) constraint salary value test check(value >= 29000.00);
  • 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).

blobكائن ثنائي كبير
Binary large object — a large collection of uninterpreted binary data, whose interpretation is left to an application outside the database system.
clobكائن نصي كبير
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.

What is the difference between SQL types and domains, according to the create domain construct?

تفاصيل المصدرالفصل 4 · الشرائح ⁦44–46⁩
المصدر
الفصل 4 · الشرائح ⁦44–46⁩

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.

A user has Update authorization on a relation. What can the user do?

تفاصيل المصدرالفصل 4 · الشريحة ⁦47⁩
المصدر
الفصل 4 · الشريحة ⁦47⁩

grant and revokegrant وrevoke

grant
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
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.

Who can grant a privilege on a relation?

تفاصيل المصدرالفصل 4 · الشرائح ⁦48–50⁩
المصدر
الفصل 4 · الشرائح ⁦48–50⁩

Roles and other authorization featuresالأدوار

من الشرائح

  • create role instructor; grant instructor to Amit;
  • grant select on takes to instructor;
  • create role teaching_assistant; grant teaching_assistant to instructor;
  • create role dean; grant instructor to dean; grant dean to Satoshi;
  • 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.

After grant teaching_assistant to instructor; and grant instructor to dean;, which statement is correct?

تفاصيل المصدرالفصل 4 · الشرائح ⁦51–53⁩
المصدر
الفصل 4 · الشرائح ⁦51–53⁩

Authorization on views and the authorization graphرسم الصلاحيات

Roles and other authorization features

من الشرائح

  • create view geo_instructor as (select * from instructor where dept_name = 'Geology');
  • grant select on geo_instructor to geo_staff
  • Suppose that a geo_staff member issues: select * from geo_instructor;

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)
Authorization graph (slide 54): each arrow, from grantor to grantee
FromTo
DBAU1
DBAU2
DBAU3
U1U4
U1U5
U2U5
تفاصيل المصدرالفصل 4 · الشرائح ⁦52–54⁩
المصدر
الفصل 4 · الشرائح ⁦52–54⁩

الخلاصة

تفاصيل المصدر
المصدر
الفصل 4

خريطة الفصل

    1. 1مقدمة الفصل
  1. Joined relations and inner joinالربط والربط الداخلي

    1. 2Join operationsعمليات الربط
    2. 3Inner joinالربط الداخلي
  2. Outer joinsالربط الخارجي

    1. 4Outer joins: left, right, fullالربط الخارجي
    2. 5Outer join resultsنتائج الربط الخارجي
    3. 6Join syntax examplesصيغ الربط
    4. 7Example: student and takesمثال student وtakes
    5. 8student natural join takesالربط الطبيعي
    6. 9Natural left and right outer joins of student and takesالربط الخارجي
  3. Viewsالعروض

    1. 10Viewsالعروض
    2. 11Example viewsأمثلة العروض
  4. Views defined using other views; view expansionالعروض المبنية على عروض وتوسيع العرض

    1. 12View dependencies and view expansionتوسيع العرض
  5. Updates through views; materialized viewsالتحديث عبر العروض والعروض المجسّدة

    1. 13Updating through viewsالتحديث عبر العرض
    2. 14Updating through a view: what the slides showتحديث العروض
    3. 15Materialized viewsالعروض المجسّدة
  6. Transactionsالمعاملات

    1. 16Transactions in SQLالمعاملات
  7. Integrity constraints on a single relationقيود السلامة على علاقة واحدة

    1. 17not null, unique and checkunique وcheck
  8. Referential integrity and cascading actionsالسلامة المرجعية والإجراءات المتتالية

    1. 18Referential integrityالسلامة المرجعية
    2. 19A foreign key between course and departmentمثال المفتاح الأجنبي
    3. 20Constraint violations and complex checksانتهاك القيود
  9. SQL data types, indices, user-defined types and domainsأنواع البيانات والفهارس والأنواع والنطاقات

    1. 21Date and time types, defaults and indicesالأنواع والفهارس
    2. 22User-defined types, domains and large objectsالأنواع والنطاقات
  10. Authorization: privileges, grant and revokeالصلاحيات: الامتيازات وgrant وrevoke

    1. 23Forms of authorizationأشكال الصلاحيات
    2. 24grant and revokegrant وrevoke
  11. Roles and other authorization featuresالأدوار وميزات أخرى للصلاحيات

    1. 25Roles and other authorization featuresالأدوار
    2. 26Authorization on views and the authorization graphرسم الصلاحيات
    1. 27الخلاصة