2

Problem

A question I once found on a test was worded as such:

Report the book information for the book with ISBN=43221

The relational schema for a book is depicted below:

πISBN, title, type, NumPages, edition, sequel, nameISBN=43221(Book))

This is essentially the equivalent of

SELECT * FROM Book WHERE ISBN=43221.

I wrote out all the attributes in the Projection statement on the test, but I had the feeling there was a quicker way to do it.

Question

Is there a shortcut way of displaying all the information of one tuple in Relational Algebra, or must all attributes be written out in the Project statement?

5

Yes.

In relational algebra the relation

Book

corresponds to

select * from Book

If you want to restrict to some rows you apply a selection σ:

σISBN=43221(Book)

In SQL this is a where-clause like

select * from Book where ISBN=43221

If you want to reduce the columns you need a projection π:

πISBN, title, typeISBN=43221(Book))

In SQL this is a select-list different from *:

select ISBN, title from Book where ISBN=43221
  • In order to get a projection, you may need to use SELECT DISTINCT in some cases. In this case the results are already distinct, because ISBN is distinct. But, in other cases, you might get multiple rows with the same value – Walter Mitty Jan 27 '18 at 12:46
0

In relational algebra you can write query in this way:

Select ISBN = 43221 (Book)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.