Archive for the ‘SQL Server 2005’ Category
Posted by jpluimers on 2018/01/24
The subtle difference between -q and -Q: the latter will exit after executing the command (regardless of the SQL server version; I think this was introduced in SQL Server 2005 or 2000).
Inside the command, you can use single ' quotes for strings.
C:\Users\jeroenp>sqlcmd /?
Microsoft (R) SQL Server Command Line Tool
Version 10.50.2500.0 NT x64
Copyright (c) Microsoft Corporation. All rights reserved.
usage: Sqlcmd [-U login id] [-P password]
[-S server] [-H hostname] [-E trusted connection]
[-N Encrypt Connection][-C Trust Server Certificate]
[-d use database name] [-l login timeout] [-t query timeout]
[-h headers] [-s colseparator] [-w screen width]
[-a packetsize] [-e echo input] [-I Enable Quoted Identifiers]
[-c cmdend] [-L[c] list servers[clean output]]
[-q "cmdline query"] [-Q "cmdline query" and exit]
[-m errorlevel] [-V severitylevel] [-W remove trailing spaces]
[-u unicode output] [-r[0|1] msgs to stderr]
[-i inputfile] [-o outputfile] [-z new password]
[-f | i:[,o:]] [-Z new password and exit]
[-k[1|2] remove[replace] control characters]
[-y variable length type display width]
[-Y fixed length type display width]
[-p[1] print statistics[colon format]]
[-R use client regional setting]
[-b On error batch abort]
[-v var = "value"...] [-A dedicated admin connection]
[-X[1] disable commands, startup script, enviroment variables [and exit]]
[-x disable variable substitution]
[-? show syntax summary]
–jeroen
via: [WayBack] c# – How to terminate sqlcmd immediately after execution completed? – Stack Overflow
Posted in Database Development, Development, Software Development, SQL, SQL Server, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012, SQL Server 2014 | 1 Comment »
Posted by jpluimers on 2017/01/12
Static Code Analyzer for T-SQL – MS SQL Server.
Plugs into MS SSMS and can also be run from command line.It reports useful clues which you can turn/on off to your liking. http://sqlcodeguard.com/index-database-issues.html
It will spot declared but unused variables, but it appears it doesn’t do code coverage or execution path to spot stuff like variables being used without being initialized.
http://sqlcodeguard.com/ Price: Free
Source: Lars Fosdal on G+: Static Code Analyzer for T-SQL – MS SQL Server. Plugs into MS SSMS and can al…
–jeroen
Posted in Database Development, Development, SQL, SQL Server, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012, SQL Server 2014 | Leave a Comment »
Posted by jpluimers on 2016/09/28
Common table expressions are awesome. They work in at least Oracle and SQL Server.
You cannot nest them, but you can use them consecutively. Thanks spender for explaining that:
WITH
x AS
(
SELECT * FROM MyTable
),
y AS
(
SELECT * FROM x
)
SELECT * FROM y
–jeroen
via: sql – Can you create nested WITH clauses for Common Table Expressions? – Stack Overflow.
Posted in Database Development, Development, OracleDB, SQL Server, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012, SQL Server 2014 | Leave a Comment »
Posted by jpluimers on 2014/04/08
Posted in Access, Database Development, DB2, Development, Firebird, InterBase, MySQL, OracleDB, PostgreSQL, SQL, SQL Server, SQL Server 2000, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012, SQL Server 7 | Leave a Comment »
Posted by jpluimers on 2014/03/31
With SQL Server, when your database is in “Recovery Pending” mode don’t just start blindingly search google, but sit down as you might be causing more damage doing so.
After sitting down, read these two posts by Paul Randal | SQLskills.com from his SQL Server Corruption series:
- Search Engine Q&A #4: Using EMERGENCY mode to access a RECOVERY PENDING or SUSPECT database.
- SQL Server EMERGENCY mode repair.
Then think about it before acting.
Though the simplest cause for “Recovery Pending” might be that a disk spin-up was slow, or a disk became full (and everything might just be dandy after the disk is available and there is enough room on it), make sure you read the above posts first before relying on the simple causes.
–jeroen
Posted in Development, Software Development, SQL Server, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012, SQL Server 2014 | Tagged: EMERGENCY mode, Recovery Pending, SQL Server | Leave a Comment »
Posted by jpluimers on 2014/03/19
Funny way to learn something new:
I hardly use CAST and CONVERT (Transact-SQL), and when I do, it is the standard SQL-92 way.
But a while ago, I came across some code like this:
CONVERT(DATETIME, "31/12/2013", 105);
and wondered what the 105 was.
And it appeared to convert from the Italian date format to DateTime. And that it has been there since at least SQL Server 2000, probably earlier.
Not sure why the passed slashes (/) in stead of dashes (-) as separators though.
There are styles for these groups of conversions:
- Binary
- Date/Time
- Float/Real
- Money/Smallmoney
- XML
Never to old to learn something new (:
–jeroen
Posted in Database Development, Development, SQL Server, SQL Server 2000, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012 | Leave a Comment »
Posted by jpluimers on 2014/01/14
Last year, I had a very odd project at a client.
Their monitoring software was quite odd, and there was no time to create/test/implement a module for it doing SQL query performance measurement any better.
The odd software had two ways of looking at queries:
- in a succeed/fail fashion
- in a count(*) fashion
Don’t ask why it was that way, the monitor was hysterically grown.
So below is a small query script that does what the odd monitoring software can do: provide a select with rows indicating the query response time.
What is does is insert into the #sma temporary table a number of records depending on the query duration.
The partition here is 1 record per 125 milliseconds, aiming for four partitions (green, yellow, orange, red) in half a second.
Note the maximum accuracy is about 3.3 milliseconds.
The script is based on these SQL server features:
I might add a try/catch to fake a finally in case the #sma insert fails. Read the rest of this entry »
Posted in Database Development, Development, SQL Server, SQL Server 2000, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012 | Leave a Comment »
Posted by jpluimers on 2013/12/24
This has bitten me so many times, so I’m glad I found the below question/answers on StackOverflow.
When you perform calculations in SQL Server involving numeric literals, you have to take into account which precision you want your result to be, and CAST/CONVERT the literals accordingly.
The reason is condensed to this statement by Lieven Keersmaekers:
SQL Server uses the smallest possible datatype.
He follows with examples to view the actual representation of a literal/expression using SQL_VARIANT_PROPERTY (which has been there since at least SQL Server 2000).
SELECT SQL_VARIANT_PROPERTY(1.0, 'BaseType')
SELECT SQL_VARIANT_PROPERTY(1.0, 'Precision')
SELECT SQL_VARIANT_PROPERTY(1.0, 'Scale')
SELECT SQL_VARIANT_PROPERTY(1.0, 'TotalBytes')
Read the rest of this entry »
Posted in Algorithms, Database Development, Development, Floating point handling, Software Development, SQL Server, SQL Server 2000, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012, SQL Server 7 | Leave a Comment »