Quantcast
Channel: microsoft sql server – SQL Studies
Browsing index pages (450 articles)

Image may be NSFW.
Clik here to view.

Viewing errors with extended events

A little while back I came across this post: Identifying failed queries with extended events. It has a script to create an extended event that tracks failed queries. I cannot tell you how excited I...

View Article


Conversion Precedence

Recently I talked about the difference between implicit and explicit datatype conversions. In it I ran this code: DECLARE @IntA INT = 1, @IntB INT = 2; SELECT 1.0*@IntA/@IntB; With the expectation...

View Article


Image may be NSFW.
Clik here to view.

Creating a SERVER ROLE created a LOGIN as well.

One of my co-workers came to me the other day and told me that they found their network id as a login on one of our SQL Server instances. Why is that note worthy? We make a point of using AD groups if...

View Article

Image may be NSFW.
Clik here to view.

Explicit and implicit datatype conversions

Did you know that 1/2=0? If you didn’t you could be in for some interesting surprises. 1/2 returns 0 because 1 and 2 are both integers. When you divide two integers you get back an integer. Now, we,...

View Article

SQL Server Query Tuning and Optimization by Benjamin Nevarez

I was recently asked to review SQL Server Query Tuning and Optimization by Benjamin Nevarez (blog|twitter), and as soon as I saw who had written the book I jumped at the chance. I want to start this...

View Article


Using DBCC CLONEDATABASE to create a schema only copy of your database.

DBCC CLONEDATABASE is one of those features that I don’t use often but it’s really cool when I need it. I was recently asked to create schema only copies of ~40 databases. This DBCC command was...

View Article

Image may be NSFW.
Clik here to view.

EXECUTE AS USER vs EXECUTE AS LOGIN

I use impersonation a lot. It’s a really easy way to check if someone has the permissions they are supposed to. That said, a co-worker recently had an interesting question. They were testing...

View Article

Image may be NSFW.
Clik here to view.

SSMS Put pinned tabs in their own row

A while back (6 years ago ) I talked about how you can change the behavior of SSMS so that the pinned tabs have their own row across the top of the screen. In fact, if you have a bunch of pinned tabs...

View Article


How do I tell if identity_insert is turned on and if so what table?

TLDR; The code to do this is below but it’s a bit hokey and probably isn’t worth it. It’s pretty unlikely that you’d ever need it. I just had someone ask me this question. It’s an interesting question...

View Article


An auditing mind set

I little while back I presented at Pass Data Community Summit. Specifically the presentation was Auditing your data and data access and as with each of the presentations I’ve done I not only learned a...

View Article

Getting a list of the articles in a publication.

The other day I was asked to supply a list of all of the tables being replicated into a given database. Now, for those of you that aren’t aware, if I replicate a group of tables from database SourceDB...

View Article

Image may be NSFW.
Clik here to view.

How can I use the identity column, without knowing identity column’s name.

One of the most fun parts of blogging is when you learn something completely unexpected while writing a blog. The other day I was writing my most recent SQL Homework post about using Microsoft Docs...

View Article

Scripting with a temp stored procedure

A few years back I learned about temporary stored procedures from a Kendra Little (blog|twitter) blog post. At the time the only use I had for them (and it’s a pretty spectacular use) was performance...

View Article


Shift calculations (or same time every day)

One of the more interesting jobs I’ve had over the years was for a company that created emergency room software. It was pretty cool software and I learned a lot, both about writing queries in SQL...

View Article

I’m writing a SQL Server security presentation and I need your help.

I’m working on a new presentation titled Watch Ken solve security headaches in SQL Server. In this presentation I’m going to pick a handful of common security problems and solve them in demos. How...

View Article


Image may be NSFW.
Clik here to view.

Help, not all of my column is displaying in the output of the query!

I’ll be honest, I don’t remember if I’ve written about this before but I couldn’t find it, so here we go. Have you ever run a query and not all of your output is displaying? CREATE TABLE #test (col1...

View Article

Image may be NSFW.
Clik here to view.

A DBA horror story in database file extensions.

CREATE DATABASE [Story] ON PRIMARY ( NAME = N'Story', FILENAME = N'C:\Data\Story.mdf', SIZE = 101MB), FILEGROUP [Line1] ( NAME = N'File1', FILENAME = N'C:\Data\_.It', SIZE = 102MB), ( NAME = N'File2',...

View Article


Image may be NSFW.
Clik here to view.

The sysname datatype defaults to not NULL.

The other day I was creating a table to store some metadata. Since the metadata I was collecting (sys.databases.name for example) uses the datatype sysname I used the same datatype. In case you didn’t...

View Article

Image may be NSFW.
Clik here to view.

Experiment: Does sp_recompile on a table update associated views.

tldr: No. You have to use sp_refreshview. One of the only good things to come out of all of the lockdowns this last year is the opportunity to attend presentations at user groups that aren’t in your...

View Article

Padding a string in SQL Server

I’ve been working on converting a piece of DB2 code into T-SQL and one of the functions I had to replace was lpad. It’s a simple enough function that will pad a string on the left with another string....

View Article
Browsing index pages (450 articles)


Latest Images