Quote:
|
Originally Posted by annamaria
The new five columns were created by making math operations among numbers with when clauses:
when field A = 8 then (field B * field C) as field R1
when field A = 7 then (field C / field D) as field R2
So now I have columns R1 and R2. I don't know what kind of format there is
in column R1 but in record A = 7 it is empty (doesn't it mean NULL?).
|
I wouldn't use the term "empty" to denote unknown values. NULL is intended for that. Saying "empty" has the huge problem that a string may be empty but not NULL. An empty string happens to be a string that contains no characters. Having NULL there indicates the absence of a string. You have the same thing in many programming languages: an empty string in Java is "". A not-existing string is null.
So I suggest that we stick with the relational terminology here.
Note: SQL doesn't have fields: there are
tables with
columns and
rows (or records), and each row has
values. Each column of a table has a (declared)
data type, which is probably what you are referring to with "format"?
Quote:
|
I hope that the number in my new columns is in the number format,and it can be used to make other math operations. Is it so?
|
There are a few different numeric data types in DB2: SMALLINT, INTEGER, BIGINT, DECIMAL, REAL, and DOUBLE. Which one will be chosen depends on the data types of the input values for a mathematical operation, e.g. adding two BIGINT values yields a BIGINT.
Quote:
|
How can I check what kind of value has a field? How can I choose the format of a field?
|
Checking the value can be done by simply selecting the value. You can choose the data type by applying the CAST function (or some other function).
Quote:
'Adding things up is not necessary if you really can rely on only 1 of the 5 values being non-NULL. (You should add constraints to let the DBMS enforce that.)'
What do you mean. What is it that should be enforced?
|
A constraint in SQL is a rule that tells the DBMS certain conditions that must be met by the data in a given table. For example, you could say that the values in a column ID in table T must be larger than 0 by adding such a constraint:
Code:
ALTER TABLE t
ADD CONSTRAINT positive_id CHECK ( id > 0 )
Everytime someone tries to insert an ID value <= 0, DB2 will raise an except and prevent the operation. Same thing with other, more complex conditions...
I believe that you are asking a lot of very basic questions, which implies to me that some foundations on relational database systems is not yet present. Therefore, it is my recommendation that you grab a good book on SQL. It should cover at least the relational model, relational algebra, and relational calculus as well as an introduction to SQL.
Quote:
Have you watched the motoGP race in Turkey today?
I can't believe Valentino Rossi did what he did!!!! (He was the 10th to arrive!).
|
He made a wrong choice in tyre selection. That's life... err... racing.
(I had a similar problem two weeks ago and ended up in the gravel.
