Wednesday, March 21, 2012

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.If the file says only:

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) ...|||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.|||Have you installed the SQL server Client Tools?|||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.|||SQL Server Mangement Studio is the new EM/QA

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

Oracle fiend?|||How about:

insert into test..t1 ([c1], [c2]) values ('1', '2')
go|||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.|||Ok, let's take it from the top here ... Do you even get connected to a SQL Server ?
Try:
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

No comments:

Post a Comment