relational-algebra

Is there set division in SQL?

I'm fully aware that set division can be accomplished through a series of other operations, so my question is: Is there a command for set division in SQL? ...

Is my Relational Algebra correct?

I have a database assignment which i have to create some relational algebra for two problems. I feel fairly all right with the majority of it, but I just get confused when trying to project attributes out of a table which is joined to another table. for example is this correct? Q1) List the details of incidences with no calls made, so ...

How do I represent my joins in Relational Algebra?

I am new to relational algebra and for my assignment I have to create two. I have written out the problem I have faced in SQL but I am unsure of how to represent such joins in relational algebra. Any help/pointers would be greatly appreciated. SELECT ps.FirstName AS StudentFirstName, ps.LastName AS StudentLastName, pst.FirstName AS Staf...

Are there canonical-forms for database queries?

Say I want to make an "Optimized query generator". Basically a SQL query optimizer that is a lot better than what can be put in an SQL server based on time/space limitations. It would take a query and DB stats as input and generate an SQL query tailored for the target system that will quickly optimize to a nearly ideal plan. How much of...

Relational Algebra

This is not a homework problem... I'm studying on my own. If someone could explain to me what is going on here and how to solve this problem it would be greatly appreciated. Suppose relation R(A,B) has the tuples: A B 1 2 3 4 5 6 and the relation S(B,C,D) has tuples: B C D 2 4 6 4 6 8 4 7 9 Compute the natural join of R and S....

Relations With No Attributes

Aheo asks if it is ok to have a table with just one column. How about one with no columns, or, given that this seems difficult to do in most modern "relational" DBMSes, a relation with no attributes? ...

Why are positional queries bad?

I'm reading CJ Date's SQL and Relational Theory: How to Write Accurate SQL Code, and he makes the case that positional queries are bad for example, this INSERT: INSERT INTO t VALUES (1, 2, 3) Instead, you should use attribute-based queries like this: INSERT INTO t (one, two, three) VALUES (1, 2, 3) Now, I understand that the first...

SQL Query theory question - single-statement vs multi-statement queries

When I write SQL queries, I find myself often thinking that "there's no way to do this with a single query". When that happens I often turn to stored procedures or multi-statement table-valued functions that use temp tables (of one sort or another) and end up simply combining the results and returning the result table. I'm wondering if...

What is an existing library for making queries with the relational model?

I'm looking for a simple, high level library (implemented in python would be nice) for handling the relational algebra. Alternatively, an existing SQL implementation might have support for these queries. For example, if the relation schema of the account relation is (account id, name, balance), I'd like to input the expression here ...

Relational Algebra

I was wondering if I could get some feedback on the relational algebra I have done and any advice on improving it also if you see anything wrong with my SQL could you possibly point it out. SELECT CourseName FROM Course WHERE CourseNo = 6; ∏CourseName(σCourseNo=6(Course)) SELECT CU.UnitNo FROM C.Course, CU CourseUnit WHERE C.CourseNa...

Python code for determining which normal form tabular data is in

I'm looking for Python code that can take tabular data and establish which normal form(s) it is in (if any) and show any functional dependencies, etc. ...

Sorting based on the count in a related field in Django

I have two models, Image and Tag. Each Image object can have more than one Tag associated with it, and I want to find my most frequently used tags. How would I go about this? It seems easy enough but I can't seem to figure it out. ...

Help to translate SQL query to Relational Algebra

Hi everyone, I'm having some difficulties with translating some queries to Relational Algebra. I've a great book about Database Design and here is a chapter about Relational Algebra but I still seem to have some trouble creating the right one: Thoes queries I've most difficuelt with is these: SELECT COUNT( cs.student_id ) AS counter F...

subscript for a join (\bowtie) operation in LyX/LaTeX

I'm using LyX to write some Relational Algebra queries. I'm using the \bowtie symbol for the join operation but when I try to put a text in subscript directly under the symbol, I get the following error: ...a_{\t{pId}}\t{person}\right)\bowtie\limits {\t{pId}{1}=\t{pId}_{2}... I'm i...

Rails3: how to use relational algebra to replace SQL-constructions like NOT and OUTER JOIN

There are two models Post and Comment. I should get all posts, which have no comments with specific tag. How can I do this using new Rails 3 features such relational algebra (arel). SQL-solution should be something like this: SELECT `posts`.* FROM `posts` LEFT OUTER JOIN `comments` ON `posts`.`id` = `comments`.`post_id` WHERE...

Converting SQL to relational algebra

How do I go about writing the relational algebra for this SQL query? Select p.name, p.ward, m.name, p.quantity, f.frequency From patient, medicine, prescription Where frequency = "3perday" AND p.end-date="08-06-2010" AND canceled = "Y". ...

SQL to Relational Algebra

How do I go about writing the relational algebra for this SQL query? Select patient.name, patient.ward, medicine.name, prescription.quantity, prescription.frequency From patient, medicine, prescription Where prescription.frequency = "3perday" AND prescription.end-date="08-06-2010" AND canceled = "Y"...

How to fetch distinct values with arel/relational algebra

I'm doing my best to bend my brain around arel and the relational algebra behind it, but how to represent a SELECT DISTINCT is consistently eluding my comprehension. Can anyone explain how to arel: SELECT DISTINCT title FROM posts; Many thanks! ...

Do you know of an online tutorial for relational algebra/DDL statements?

I was meant to have my final exam on database management back in January, but I was too ill at the time to sit it. My resit have been scheduled for the end of August, which comes right at the crucial time where my dissertation needs to be nearing completion. Therefore I need to start my revision now as it's been a while since I last ha...

Relational Algebra instead of SQL

I am studying relational algebra these days and I was wondering... Don't you thing it would be better if a compiler was existed which could compile relational algebra than compiling SQL? In which case a database programmer would be more productive? Is there any research on relational algebra compilers? Thanks in advance ...