Assignment Operator

The assignment operator is one of the most intuitive to use. It assigns a value to a variable. The only confusion in using this operator could stem from its overloading. All RDBMS overload this operator with an additional function — comparison — in the SQL.

The equals operator (=) is used as an assignment in the following SQL query that updates the price (PROD_PRICE_N) column in the PRODUCT table, raising the existing prices by 2 percent:

UPDATE product SET prod_price_n = prod_price_n * 1.02 (10 row(s) affected) 

And the same operator would be used for comparing values when used, for example, in the WHERE clause of an SQL statement:

UPDATE product SET prod_price_n = prod_price_n * 1.02 WHERE prod_id_n = 1880 (1 row(s) affected)

This statement assigns a 2 percent increase to a product whose ID is 1880; in the same query, the equals operator (=) is used in its assignment and comparison capacity at the same time.

Note 

In some SQL procedural languages, there are distinctions between assignment and comparison operators. Oracle PL/SQL uses := for assignment and = for comparison; MS SQL Server's Transact SQL uses only one operator for these purposes, =, as does IBM DB2 UDB.




SQL Bible
Microsoft SQL Server 2008 Bible
ISBN: 0470257040
EAN: 2147483647
Year: 2005
Pages: 208

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net