473,460 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Coding in standard SQL ?

Hi;

Is there an **easy** way to tell tsql apart from standard sql?

Will sqlserver run scripts written only in standard sql?

What about variable definitions?

Thanks in advance

Steve
Jul 20 '05 #1
8 3530
Variable definitions are the first thing that kills you.
SQL/PSM uses the same namespace for variables as for columns, no @.
If you want to write portable SQL you'd have to stay away from any
procedural logic in SQL because no two DBMS have the same implementation:
PL/SQL (Oracle), T-SQL (MS, Sybase), SPL (Informix), SQL/PSM (DB2)

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Jul 20 '05 #2
Serge Rielau <sr*****@ca.eye-be-em.com> wrote in message news:<c7**********@hanover.torolab.ibm.com>...
Variable definitions are the first thing that kills you.
SQL/PSM uses the same namespace for variables as for columns, no @.
If you want to write portable SQL you'd have to stay away from any
procedural logic in SQL because no two DBMS have the same implementation:
PL/SQL (Oracle), T-SQL (MS, Sybase), SPL (Informix), SQL/PSM (DB2)

Cheers
Serge


LOL!

Thanks for preventing me from wasting my time :)

Steve
Jul 20 '05 #3
Well, if you try to write standard SQL statements at least it's one
worry less.
Mapping the procedural blurp isn't that bad and most vendors support
migration tools to steal each others customers.

I would steer clear of scalar subqueries (queries which are expected to
return a single row and a single column) if you are NOT sure they return
a single row. The SQL standard requires a DBMS to raise an error if more
than one row is retrieved.
TSQL will happily return "a" row, IIRC.

use regular JOIN syntax instead of the short forms,

go easy on TOP and it's friends (it maps to FETCH FIRST n ROWS which is
trivial enough).

GROUP BY is no substitute to ORDER BY

Avoid setting the rowcount (?) environment variable like the plague.

Never depend on INSERT order or order in the table in general.

UPDATE/DELETE FROM isn't that bad. Informix supports it and both Oracle
and DB2 support SQL Standard MERGE which maps well enough.
Just make sure you join on keys and don't write the same row twice.

All hope is lost I fear to ever agree on how to return updated rows.
Yukon: UPDATE INTO, Oracle: UPDATE with RETURN, DB2: SELECT FROM UPDATE
(Dear MS folks: Is it too late to change? Bad timing I s'pose *sigh*)

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Jul 20 '05 #4
"Serge Rielau" <sr*****@ca.eye-be-em.com> wrote in message
news:c7**********@hanover.torolab.ibm.com...
Well, if you try to write standard SQL statements at least it's one
worry less.
Mapping the procedural blurp isn't that bad and most vendors support
migration tools to steal each others customers.

I would steer clear of scalar subqueries (queries which are expected to
return a single row and a single column) if you are NOT sure they return
a single row. The SQL standard requires a DBMS to raise an error if more
than one row is retrieved.
TSQL will happily return "a" row, IIRC.
T-SQL will indeed raise an error here that looks like:

Server: Msg 512, Level 16, State 1, Line XXX
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= ,, >= or when the subquery is used as an expression.
I know this to be the behavior since at least 7.0.

--
JAG
use regular JOIN syntax instead of the short forms,

go easy on TOP and it's friends (it maps to FETCH FIRST n ROWS which is
trivial enough).

GROUP BY is no substitute to ORDER BY

Avoid setting the rowcount (?) environment variable like the plague.

Never depend on INSERT order or order in the table in general.

UPDATE/DELETE FROM isn't that bad. Informix supports it and both Oracle
and DB2 support SQL Standard MERGE which maps well enough.
Just make sure you join on keys and don't write the same row twice.

All hope is lost I fear to ever agree on how to return updated rows.
Yukon: UPDATE INTO, Oracle: UPDATE with RETURN, DB2: SELECT FROM UPDATE
(Dear MS folks: Is it too late to change? Bad timing I s'pose *sigh*)

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab

Jul 20 '05 #5
John Gilson (ja*@acm.org) writes:
T-SQL will indeed raise an error here that looks like:

Server: Msg 512, Level 16, State 1, Line XXX
Subquery returned more than 1 value. This is not permitted when the
subquery follows =, !=, <, <= ,
, >= or when the subquery is used as an expression.


I know this to be the behavior since at least 7.0.


It was the same in 4.x and 6.x too.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #6
Steve (st**********@yahoo.com) writes:
Is there an **easy** way to tell tsql apart from standard sql?
You could try SET FIPS_FLAGGER ON. I believe this command warns you
about non-standard SQL things. I have never tried it myself, though.
Will sqlserver run scripts written only in standard sql?


Depends on which standard you mean. ANSI has revised the SQL standard
a couple of times, and each revision has several levels. It is possible
that SQL Server conforms fully to the entry level of ANSI-89, but generally
you should not assume just because it's in the ANSI that SQL Server
supports it. SQL Server has taken quite a few things from ANSI, but
has blissfullly ignored others.
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #7
Way to go, must be a habit that got left with Sybase then.

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Jul 20 '05 #8
>> Is there an **easy** way to tell tsql apart from standard sql? <<

1) Go to the Mimer website and use their on-line validator tool.
2) Write code with the FIPS Flager turned on. If you are doing any
federal work, you are doing this already.
Will sqlserver run scripts written only in standard sql? <<
Mostly, but not always.
What about variable definitions? <<


Watch your datatypes and avoid the proprietary ones. Standard SQL
uses a colon in place of a leading @ sign.

Having written five books and 700+ articles with nothing but Standard
SQL, if you learn what you are doing, it is not that much trouble to
move to a dialect. It is much harder going from a dialect to Standard
SQL. You might also look at Vembu, a translation tool.
Jul 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mikkel christensen | last post by:
Hi there I wonder if any of you could point me in a direction where I can find some usefull information about coding standarts. I have some generel experiense in programming but I lack many...
144
by: Natt Serrasalmus | last post by:
After years of operating without any coding standards whatsoever, the company that I recently started working for has decided that it might be a good idea to have some. I'm involved in this...
13
by: benben | last post by:
Is there an effort to unify the c++ coding standard? Especially identifier naming. Not a big issue but it would be annoying to have to incorporate different coding styles simultaneously when...
50
by: Konrad Palczynski | last post by:
I am looking for tool to validate conformity to defined coding standard. I have already found Parasoft's C++ Test, but it is quite expensive. Is there any Open Source alternative? I do not need...
7
by: Robert Seacord | last post by:
The CERT/CC has just deployed a new web site dedicated to developing secure coding standards for the C programming language, C++, and eventually other programming language. We have already...
4
by: steven.sagerian | last post by:
Can anyone suggest a good off the shelf coding standard for embedded real time applications? Thanks, Steve
0
by: pat | last post by:
CodeCheck Coding Standard's Support As a free service to our customers we offer support in developing "rule-files" for automating corporate coding standards. If you have a coding standard that...
8
by: =?ISO-8859-1?Q?Arnaud_Carr=E9?= | last post by:
Hi all, I guess you all know how difficult it is to choose a conding standard. And even more difficult it is to explain the choice to your dev team :-) I'm looking for an "official" c++ coding...
19
by: auratius | last post by:
http://www.auratius.co.za/CSharpCodingStandards.html Complete CSharp Coding Standards 1. Naming Conventions and Styles 2. Coding Practices 3. Project Settings and Project Structure 4....
9
by: dom.k.black | last post by:
Can anyone recommend a good existing C++ coding standard - parctical, pragmatic and sensible? A company I joined recently are moving from C to C++, they are very much into coding standards. But...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.