Re: "Macro" statement

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: --CELKO-- (jcelko212_at_earthlink.net)
Date: 01/26/05


Date: 25 Jan 2005 16:42:22 -0800


>> Imagine that we have a table named tblA and fields [sic] with the
almost same name, for example Field01, Field02,...Field20. (I have
named fields [sic] on that way for the better explanation). <<

A column is not a field -- nothing like it at all. Since each column
is a separate attribute of the entity in your data model, it would be
VERY unusual to have such a table if you had a proper data model.

However, if I were writing a 1950's file system (files are made of
records which do have fields), then they would probably be a repeating
group -- and a violation of First Normal Form (1NF).

>> Now, suppose that we want to do almost the same update on all of the
fields [sic]: <<

In SQL an UPDATE works on entire rows (rows are not records), changing
all the columns at the same time.

UPDATE Foobar
SET x = <value1>,
y = <value2>,
z = <value3>,
etc.

If you want to pass the values as parameters, then you can skip some of
them by passing a NULL and having this SET clause in your UPDATE
statement.

SET x = COALESCE (<value1>, x)

Dynamic SQL generation is considered very poor design; it says you have
no data model and no idea what to do until run time.



Relevant Pages

  • Re: Insert.... Select From... question
    ... The target table has a primary key but it isnt an identity ... You did screw up the schema! ... SQL is a set oriented language, not a sequential file system. ... Now if you want to start over and do it right, with a proper data model ...
    (microsoft.public.sqlserver.programming)
  • Re: Insert.... Select From... question
    ... > An IDENTITY property cannot NEVER be a key by definition, ... you did not screw up your data model by using ... on attributes in the data model and is exposed to the user. ... SQL is a set oriented language, not a sequential file system. ...
    (microsoft.public.sqlserver.programming)