Results 1 to 6 of 6

Thread: Query

  1. #1
    Join Date
    May 2002
    Posts
    73

    Unanswered: Query

    Hello folks,

    Im new in database bussines. I will appreciate if someone can help me.
    I need to insert new records to a table. First of all I dont know what is the syntax for insert command in SQL Server2000. Also one of the fields to insert is changing every second so I think I will need to include in the insert command a nested select statement.
    For example,

    The table has the ID field and this field is the one is changing every time. If in the n second I do a select to know what value such field has I could use the value equal to ID + 1. But while I build query, type and execute it will be the second n+1, so probably the value for ID now is already equal to ID + 1 and my query will fail because the duplicated record error.

    I hope is clear what the proble I have,

    Regards,

  2. #2
    Join Date
    Dec 2002
    Location
    Antwerp, Belgium
    Posts
    227
    You can look in BooksOnline (comes with the sql server) for the syntax on insert statements.
    If your changing field is the ID for a record, you can use auto numbering on this field. This means that sql server itself will keep track of the value of the field and makes sure there are no duplicates.

    hth
    Johan

  3. #3
    Join Date
    May 2002
    Posts
    73

    Query

    So can I just use:

    insert into table_name values(ID,'MNAME','F_NAME')....

    I was thinking that some other query was needed to be introduced to get the new value for ID field, ie.

    insert into table_name values(((select ID from TABLE)+1),'M_NAME','F_NAME')

    Thanks

  4. #4
    Join Date
    Dec 2002
    Location
    Antwerp, Belgium
    Posts
    227
    Not completely correct yet, your insert statement. If the ID column is set to auto numbering, you don't include it in the insert statement. Your statement will be:
    insert into table_name values('MNAME','F_NAME')
    Johan

  5. #5
    Join Date
    May 2002
    Posts
    73

    autonumbering

    Thanks, How I can know if the field is autonumbering?

    How I can get the table fields with all it properties using SQL Command?

    In db2 it was with command describe table...
    It is the same?

    Regards,

  6. #6
    Join Date
    Dec 2002
    Location
    Antwerp, Belgium
    Posts
    227
    in sql server, there is a stored proeedure for this information called 'sp_columns'. See BOL for more information. You can also find information about using auto numbering in BOL, just search on 'identity'.
    Johan

Posting Permissions

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