Article View: borland.public.interbase.sql
Article #10996Re: Learning Interbase "style"
From: Bradley J. Bell
Date: Sat, 21 Dec 2002 16:11
Date: Sat, 21 Dec 2002 16:11
96 lines
4406 bytes
4406 bytes
I guess I find the manuals "wanting".
In Sybase I can just do an insert, duplicates are ignored. In IB I can't as
you pointed out.
Someone replied saying the way to do this in IB is...
if (exists(select * from table where myuniquekey = :keyparam)) then
update table set ...
else
insert into table ...;
In the IB manual I have (yes, its old version 4.0). it says that there is a
keyword "EXISTS", but gives no further information, no samples, examples,
nothing. In Sybase I've never seen this "style" before.
The above code snippet is exactly what I'm looking for. This is the way IB
would handle the situation.
Another example is the following: I have a table I'll call DEST. It has in
int ID field and a VarChar PName field. I have an ID and I want to insert
the PName from another table called SOURCE that consists of an ID and a
PNAME. In Sybase I would do this
Update DEST set d.PName = s.PName from DEST d, SOURCE s where d.ID = s.ID
You can't do this in IB. The manual says I should do the following
Update DEST set PName = (Select PName from SOURCE where SOURCE.ID = DEST.ID)
It works, but it's slower then HECK.
After digging around Deja.com I found the following to be a better way
for select ID, PName from SOURCE into :ID, :PName do begin update DEST set
PName = :PName where ID = :ID; end
A lot better. While doing more research I found that there still might be a
better way using "RDB$DB_KEY". I haven't played around with this techique
yet.
Maybe the problem is that I'm coming from a Sybase environment. I guess
Sybase doesn't do things in a "SQL-92 standard" way. I haven't found any
SQL-92 standard books either. They all seem to be Sybase, Oracle, SqlServer.
I'll keep looking, thanks for the reply.
Bradley
"Bill Todd" <bill@notthis.dbginc.com> wrote in message
news:82v80v8k2rn4e05smr4pgqi56bi4lu37so@4ax.com...
> What is it about SQL syntax that you cannot find in the InterBase
> manuals?
>
> In IB if an index is unique then you cannot insert a row with the same
> value as an existing row. For rows that exist you must use an UPDATE.
>
> On Sat, 21 Dec 2002 01:39:55 -0600, "Bradley J. Bell"
> <bradleyjbell@attb3i.c1o2m> wrote:
>
> >I currently use Sybase at work and I am use to its SQL syntax. I've
recently
> >decided to do some "brushing up" with Delphi and have decided to try
> >Interbase as the database.
> >
> >I'm having one heck of a time trying to learn Interabase's SQL syntax,
> >Interbase's "way" of doing things. I have been unable to find one
Interbase
> >programming book. What little I've learned is from searching Deja.com,
but
> >it takes a long time just to learn how to do simple things.
> >
> >Can anyone point me to a good book or website that teaches Interbase
> >"style"?
> >
> >TIA
> >
> >Bradley
> >
> >p.s. Just as a second question; in Sybase I can insert new records into a
> >database with a unique key and not worry about duplicates by including
"with
> >ignore dups" when defining the index. Does Interbase have a similar
option.
> >Right now what I've been doing is to take all the possible new entries
from
> >my source table and deleting any entries that already exisit in the
> >destination table. There has to be a better way (I hope).
> >
> >Again, TIA
> >
>
>
> --
> Bill (TeamB)
> (TeamB cannot respond to questions received via email)
Technical Details
Message-ID:
<3e0492ad$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!news.uni-x.net!newsgroups.borland.com!not-for-mailReferences:
<3e041ac9$1@newsgroups.borland.com> <82v80v8k2rn4e05smr4pgqi56bi4lu37so@4ax.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 114a0e,8dcbdc28ad264e66 X-Google-Attributes: gid114a0e,public X-Google-ArrivalTime: 2002-12-21 08:15:29 PST From: "Bradley J. Bell" <bradleyjbell@attb3i.c1o2m> Newsgroups: borland.public.interbase.sql References: <3e041ac9$1@newsgroups.borland.com> <82v80v8k2rn4e05smr4pgqi56bi4lu37so@4ax.com> Subject: Re: Learning Interbase "style" Date: Sat, 21 Dec 2002 10:11:26 -0600 Lines: 98 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 12.249.164.138 Message-ID: <3e0492ad$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1040487085 12.249.164.138 (21 Dec 2002 08:11:25 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!news.uni-x.net!newsgroups.borland.com!not-for-mail