Home Forums SQL Server 2005 T-SQL (SS2K5) Inserting data in one table as selecting from other tables RE: Inserting data in one table as selecting from other tables

  • priest Ivan Delic (8/9/2012)


    Hi all!

    I have a simple question. I've made a simple database in Access and upsized it in my SQL Server 2005 Express edition Service Pack 4 on my Windows 7 machine, 2GB RAM.

    That database was newbie one, I tried to normalized my data in about 10 tables. In one table called Records I put these columns

    ID int NOT NULL PK auto-increment (I don't recall at this moment how is it called actually)

    book int NULL

    page int NULL

    number int NULL

    Second table is called names with following structure:

    ID int NOT NULL PK auto-increment (see above)

    name1 varchar (70)

    name2 varchar (120)

    Third table is most complex one. Now I realize that I should make it simple. Table name is Parents and the structure is:

    ID int NOT NULL PK auto-increment (see above)

    father_first_name varchar (50)

    father_last_name varchar (50)

    father_occupation varchar (50)

    ...

    All those ID fields are the same, e. t. have the same value, so I want to make one table with all those fields together. I know of routine such as

    SELECT father_first_name + '' + father_last_name + '' + father occupation AS father,

    which is, in my experience with SQL Server, the best solution for putting few fields together in one field.

    Could anyone help me with my problem.

    P. S. I am aware of possible solution

    INSERT INTO...

    AS

    SELECT

    FROM

    but I don't know the whole T-SQL sequence.

    Sincerely yours,

    Fr. Ivan Delic

    Serbia

    First, I wuldn't denormaize like that. Second, I don't believe you could anyway because there is absolutely nothing in those tables to relate them to each other unless you're 100% sure that the ID columns are, in fact, currently 1:1:1.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)