The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,860 other subscribers

Archive for the ‘SQL Server 2008’ Category

SQL Server: some links on displaying query plans

Posted by jpluimers on 2013/10/02

Link dump:

–jeroen

Posted in Database Development, Development, SQL, SQL Server, SQL Server 2000, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012 | Leave a Comment »

SQL query to get the deadlocks in SQL SERVER 2005 and up

Posted by jpluimers on 2013/09/05

Darren Davies answered via SQL query to get the deadlocks in SQL SERVER 2008 – Stack Overflow a while ago listing a great SQL statement by Mladen Prajdić that shows how to do without the deprecated SP_LOCKS and SP_WHO2 (which is undocumented, and slightly different from SP_WHO) or the good old SP_LOCK2.

It is the textual equivalent of the Deadlock Graph, which is part of the SQL Server Profiler.
I like that profiler a lot (read this step-by-step intro if you haven’t used it), but some environments consider it too much power for a developer to use.

The SP_LOCKS documentation directs you to the sys.dm_tran_locks documentation, which is the base of the SQL below. It requires the mostly harmless VIEW SERVER STATE permission.

Finding out what to join in order to get some readable results suited for quick troubleshooting is quite an undertaking.
Mladen did all that, and this is his SQL: 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 »

Database Workbench 4.4.1 released (via: News @ Upscene Productions)

Posted by jpluimers on 2013/08/22

I like this Delphi program very much: it is one of the database tools with the widest support of back-ends, and friendliest user interface I know.

Oh, and it is by a great Dutch company too: UpScene (:

So this is their release information:

2013-08-19:

Database Workbench 4.4.1 released

This new release of Database Workbench brings new features and fixes for issues reported by our users.

The free Lite Editions will be released later.

Multi-DBMS developer tool

Database Workbench works natively with:

  • Oracle Database
  • Microsoft SQL Server
  • Sybase SQL Anywhere
  • MySQL
  • Firebird
  • InterBase
  • NexusDB

More information about Database Workbench is available at the Database Workbench page, download your copy today via our downloads page, pricing information is available.

This release includes fixes for the InterBase, Firebird, MySQL and Microsoft SQL Server modules, as well as general fixes and small new features.

The full details and list of changes in 4.4.1 is available here.

–jeroen

via: News @ Upscene Productions.

Posted in Database Development, Delphi, Development, Firebird, InterBase, MySQL, OracleDB, Software Development, SQL, SQL Server, SQL Server 2000, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012, Sybase | 2 Comments »

Firebird and InterBase have single direction indexes for your data safety.

Posted by jpluimers on 2013/01/18

In most database index nodes are doubly linked to allow bi-directional scans. http://is.gd/8CMb7w, however not for InterBase and FireBird, there the reverse link isn’t used because it can be inconsistent due to write order of index pages.

The result is that in Firebird and InterBase, indexes are single-directional (either ascending or descending).

This is for your safety: it guarantees index consistency, even if because of EMP, your machine suddenly reboots after your tank fired a missile.

–jeroen

via Twitter / Avalanche1979: @SQLPerfTips For Firebird the ….

(Wow, did I really wrote 1200 blog posts?)

Posted in Database Development, DB2, Development, Firebird, InterBase, MySQL, OracleDB, PostgreSQL, SQL Server, SQL Server 2000, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012, SQL Server 7, Sybase | Leave a Comment »

Adding the localized [BUILTIN\Administrators] as SQL Server and giving them SA equivalent rights

Posted by jpluimers on 2013/01/02

On development machines it can be comfortable to add the local Administrators group to SQL Server, and make them equivalent to SA (SQL Server Administrator).

This especially as SA is disabled by default when you install using Windows Authentication mode (which is the default). You can Change Server Authentication Mode to include SQL Server mode, but then you still have to enable SA (you can even rename SA)

This is basically what you want to do:

CREATE LOGIN [BUILTIN\Administrators] FROM WINDOWS WITH DEFAULT_DATABASE=[master];
EXEC master..sp_addsrvrolemember @loginame = N'BUILTIN\Administrators', @rolename = N'sysadmin';
GRANT CONTROL SERVER TO [BUILTIN\Administrators];

There are a few gotchas here:

  • The name of the group BUILTIN\Administrators depends on the localization of your system.
    This is one of the reasons I usually advise clients to have server systems run on the most common ENU (English USA) localization of Windows.
    Another reason is that it is far easier to find information ENU English Messages back on the internet.
  • You need to be SQL Server Administrator to begin with.
    There is a little trick to get this done: you can stop the SQL Server service, then restart SQL Server it in single-user mode.
    In single-user mode, members from the BUILTIN\Administrators group can connect as a member of the sysadmin fixed server role.
  • If you want to access SQL Server as member from BUILTIN\Administrators, you need to run your SQL client tools with the UAC elevated permission (otherwise the Administrative bit is not set, and the BUILTIN\Administrators is not recognized).

That’s what the batch file below solves.

You need to start it as member of BUILTIN\Administrators with elevated privilege (the easiest way is to run it from an elevated command prompt).

It will: Read the rest of this entry »

Posted in Batch-Files, Database Development, Development, Scripting, Software Development, SQL Server, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012 | Leave a Comment »

Re-adding a user to SQL Server 2000 and up when it was Orphaned

Posted by jpluimers on 2012/12/25

In SQL Server 2000 and up, the easiest way to re-add a user that got orphaned is with a script like below.

The script does not correct the SID, but in stead sets new permissions (in this case, db_datareader and db_datawriter). Most of the times that is not a problem.

The script uses these stored procedures:

  1. sp_dropuser – drops a user from the current database
  2. sp_droplogin – drops a login from the current server
  3. sp_addlogin – adds a login to the database server
  4. sp_adduser – adds a user to the current database (you can add both a SQL user – with name and password – and a Windows user)
  5. sp_addrolemember – adds a member to a certain role

More modern versions have alternatives to these stored procedures, but the stored procedures work with the widest ranges of SQL Server versions.

-- Execute this script as SA or DB Administrator

use MyDatabase -- the databae where you want the user to be re-added to

-- you cannot perform a 'use [MyDatabase]' without destroying the context (and declared variables)
-- http://stackoverflow.com/questions/9165513/sql-server-change-current-database-via-variable
-- it is possible with exec (@exec_stmt) (as sp_droplogin does it), but it is a bit cumbersome for a relatively simple script

declare @loginname sysname
declare @passwd sysname

set @loginname = 'MyUser'
set @passwd = 'MyPassword'

-- from current database
exec sp_dropuser @loginname

-- from server
exec sp_droplogin @loginname

-- to current server
exec sp_addlogin @loginname, @passwd

-- to current database
exec sp_adduser @loginname

-- roles to add the user to
exec sp_addrolemember db_datareader, @loginname
exec sp_addrolemember db_datawriter, @loginname

If the user didn’t exist in the database, or didn’t exist as a login on the server, you can get two errors like these: 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, SQL Server 7 | Leave a Comment »

SQL Server FineBuild

Posted by jpluimers on 2012/12/21

Interesting; is on my research list to see if the installation process gets easier and more standardized.

SQL Server FineBuild Introduction

FineBuild provides 1-click install and best-practice configuration of SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, and SQL Server 2005.

–jeroen

via: SQL Server FineBuild.

Posted in Database Development, Development, Power User, Reporting Services, SQL Server, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012, Windows, Windows 7, Windows 8, Windows Server 2003, Windows Server 2003 R2, Windows Server 2008, Windows Server 2008 R2, Windows Vista, Windows XP | Leave a Comment »

Be aware of the three valued logic when NULL gets involved: SQL Server: JOIN vs IN vs EXISTS – the logical difference

Posted by jpluimers on 2012/11/29

Great post: SQL Server: JOIN vs IN vs EXISTS – the logical difference.

Be aware of the three valued logic when NULL gets involved.

EXIST comes closes to what you expect.

And be aware that with IN, you cannod pass one parameter containing more than 1 IN value: sql server 2005 – Passing multiple values for one SQL parameter – Stack Overflow..

–jeroen

Posted in Database Development, Development, 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 »

System Error Messages: anyone who has links for SQL Server > 2000?

Posted by jpluimers on 2012/11/27

I could only find the System Error Messages overview for:

Are there any such links for SQL Server 2005 and up?

The odd thing is online lists of Database Engine Error Severities are available for multiple versions of SQL Server: 2005, 2008 and 2008 R2.

–jeroen

Posted in Database Development, Development, SQL Server, SQL Server 2000, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012, SQL Server 7 | 1 Comment »

SQL Server quick tip by Denis Gobo: use DBCC SHOWCONTIG for Min/Max/Average row sizes (via: sql server – Size of a single Record ? SQL – Stack Overflow)

Posted by jpluimers on 2012/11/22

Thanks SQLMenace (Denis Gobo) for this great tip on getting min/max/average row sizes (and more) using DBCC SHOWCONTIG.

Don’t forget the “with tableresults”, without it, it will skip the min/max/average recordsize from the results, and present the results as text (not as a row).

 

 

Run DBCC SHOWCONTIG with your table name

dbcc showcontig ('TableName') with tableresults

then look at max min and average record size

This feature works at least from SQL Server 2000 onward, though somewhere after SQL Server 2012 it will be removed.
As of SQL Server 2005 you can use sys.dm_db_index_physical_stats. An example on how to use that is here.

It just made me shiver when finding out an unindexed table with 9 million rows averaging about 300 bytes took 8 minutes to query.
Time to add some indexes, and have someone look at the disk back-end.

–jeroen

via: sql server – Size of a single Record ? SQL – Stack Overflow.

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 »