Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2003
    Posts
    218

    Unanswered: How to run a insert script in SQL Server

    MS SQL Server 2005 on Win2003 EE.

    I am new to SQL Server.. Can someone let me know how to run a script file from sqlcmd prompt in sql server?

    I tried this command and got an error: label names must be unique within a query or stored procedure.

    sqlcmd -U sa -P sa -d Test -i c:\tmp\t1.sql -o c:\tmp\1.log


    Table: t1
    c1 nchar(10)
    c2 nchar(10)

    t1.sql
    insert into t1 (c1, c2) values ('1', '2');
    GO

    Thanks in advance.

  2. #2
    Join Date
    Dec 2005
    Location
    Tilburg, Netherlands
    Posts
    73
    If the file says only:

    Code:
    insert into test..t1 (c1, c2) values ('1', '2')
    go
    it should insert the tuple (1,2) into the table t1 in the database test, using the default schema for the user (so dbo will be used I guess) ...

    > SELECT * FROM users WHERE clue > 0;
    Empty set (0.00 sec)


  3. #3
    Join Date
    Sep 2003
    Posts
    218
    No I am not seeing the results. Following error is shown:

    The label 'c' has already been declared. Label names must be unique within a query batch or stored procedure.

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Have you installed the SQL server Client Tools?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  5. #5
    Join Date
    Sep 2003
    Posts
    218
    I did not install the suite.. but when I look into the folder, I see MS SQL Server Management Studio, DTS etc. I am running the command from command prompt using sqlcmd...

    I know in SQL2000 we use to have SQL Query Analyzer however, not sure if they have changed in SQL2005!?

    Thanks.

  6. #6
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    SQL Server Mangement Studio is the new EM/QA

    If you've done QA before, how come you are doing command ine?

    Oracle fiend?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  7. #7
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    How about:
    Code:
    insert into test..t1 ([c1], [c2]) values ('1', '2')
    go

  8. #8
    Join Date
    Sep 2003
    Posts
    218
    The reason for trying out from the command line is that we obtained a script with insert statements and this needs to be run using command line!!

    Tried what MCrowley suggested.. but no luck.. same error gets reported in the sqlcmd window.

  9. #9
    Join Date
    Dec 2005
    Location
    Tilburg, Netherlands
    Posts
    73
    Ok, let's take it from the top here ... Do you even get connected to a SQL Server ?
    Try:
    Code:
    sqlcmd -U sa -P sa -S <ServerName>
    If all goes well, you should see the '1>' prompt and from there you should be able to do SQL from there. Something like 'select getdate()' (followed by 'go') should give some result.

    Does that work ?

    Gr,
    Yveau

    > SELECT * FROM users WHERE clue > 0;
    Empty set (0.00 sec)


Posting Permissions

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