Portable SQL/Common/Aliases

From Linuxnetworks
< Portable SQL
Revision as of 12:06, 3 September 2006 by Nose (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Alias for tables and columns

Don't use the keyword "AS" between name and alias as no DBMS requires it and some don't recognize it. Instead, always write

SELECT * FROM table t WHERE t.id = 0

Quotes and numeric values

MS SQL Server and Sybase ASE doesn't allow single quotes (') around numeric values (integer and floating point values), for example

INSERT INTO table (floatval,string) VALUES ('-3.14','some text')

generates an error when using these servers. They only accept

INSERT INTO table (floatval,string) VALUES (-3.14,'some text')

This gets tricky if the values are supplied by a user. You must validate the input to be sure it is a numeric value and you can't use the escape() function. Otherwise, if you don't look at the input, your application will be vulnerable to SQL injection and you will be in deep trouble.



Back to Overview