Table comparison - sql, PL-SQL Programming

Table Comparison - SQL

The following definitions for relation comparisons:

Let r1 and r2 be relations having the same heading. Then:

r1 ⊆ r2 is true if every tuple of r1 is also a tuple of r2, otherwise false.

r1 ⊇ r2 is equivalent to r2 ⊆ r1

r1 = r2 is equivalent to r1 ⊆ r2 AND r2 ⊆ r1

The question arises as to whether SQL tables can be similarly compared. SQL does not have direct counterparts of ⊆ and ⊇. It does of course have =, but table expressions cannot be used as comparands. However, as we have seen in Examples et seq., the operator TABLE has been available since SQL: 2003 to derive from a given table expression a value of a multiset type whose element type is a row type. In other words, (SELECT * FROM t1) = (SELECT * FROM t2) is illegal but we can obtain the required effect by writing TABLE (SELECT * FROM t1) = TABLE (SELECT * FROM t2). So, to compare two tables, we have to use an operator named TABLE to "convert" them from tables into multisets of rows!

To test for every row of t1 being also a row of t2 we could write, for example, NOT EXISTS (SELECT * FROM t1 EXCEPT SELECT * FROM t2). In fact, SQL's NOT EXISTS is an exact counterpart of Tutorial D's IS_EMPTY operator. However, note carefully that the case where every row in t1 appears in t2 and every row of t2 appears in t1 does not guarantee that t1 and t2 are the same table. Row r might appear twice in t1 but only once in t2, for example.

Posted Date: 1/18/2013 7:02:48 AM | Location : United States







Related Discussions:- Table comparison - sql, Assignment Help, Ask Question on Table comparison - sql, Get Answer, Expert's Help, Table comparison - sql Discussions

Write discussion on Table comparison - sql
Your posts are moderated
Related Questions
Avoid the NOT NULL Constraint In the PL/SQL, using the NOT NULL constraint incur a performance cost. Consider the illustration as shown below: PROCEDURE calc_m IS m NUMB

Row Counterparts of Table Operators SQL does not have counterparts tuple rename, tuple projection, tuple extension, tuple join and tuple compose. To obtain the same effects as

DBMS: The answer to this question is of course given in of the theory book. This book is concerned with SQL DBMSs and SQL databases in particular. Soon we will be looking a

Brewbean's is implementing a new discount for return shoppers - every fifth completed order receives a 10% discount. The count of orders for a shopper is placed in a packaged varia

Organi c Evolution Evolution is a slow continuous, irreversible and natural process of change to give rise to advance and diverse forms of life i.e. formation of new specie

Need Database Development with Analysis Tools Project Description: I want a database for large governmental and private data sets on one country that can be simply extended t

Create the four tables and populate them with the given data. Answer the following queries in SQL. 1. Get all part-color/part-city combinations. Note: Here and subsequently, the

Procedures The procedure is a subprogram which can take parameters and be invoked. Normally, you can use a procedure to perform an action. The procedure has 2 sections: the spe

Providing Results of Queries Expressing queries in SQL is the (big) subject. Here I present just a simple example to give you the flavour of things to come in those chapters.

Joining in SQL Joining IS_CALLED and IS_ENROLLED_ON in SQL SELECT * FROM IS_CALLED NATURAL JOIN IS_ENROLLED_ON This is an example of an SQL table expression. I have been