SQLCMD Mode: give it one more chance
- 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”.
SQLCMD Mode: give it one more chance的更多相关文章
- SQLCMD备忘录:执行文件夹所有Sql文件
在做性能测试的时候最希望的一件事情是数据自动导入. 一般做法就是写很多SQL文件,通过Bat自动执行所有Sql文件. Bat代码: @ECHO OFF SET SQLCMD="C:\Prog ...
- ms sql server 在cmd中执行sqlcmd的时候报错
cmd下直接输入sqlcmd会提示 错误: HResult 0x2,级别 16,状态 1命名管道提供程序: 无法打开与 SQL Server 的连接 [2].Sqlcmd: 错误: Microsoft ...
- Chance – 功能强大的 JavaScript 随机数生成类库
Chance 是一个基于 JavaScript 的随机数工具类.可以生成随机数字,名称,地址,域名,邮箱,时间等等,几乎网站中使用的任何形式的内容都能够生成.这个随机数工具可以帮助减少单调的测试数据编 ...
- poj 1698 Alice‘s Chance
poj 1698 Alice's Chance 题目地址: http://poj.org/problem?id=1698 题意: 演员Alice ,面对n场电影,每场电影拍摄持续w周,每周特定几天拍 ...
- sqlserver执行sql文件命令(sqlcmd)
个人自用sqlcmd命令: sqlcmd -E -i test.sql -d databasename -s 127.0.0.1 sqlcmd命令解释: 用法: Sqlcmd [ ...
- sqlcmd
使用sqlcmd可以在批处理脚本中执行SQL.虽然这个命令的参数很多,但幸运的是,我们不需要全部理解,在这里简要介绍以下几个: { -U login_id [ -P password ] } | –E ...
- (转)使用SQLCMD在SQLServer执行多个脚本
概述: 作为DBA,经常要用开发人员提供的SQL脚本来更新正式数据库,但是一个比较合理的开发流程,当提交脚本给DBA执行的时候,可能已经有几百个sql文件,并且有执行顺序,如我现在工作的公司,十几个客 ...
- sqlcmd 登录和执行语句。
sqlcmd -U sa -P atc@2014 -S HK-DB01 -d msdb -Q "exec sp_start_job @job_name='3PL_OUT_TEST'" ...
- linux安装sqlcmd登录sqlserver
首先从微软网站下载sqlncli安装文件,link. 因为是在内网安装,首先手工下载unixODBC2.3.0.tar.gz,下载后上传到服务器. 将下载的tar文件文件,放在同build_dm.sh ...
随机推荐
- pytest学习(3)
在pytest 2.0以上的版本里,我们也可以通过python -m pytest ...来调用.这实际上和pytest ...几乎一摸一样. 只是用python的时候,把当面目录也加入到sys.pa ...
- Laravel使用Carbon人性化显示时间
1.下载Carbon composer require nesbot/carbon Laravel自带Carbon包,可以直接使用 use Carbon\Carbon; 2.如果数据库存的是日期格式, ...
- 利用ResultFilter实现asp.net mvc3 页面静态化
为了提高网站性能.和网站的负载能力,页面静态化是一种有效的方式,这里对于asp.net mvc3 构架下的网站,提供一种个人认为比较好的静态话方式. 实现原理是通过mvc提供的过滤器扩展点实现页面内容 ...
- uiautomator2 +Python进行Android原生应用UI测试
uiautomator2封装了google的uiautomator(只能用java),uiautomator2可以使用脚本语言python进行编写,更简单直观地修改.运行自动化测试代码: 不足为:仅支 ...
- Storm学习中遇到的问题整理
在编写storm代码来进行实时分析的时候遇到了一些问题,有些的确令人比较头痛,现在稍微做一下整理.数据流向(本地-Spout-Bolt-Hdfs) 1数据的输入输出文件的路径选择 因为在此项目中数据是 ...
- UVA 10340 All in All(字符串,朴素匹配)
#include <stdio.h> #include <algorithm> #include <cstring> using namespace std; ], ...
- 欧拉图和欧拉圈-Play On Words(UVa10129)
欧拉路和欧拉圈,简言之就是,从无向图的一个结点出发,走一条路/圈,每条边恰好经过一次,即一笔画问题 欧拉定理:一个无向图最多只有两个奇结点,那么我们就从一个奇结点出发,到另一个结点为之,一定有一条欧拉 ...
- 差分数组 and 树上差分
差分数组 定义 百度百科中的差分定义 //其实这完全和要讲的没关系 qwq 进去看了之后是不是觉得看不懂? 那我简单概括一下qwq 差分数组de定义:记录当前位置的数与上一位置的数的差值. 栗子 容易 ...
- UVA GCD - Extreme (II)
discription Given the value of N, you will have to find the value of G. The definition of G is given ...
- 【kmp算法】uva11475 Extend to Palindrome
就把每个串倒过来,和原串匹配,看最后能匹配多少就行. #include<cstring> #include<algorithm> #include<cstdio> ...