sqlcmd

SqlServer 08: Query to list all databases in an instance?

寵の児 提交于 2019-12-03 09:36:23
How do I list all the databases for a given sql server 08 instance using sqlcmd? sqlcmd -E -S SERVER\INSTANCE -Q "sp_databases" EXEC sp_databases or SELECT NAME FROM sys.sysdatabases or EXEC sp_msForEachDB 'PRINT ''?'''; To elaborate with more detail for the sqlcmd newbie: C:\> sqlcmd -S <the_server_name> 1> select name from sys.databases 2> go You can use sp_databases stored procedure. 来源: https://stackoverflow.com/questions/2087902/sqlserver-08-query-to-list-all-databases-in-an-instance

How to suppress hyphens in SQLCMD

陌路散爱 提交于 2019-12-03 09:14:42
问题 How can I suppress hyphens (------------) from the results set of this sqlcmd command: C:\temp>sqlcmd -d AdventureWorks -s ";" -Q "SET NOCOUNT ON SELECT top 5 FirstName, LastName FROM Person.Contact;" FirstName ;LastName --------------------------------------------------;---------------------------- Gustavo ;Achong Catherine ;Abel Kim ;Abercrombie Humberto ;Acevedo Pilar ;Ackerman C:\temp> 回答1: I don't think there's any option available to achieve this - you'll have to live with those headers

Sqlcmd to generate file without dashed line under header, without row count

你说的曾经没有我的故事 提交于 2019-12-03 07:22:50
问题 Using the following sqlcmd script: sqlcmd -S . -d MyDb -E -s, -W -Q "select account,rptmonth, thename from theTable" > c:\dataExport.csv I get an csv output file containing acctnum,rptmonth,facilname -------,--------,--------- ALLE04,201406,Allendale Community for Senior Living-LTC APPL02,201406,Applewood Estates ARBO02,201406,Arbors Care Center ARIS01,201406,AristaCare at Cherry Hill . . . (139 rows affected) Is there a way to get rid of the dashed line under the column headers : -------,---

SQLCMD utility from BAT file - how to return ERRORLEVEL in case of syntax error

爷,独闯天下 提交于 2019-12-03 07:16:44
How can I get %ERRORLEVEL% from SQLCMD utility when some of .sql files contains syntax error? These files create stored procedures. They don't invoke "raiseerror", but they can conatin syntax error and I need to terminate the process. But it always returns %ERRORLEVEL% as 0. I tried use -b, -V and -m (and their combinations), but nothing worked for me as expected. Here's the code fragment of my BAT file. REM process all sql files in "SQL\scripts" folder and subfolders FOR /R "SQL\scripts" %%G IN (*.sql) DO ( sqlcmd -d %1 -S %2 -U %3 -P %4 -i "%%G" -b -V 1 echo %ERRORLEVEL% IF %ERRORLEVEL% NEQ

Docker + mssql-server-linux: How to launch .sql file during build (from Dockerfile)

流过昼夜 提交于 2019-12-03 01:56:28
I am trying to create my own Docker image with MSSQL DB for development. It's based on microsoft/mssql-server-linux image. During the build I want to copy some .sql files into the container and then run these scripts (to create DB schemas, tables, insert some data etc.). My Dockerfile looks like this: # use MSSQL 2017 image on Ubuntu 16.04 FROM microsoft/mssql-server-linux:2017-latest # create directory within SQL container for database files RUN mkdir -p /opt/mssql-scripts # copy the database files from host to container COPY sql/000_create_db.sql /opt/mssql-scripts # set environment

How to suppress hyphens in SQLCMD

拟墨画扇 提交于 2019-12-02 22:02:30
How can I suppress hyphens (------------) from the results set of this sqlcmd command: C:\temp>sqlcmd -d AdventureWorks -s ";" -Q "SET NOCOUNT ON SELECT top 5 FirstName, LastName FROM Person.Contact;" FirstName ;LastName --------------------------------------------------;---------------------------- Gustavo ;Achong Catherine ;Abel Kim ;Abercrombie Humberto ;Acevedo Pilar ;Ackerman C:\temp> I don't think there's any option available to achieve this - you'll have to live with those headers, I'm afraid. Stef Heyenrath The only thing I can think of is removing the header using the -h -1 switch and

Sqlcmd to generate file without dashed line under header, without row count

孤街浪徒 提交于 2019-12-02 20:57:50
Using the following sqlcmd script: sqlcmd -S . -d MyDb -E -s, -W -Q "select account,rptmonth, thename from theTable" > c:\dataExport.csv I get an csv output file containing acctnum,rptmonth,facilname -------,--------,--------- ALLE04,201406,Allendale Community for Senior Living-LTC APPL02,201406,Applewood Estates ARBO02,201406,Arbors Care Center ARIS01,201406,AristaCare at Cherry Hill . . . (139 rows affected) Is there a way to get rid of the dashed line under the column headers : -------,--------, but keep the column headers? and also a way to get rid of the two lines used for the row count

Running a SQLCMD script from SSIS Execute Process Task with variables

我的未来我决定 提交于 2019-12-02 20:55:58
问题 I have an .sql file with scripts that include SQLCMD elements. I need to have it run from an SSIS package. I was unable to execute it from an "Execute SQL Task". According to this http://www.sqlservercentral.com/Forums/Topic818940-147-1.aspx I should use an "Execute Process Task" with: Executable: C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE Arguments: -S server -U user -P pass -i C:\path\to\file.sql This is working fine. But, I need the Arguments to include a Variable.

How to properly manage database deployment with SSDT and Visual Studio 2012 Database Projects?

折月煮酒 提交于 2019-12-02 13:52:35
I'm in the research phase trying to adopt 2012 Database Projects on an existing small project. I'm a C# developer, not a DBA, so I'm not particularly fluent with best practices. I've been searching google and stackoverflow for a few hours now but I still don't know how to handle some key deployment scenarios properly. 1) Over the course of several development cycles, how do I manage multiple versions of my database? If I have a client on v3 of my database and I want to upgrade them to v8, how do I manage this? We currently manage hand-crafted schema and data migration scripts for every version

Running a SQLCMD script from SSIS Execute Process Task with variables

a 夏天 提交于 2019-12-02 11:51:07
I have an .sql file with scripts that include SQLCMD elements. I need to have it run from an SSIS package. I was unable to execute it from an "Execute SQL Task". According to this http://www.sqlservercentral.com/Forums/Topic818940-147-1.aspx I should use an "Execute Process Task" with: Executable: C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE Arguments: -S server -U user -P pass -i C:\path\to\file.sql This is working fine. But, I need the Arguments to include a Variable. What ever I try, it is failing. Arguments: -S server -U user -P pass -i @[User::FileNameView] The error: