Date In Sql And Relation Algebra Is Null?
Solution 1:
Yes, though the table schema has to declare the column as nullable. If you're creating a new table, you'll need to do something like
createtableOrder
(
order_id intnotnullprimary key ,
ship_date datetime null ,
...
)
If you are modifying an existing table, you'll need a magic incantation like
altertableOrderaltercolumn shop_date datetime nullThe exact syntax may vary, depending on your particular flavour of SQL.
Solution 2:
There is no need of the table CUSTOMER, just get the prodno not in Ordered, unless you want to know which product each customers have never ordered.
In SQL
SELECT Prodno
FROM Products
WHERE Prodno NOTIN (SELECT Prodno
FROM Ordered)
or the equivalent
SELECT Prodno
FROM Products
EXCEPTSELECT Prodno
FROM Ordered
Solution 3:
Apparently Product(prodno,name) means "product [prodno] is named [name]" and Ordered(orderid, prodno, quantity) means "order [orderid] was for quantity [quantity] of product [prodno]". But you need to make such meanings clear.
check if the Order.orderid is not equal to Ordered.orderid and Porduct.prodno is not equal to Ordered.prodno
That is just not clear enough to reason about the problem. Conditions don't always correspond to selections. Work to find a clear, full natural language description of what you want. Ordered products are those that appear in Ordered and unordered products are those that only appear in Product. Apparently you want prodno and name of unordered products.
We use algebraic substraction to remove a relation's tuples from another's. But subtraction arguments need the same attributes. The prodnos of products are π prodno Product and the prodnos of ordered products are π prodno Ordered. So unordered prodnos are π prodno Product - π prodno Ordered. But you want the prodno and name of the products with those prodnos:
(π prodno Product - π prodno Ordered) ⋈ Product
This doesn't involve customers.
This doesn't involve orders or their shipment dates. (Don't confuse shipped products with ordered products.)
However, your question topic involves dates and NULL. So I may not really have understood your question. If Order shipdate is nullable then that is a different issue. (You have to decide what relation corresponds to an SQL table with NULLs and you have to involve NULL in translating between algebra operators and SQL operators.)
Post a Comment for "Date In Sql And Relation Algebra Is Null?"