Results 1 to 11 of 11
  1. #1
    Join Date
    Jun 2004
    Posts
    8

    Question Unanswered: multiple records

    Hi there...

    I am new at sql programming and I need all the help i can possibly get..Im using SQL Server 2000 and I have been given an assignment which follows:

    - i have to add 100 new records at once to an existing table.
    I have to do it through SQL Server only( query analizer,i suppose) and I am not allowed to use any other languages to achieve this. Now, my question is how can i do it through sql only? What is the code i have to write to make this thing work? I simply dont know where and how to start...

    thanx in advance and sorry for my bad english

  2. #2
    Join Date
    Feb 2004
    Posts
    492
    look up INSERT as Transact-SQL reference in BOL (Books Online, press SHIFT-F1 in the analyser).

  3. #3
    Join Date
    Jun 2004
    Posts
    8
    Thanx, Ive already done that, but i didnt find it very useful in this case..

  4. #4
    Join Date
    Sep 2003
    Location
    Germany
    Posts
    63
    In which form do you have the data? In a flat file (pure text) or do you have to type it in?

    Carsten

  5. #5
    Join Date
    Jun 2004
    Posts
    8
    Hi CarstenK,

    I have to type the data in.

  6. #6
    Join Date
    Sep 2003
    Location
    Germany
    Posts
    63
    In this case, I see two possibilites

    1. Write an SQL-Statement like:
    INSERT INTO table_1 VALUES (Value1, Value2, ValueN)

    2. Use SQL Server Enterprise Manager. Open the table and type the data in. (right mouse click on table_1 and select "Open Table > Return All Rows").

    Carsten

  7. #7
    Join Date
    Jun 2004
    Posts
    8
    OK, that would be a solution for inserting one record, right?Now , how do i insert 100 records at once?Cause thats the core of my problem..and its really driving me crazy!

    bejbika

  8. #8
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Why does the teacher want you to insert 100 rows at once? Is there some point they are trying to make?

    This can be done using just MS-SQL (using a union), but it is very poor design.

    -PatP

  9. #9
    Join Date
    Sep 2003
    Location
    Germany
    Posts
    63

    Angry

    When you go for way 1 you have to create an INSERT-statement for every record you want to insert.
    http://www.dbforums.com/images/icons/icon8.gif

  10. #10
    Join Date
    Jun 2004
    Posts
    8
    Thanx everyone on your replies!

  11. #11
    Join Date
    Feb 2004
    Posts
    492
    yeah, or create a temporary table inwhich you do the 100 inserts one by one and then do one insert selecting all the records from the temp. table into the final destination table

Posting Permissions

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