SQLCMD Mode: give it one more chance

From : http://sqlblog.com/blogs/maria_zakourdaev/archive/2012/05/11/sqlcmd-mode-give-it-one-more-chance.aspx?utm_source=tuicool

- Click on me. Choose me. - asked one forgotten feature when some bored DBA was purposelessly wondering through the Management Studio menu at the end of her long and busy working day.

- Why would I use you? I have heard of no one who does. What are you for? - perplexedly wondered aged and wise DBA. At least that DBA thought she was aged and wise though each day tried to prove to her that she wasn‘t.

- I know you. You are quite lazy. Why would you do additional clicks to move from window to window? From Tool to tool ? This is irritating, isn‘t it? I can run windows system commands, sql statements and much more from the same script, from the same query window!

- I have all my tools that I‘m used to, I have Management Studio, Cmd, Powershell. They can do anything for me. I don’t need additional tools.

- I promise you, you will like me. – the thing continued to whine .

- All right, show me. – she gave up. It’s always this way, she thought sadly, - easier to agree than to explain why you don’t want.

- Enable me and then think about anything that you always couldn’t do through the management studio and had to use other tools.

- Ok. Google for me the list of greatest features of SQL SERVER 2012.

- Well... I’m not sure... Think about something else.

- Ok, here is something easy for you. I want to check if file folder exists or if file is there. Though, I can easily do this using xp_cmdshell …

- This is easy for me. – rejoiced the feature.

By the way, having the items of the menu talking to you usually means you should stop working and go home. Or drink coffee. Or both. Well, aged and wise dba wasn’t thinking about the weirdness of the situation at that moment.

- After enabling me, – said unfairly forgotten feature (it was thinking of itself in such manner) – after enabling me you can use all command line commands in the same management studio query window by adding two exclamation marks!! at the beginning of the script line to denote that you want to use cmd command:

-Just keep in mind that when using this feature, you are actually running the commands ON YOUR computer and not on SQL server that query window is connected to. This is main difference from using xp_cmdshell which is executing commands on sql server itself. Bottomline, use UNC path instead of local path.

- Look, there are much more than that. - The SQLCMD feature was getting exited.- You can get IP of your servers, create, rename and drop folders. You can see the contents of any file anywhere and even start different tools from the same query window:

Not so aged and wise DBA was getting interested: - I also want to run different scripts on different servers without changing connection of the query window.

- Sure, sure! Another great feature that CMDmode is providing us with and giving more power to querying. Use “:” to use additional features, like :connect that allows you to change connection:

- Now imagine, you have one script where you have all your changes, like creating staging table on the DWH staging server, adding fact table to DWH itself and updating stored procedures in the server where reporting database is located.

- Now, give me more challenges!

- Script out a list of stored procedures into the text files.

- You can do it easily by using command :out which will write the query results into the specified text file. The output can be the code of the stored procedure or any data. Actually this is the same as changing the query output into the file instead of the grid.

- Now, take all of the scripts and run all of them, one by one, on the different server.

- Easily

- Come on... I’m sure that you can not...

-Why not? Naturally, I can do it using :r commant which is opening a script and executing it. Look, I can also use :setvar command to define an environment variable in SQLCMD mode. Just note that you have to leave the empty string between :r commands, otherwise it’s not working although I have no idea why.

- Wow.- She was really impressed. - Ok, I’ll go to try all those…

-Wait, wait! I know how to google the SQL SERVER features for you! This example will open chrome explorer with search results for the “SQL server 2012 top features” ( change the path to suit your PC):

“Well, this can be probably useful stuff, maybe this feature is really unfairly forgotten”, thought the DBA while going through the dark empty parking lot to her lonely car. “As someone really wise once said: “It is what we think we know that keeps us from learning. Learn, unlearn and relearn”.

时间: 2024-10-13 18:29:12

SQLCMD Mode: give it one more chance的相关文章

poj 1698 Alice's Chance(网络流)

Alice's Chance Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5280   Accepted: 2171 Description Alice, a charming girl, have been dreaming of being a movie star for long. Her chances will come now, for several filmmaking companies invit

SQLCMD备忘录:执行文件夹所有Sql文件

在做性能测试的时候最希望的一件事情是数据自动导入. 一般做法就是写很多SQL文件,通过Bat自动执行所有Sql文件. Bat代码: @ECHO OFF SET SQLCMD="C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE" SET PATH="C:\path\to\sql\files\" SET SERVER="Server\Instance" SET DB=&qu

sqlcmd导入大数据文件

SQLCMD 允许在Windows命令窗中通过命令行提示符运行脚本. 语法如下: sqlcmd  [  { { -U <login id> [ -P <password> ] } | -E }  ]  [-S <server> [ \<instance > ] ] [ -H <workstation> ] [ -d <database> ]  [ -l <time out> ] [ -t <time out>

POJ 1698 Alice&#39;s Chance 网络流(水

题目链接:点击打开链接 题目大意:   有个人想拍n部电影,每部电影限定每周哪几天可以拍 并且必须在第ki周之前把这部电影拍完,问能否拍完n部电影 解题思路:  把每部电影当作一个顶点,源点指向这些顶点,容量为该电影需要拍多少天 然后把每一天都当作顶点,某个工作可以在这天完成就连容量为1大边 每天的顶点指向汇点,容量也为1 最后求出最大流,满流则说明可以完成这些工作 啦啦啦 #include <cstdio> #include <cstring> #include <algo

理解First Chance和Second Chance避免单步调试

原文链接地址:http://blog.csdn.net/Donjuan/article/details/3859160 在现在C++.Java..Net代码大行其道的时候,很多代码错误(Bug)都是通过异常的形式表现出来的.由于工期紧或者种种原因,很多程序员在碰到程序发生未处理的异常的第一反应就是try - catch (Exception e) { - }.然而代码开发到后期的时候,这种简单粗暴的解决代码错误(Bug)的方式就会在其他不相干的地方表现出来,有的时候甚至导致程序随机的不稳定,而且

[poj1698]Alice&#39;s Chance[网络流]

[转]原文:http://blog.csdn.net/wangjian8006/article/details/7926040 题目大意:爱丽丝要拍电影,有n部电影,规定爱丽丝每部电影在每个礼拜只有固定的几天可以拍电影,只可以拍前面w个礼拜,并且这部电影要拍d天,问爱丽丝能不能拍完所有的电影第一行代表有多少组数据对于每组数据第一行代表有n部电影接下来2到n+1行,每行代表一个电影,每行9个数,前面7个数,1代表拍,0代表不拍,第8个数代表要拍几天,第9个数代表有几个礼拜时间拍 解题思路:这题可以

使用SQLCMD清理WSUS 数据库。

WSUS 运行一段时间以后,会累积一些过期的补丁或者电脑信息,长期不进行清理,则可能造成数据库越来越大,然后WSUS Server越来越慢,客户端无法通过WSUS 安装补丁等情况. WSUS 提供了一个Server Cleanup Wizard,可以帮助我们清理WSUS .如果之前长期没有进行清理,数据太大或者数据库存在一些问题,则可能会在清理的过程中碰到数据库错误,无法无法清理工作. 因为WSUS使用的是Internal SQL Databse,所以,如果出现这种情况,可以使用SQLCMD工具

使用SQLCMD在SQLServer执行多个脚本 转载

出处不明 概述: 作为DBA,经常要用开发人员提供的SQL脚本来更新正式数据库,但是一个比较合理的开发流程,当提交脚本给DBA执行的时候,可能已经有几百个sql文件,并且有执行顺序,如我现在工作的公司,十几个客户,每个客户一个库,但是数据库结构.存储过程.视图等都是一模一样,每次执行脚本(以下称为升级),如果有一百个脚本,那么就要按顺序执行过千次,这种工作量可不是一个人能承受得了的. 解决方法: 应对这种情况有以下几种方法: 1.  购买第三方软件(一般估计很少人买) 2.  自己编程一个小软件

转:SQLServer的命令行工具-sqlcmd等..

转:http://blog.csdn.net/leamonjxl/article/details/6428753 和往常一样,我们先使用 /?来看看sqlcmd的启动参数们: C:Documents and Settingschenxie.IFLYTEK>sqlcmd.exe /? Microsoft (R) SQL Server 命令行工具 版本 9.00.1399.06 NT INTEL X86 版权所有 (c) Microsoft Corporation.保留所有权利. 用法: Sqlcm