Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2004
    Posts
    9

    Unanswered: Populating a record

    Greetings,

    Assume that a database table named “tblA” has 3 numeric fields (field1 to field3) that are NOT NULL and another text field (field4) that has a Default value of ‘Unknown’ . The Primary Key (field1) is an Identity column.

    I'm looking to create one SQL statement example to populate 1 record when the information for field4 is Unknown.

    Would I use the Insert Into statment:

    Example
    INSERT INTO tbla(Name, EmployeeID, Position) VALUES(‘Albert Grant’, 100, ‘Salesman’);

    Any words of advice would be greatly appreciated.

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Without actually seeing your assignment, I'd say you've got it!

    -PatP

  3. #3
    Join Date
    Dec 2003
    Location
    Oklahoma, USA
    Posts
    354
    I would recommend writing your inserts in the way you specified. Reasoning is that if table structures change, simply writing your INSERT script as:

    INSERT INTO myTable VALUES ('abc', 'xyz', 123);

    will require a change to the code. Without specifying a column list, your respective SQL parser will assume you will be inputting values into each of the defined columns of the table.

    In your specific case, since it may not always be the case that the final value will be NULL, go ahead and specify it in your input list, and simply insert a NULL value in the VALUES part of your statement.

    Of course this is just my opinion, which is only important to me...
    JoeB

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    bzzzt, wrong, sorry

    the question was: “tblA” has 3 numeric fields (field1 to field3) and a text field (field4) with field1 being the PK

    no way this is right --

    INSERT INTO tbla(Name, EmployeeID, Position)
    VALUES(‘Albert Grant’, 100, ‘Salesman’)

    syntax error all over the floor
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Quote Originally Posted by r937
    bzzzt, wrong, sorry

    the question was: “tblA” has 3 numeric fields (field1 to field3) and a text field (field4) with field1 being the PK

    no way this is right --

    INSERT INTO tbla(Name, EmployeeID, Position)
    VALUES(‘Albert Grant’, 100, ‘Salesman’)

    syntax error all over the floor
    Can you defend your answer?

    They didn't say that those were the only defaults in the row, and they also failed to give at least one of the other criteria about field 1 that was specified in class. As you might suspect, I have some insight into this one!

    -PatP
    Last edited by Pat Phelan; 04-26-04 at 23:13.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •