On 16 Mar, 16:26, "Tony Rogerson" <tonyroger...@torver.net> wrote:
> Not only that but I doubt he mentions that using MAX(pk)+1 in an INSERT
> statement yeilds duplicates if multiple connections are concurrently
> inserting rows.
>
> MAX(..)+1 is a very bad approach for adding a next number approach.
>
> I'll let Celko get you out of the mess he has got you in, but if he fails
> then send me mail directly and I'll help.
>
> Tony
>
> "DC" <d...@upsize.de> wrote in message
>
> news:1174058000.436989.116730@b75g2000hsg.googlegroups.com...
>
>
>
> > While we're at it, Mr Celko: I adopted your identity approach from
> > "SQL for Smarties" and I
> > stumbled when I needed to do an INSERT... SELECT. This does not work
> > because obviously the max() statement is only being evaluated once:
>
> > insert into foo (pk, data)
> > select coalesce((select max(pk) + 1 from foo), 1), bar.data
> > from bar
>
> > I am in doubt about the "not using identity" directive, or am I
> > missing some point?
>
> > Regards
> > DC
>
> > On 26 Feb., 21:28, "--CELKO--" <jcelko
>
> > On 16 Mrz., 15:52, "--CELKO--" <jcelko...@earthlink.net> wrote:
> >> >> Is it possible to pass the table name and column name as variables
> >> >> like this : <<
>
> >> Why would you ever want to write such bad code?? You never had a
> >> course in basic software engineering, have you? YOu might want to do
> >> that immediately and pay attention to the parts about coupling and
> >> cohesion -- that will be covered in the first few weeks because it is
> >> so fundamental.
>
> >> Oh yes, the old "Britney Spearas, Automoible and Squid" code Module!!
>
> >> The short answer is use slow, proprietrary dynamic SQL to kludge a
> >> query together on the fly with your table name in the FROM clause. And
> >> add a comment that you are a bad programmer and this needs to be
> >> replaced as soon as possible.
>
> >> The right answer is never pass a table name as a parameter. You need
> >> to understand the basic idea of a data model and what a table means in
> >> implementing a data model. Go back to basics. What is a table? A model
> >> of a set of entities or relationships. EACH TABLE SHOULD BE A
> >> DIFFERENT KIND OF ENTITY. When you have many tables that model the
> >> same entity, then you have a magnetic tape file system written in SQL,
> >> and not an RDBMS at all.
>
> >> If the tables are different, then having a generic procedure which
> >> works equally on automobiles, octopi or Britney Spear's discology is
> >> saying that your application is a disaster of design.
>
> >> 1) This is dangerous because some user can insert pretty much whatever
> >> they wish -- consider the string 'Foobar; DELETE FROM Foobar; SELECT *
> >> FROM Floob' in your statement string.
>
> >> 2) It says that you have no idea what you are doing, so you are giving
> >> control of the application to any user, present or future. Remember
> >> the basics of Software Engineering? Modules need weak coupling and
> >> strong cohesion, etc. This is far more fundamental than just SQL; it
> >> has to do with learning to programming at all.
>
> >> 3) If you have tables with the same structure which represent the same
> >> kind of entities, then your schema is not orthogonal. Look up what
> >> Chris Date has to say about this design flaw. Look up the term
> >> attribute splitting.
>
> >> 4) You might have failed to tell the difference between data and meta-
> >> data. The SQL engine has routines for that stuff and applications do
> >> not work at that level, if you want to have any data integrity.- Hide quoted text -
>
> - Show quoted text -
Thanks for all this information.
Ina