Table comparison - sql, PL-SQL Programming

Assignment Help:

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.


Related Discussions:- Table comparison - sql

Fetching across commits, Fetching Across Commits The FOR UPDATE clause...

Fetching Across Commits The FOR UPDATE clauses acquire exclusive all row locks. All rows are locked when you open the cursor, and when you commit your transaction they are unl

Sql outer join, SQL outer join SELECT * FROM IS_CALLED NATURAL LEFT...

SQL outer join SELECT * FROM IS_CALLED NATURAL LEFT JOIN IS_ENROLLED_ON Note that adding LEFT to an invocation of CROSS JOIN has no effect unless the right-hand operand

Variables and constants in pl/sql, V ariables and Constants in PL/SQL ...

V ariables and Constants in PL/SQL The PL/SQL permits you to declare constants and variables, and then use them in SQL and procedural statements anywhere in the expression. Th

Dbms, DBMS: The answer to this question is of course given in of the t...

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

Write a pl/sql anonymous block that accepts an employee id, Based on the EM...

Based on the EMPLOYEE table created in Assignment #1, write a PL/SQL anonymous block that accepts an employee ID from the user input and finds whether the employee ID is in the EMP

3cx pbx sync windows service, 3CX PBX sync Windows Service Project Descr...

3CX PBX sync Windows Service Project Description: !! You require access to a commercial version of the 3CX PBX system in order to be able to program the API !! !! You requ

Restriction and and - sql, Restriction and AND - SQL Restriction is av...

Restriction and AND - SQL Restriction is available via the WHERE operator, and so it is in SQL. However, by Example showing how a certain simple restriction can be expressed u

Fetching with a cursor, Fetching with a Cursor The FETCH statements re...

Fetching with a Cursor The FETCH statements retrieve the rows in the result set one at a time. After each and every fetch, the cursor advance to the next row in the result set

Triggers, At times, customers make mistakes in submitting their orders and ...

At times, customers make mistakes in submitting their orders and call to cancel the order. Brewbean’s wants to create a trigger that automatically updates the stock level of all pr

Processing transactions, Processing Transactions This part describes ho...

Processing Transactions This part describes how to do the transaction processing. You learn the fundamental techniques that safeguard the consistency of your database, involvin

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd