SQLServerCentral - www.sqlservercentral.com

A community of more than 1,600,000 database professionals and growing

Featured Contents

The Voice of the DBA

The Helpful Triggers

Today is the day for T-SQL Tuesday #106 entries. I'm the host this time, which means that I'll have a busy week trying to compile all the entries for the round up. Last week I wrote the invitation, which was on triggers. Actually, I wrote the invitation in August, trying to be prepared in case my August host fell through, but Wayne Sheffield did a great job, so my hosting duties went on as planned. You still have time to write a post today for the party, but if you read this later, write at anytime. T-SQL Tuesday is a great set of ideas for blog posts, if you're ever looking for an idea.

When I think of triggers, overall I think of the headaches they have caused me. Since I rarely see them in most systems, when they do appear, it's often because I can't determine why some strange action is occurring and after hours of troubleshooting, someone else will usually suggest checking a trigger. At least, that's been my experience in the past. These days when something unexpected happens, I tend to think trigger earlier, but I hate that they're kind of hidden. The DDL is separate from the table, the folder in SSMS isn't obvious. Really I wish that trigger folder was hidden unless there was a trigger. That would be nice.

In any case, my thoughts on this T-SQL Tuesday are actually a time when I thought a trigger solved a problem really well for me. In this case we had an OLTP application and a finance application. In the pre-SSIS, pre-DTS days, moving data between systems was cumbersome, and in this case, I needed to move over some data reliably from one to the other. We elected for replication, since that would solve our issues, but these were disparate systems, with different schemas, and more importantly, a schema were were not supposed to alter for the finance application. 

Enter loose coupling. I set up two additional databases, one on each instance. In these I had my tables that were to be replicated, and that worked really well, until it didn't. Even in the v6.5 days replication would sometimes flake. No problem, these are two small tables and I can reinitialize things easily. However, to get the data in and out of these tables, I decided to use triggers. We had an insert/update trigger that would take OLTP data and move it into the small publisher database on that system. On the other side, the subscriber database had a trigger to move data into the finance system. It worked well, and if we had replication issues, we could keep working, knowing that data would continue to stack up and we didn't need to alter our application.

I'm a fan of each system doing it's own thing, usually independently, and having processes that do one thing. I can stack those up, but I expect and count on failures at some point. Usually these are minimal, but I try to avoid a long set of things that might have cascading failures if one thing ceases working. In this case, even if a trigger failed or replication had issues, I could manually add some data to another table and it would get moved by subsequent processes.

Triggers are incredibly useful in places, but I do warn people to be careful. They always fire, and often we have exceptions we might need to deal with. We also need to be sure we easily handle multiple rows in every transaction. If you can remember that, and write tight, quick, small code, maybe you'll find a helpful use for triggers rather than one that gives you headaches.

Steve Jones from SQLServerCentral.com

Join the debate, and respond to today's editorial on the forums


The Voice of the DBA Podcast

Listen to the MP3 Audio ( 4.8MB) podcast or subscribe to the feed at iTunes and Libsyn. feed

The Voice of the DBA podcast features music by Everyday Jones. No relation, but I stumbled on to them and really like the music.

ADVERTISEMENT
GDPR

How to make your SQL Server development GDPR ready

Redgate’s SQL Data Privacy Suite helps you to build a data catalog of your SQL Server estate, and put in processes to protect and monitor personal information. Find out more about how our tools help with GDPR compliance

SITC

SQL in the City Summits - New York, London & Chicago

This October, Redgate are inviting those interested in learning how their business can benefit from implementing Compliant Database DevOps to attend one of our SQL in the City Summits. If you manage SQL Server databases, or manage a team of people who do so,  Redgate’s SQL in the City Summit is the conference for you. Find out who’s presenting and register for a Summit near you today.
Register now

Featured Contents

 

What is the impact of setting SET ANSI_WARNINGS OFF?

Nakul Vachhrajani from SQLServerCentral.com

Setting ANSI_WARNINGS OFF to avoid NULL value elimination warnings can have an impact on the data quality and system behaviour. More »


 

SQL Prompt Code Analysis: Avoid using the ISNUMERIC Function (E1029)

Avoid using the IsNumeric() function, because it can often lead to data type conversion errors, when importing data. SQL Prompt Code Analysis rules include an Execution rule, E1029, which will alert you to use of this function, in your T-SQL. If you’re working on SQL Server 2012 or later, it’s much better to use the Try_Convert()or Try_Cast() function instead. On earlier SQL Server versions, the only way to avoid it is by using LIKE expressions. More »


 

Displaying and Removing Unprintable Hexadecimal Characters from SQL Server Data

Additional Articles from Database Journal

There are times when you might need to look at your SQL Server data in hexadecimal format. Occasionally some string data will contain unprintable characters, which can cause downstream problems, if not detected and removed. Read on to learn how to display and remove unprintable hexadecimal characters from SQL Server data. More »


 

From the SQLServerCentral Blogs - Power BI Custom Visuals Class (Module 116 – Scatter Chart by Akvelon)

Devin Knight from SQLServerCentral Blogs

In this module you will learn how to use the Scatter Chart by Akvelon. The Scatter Chart by Akvelon has... More »


 

From the SQLServerCentral Blogs - Back up Encryption

SQLEspresso from SQLServerCentral Blogs

Nowadays security breaches happen way to frequently. As DBA’s we should all take extra care with sensitive data and ensure we... More »

Question of the Day

Today's Question (by Steve Jones):

With this table

 CREATE TABLE UserConfig ( UserConfigKey INT IDENTITY(1,1) NOT NULL CONSTRAINT UserConfigPK PRIMARY KEY , UserID INT , IsActive BIT SPARSE , IsSubscriber BIT SPARSE , DefaultQuantity INT SPARSE , Options XML COLUMN_SET FOR ALL_SPARSE_COLUMNS ) GO 

We run this query

 INSERT dbo.UserConfig ( UserID , IsActive , IsSubscriber , DefaultQuantity ) VALUES (8, 1, 1, 5) 

and then this

 SELECT * FROM dbo.UserConfig AS uc WHERE uc.UserConfigKey = 8 ; 

What is returned?

Think you know the answer? Click here, and find out if you are right.


We keep track of your score to give you bragging rights against your peers.
This question is worth 1 point in this category: Column Sets.

We'd love to give you credit for your own question and answer.
To submit a QOTD, simply log in to the Contribution Center.

ADVERTISEMENT

Pro Power BI Desktop

This book shows how to deliver eye-catching Business Intelligence with Microsoft Power BI Desktop. You can now take data from virtually any source and use it to produce stunning dashboards and compelling reports that will seize your audience’s attention. Slice and dice the data with remarkable ease then add metrics and KPIs to project the insights that create your competitive advantage.

Yesterday's Question of the Day

Yesterday's Question (by Naveen PK):

In Power BI, what is the maximum allowed number of nested function levels for DAX Forumulas?

Answer: 64

Explanation:

DAX Formulas can contain up to 64 nested functions. 

Ref: https://docs.microsoft.com/en-us/power-bi/desktop-quickstart-learn-dax-basics 


» Discuss this question and answer on the forums

Database Pros Who Need Your Help

Here's a few of the new posts today on the forums. To see more, visit the forums.

SQL Server 2017 : SQL Server 2017 - Administration

SQL Migration - I have a SQL Cluster with Multiple databases.  some small and large spanning multiple NDF Files. My question is this.  I...


SQL Server 2017 : SQL Server 2017 - Development

Join date ranges with data from 2 tables - Hello: I have 2 tables with data as below: create table #product(product_id int, product_name varchar(50), regular_price money, start_dt datetime) create table #product_promotions(product_id...


SQL Server 2016 : SQL Server 2016 - Administration

CPU time > Elapsed time - Hello, i have a little question. Is it possible that a query has CPU time greater than elapsed time without parallelism? His...

Fast Database Clone - Hi, What is the fastest way to clone a database of 50 GB every day (SQL2014), without any interruption (detach / attache)....

Allowing developers ability to administer SQL Agent jobs in production - Hi all Trying to get an idea of what people are doing out in the industry around SQL job management. I'm...

Hide schema from all users (except people with SA access) - Hi all I need to create a schema to store a set of tables but I don't want anyone (including those...

Linked Server on AG Secondary Replica - Hi, I am using SQL 2016 SP1 and I have a question regarding linked servers with Always On AG's.  I currently...

AlwaysOn Listener registering 2 DNS records - Hello We have a situation where we need to setup AlwaysOn configuration on 2 data centers When I create a Listener providing...


SQL Server 2016 : SQL Server 2016 - Development and T-SQL

Oracle query tuning - I have been asked to tune a query in Oracle. I know about SQL Server estimate execution plan and other...

Syntax Weirdness with FOR SYSTEM_TIME AS OF - I'm basically trying to get Day-On-Day aggregates of some temporal tables I'm working with. Basic task #1 is to get counts...


SQL Server 2014 : Administration - SQL Server 2014

Best Practice Help - Table Structures - Hi there, I am being asked to provide a list of all the reasons that we should create actual normalized...


SQL Server 2014 : Development - SQL Server 2014

Selecting Min of multiple values, including an operation - Hi All, It's been a while, but would like to tap on your expertise. I've been trying to figure out the below query,...

Blocking in a VL Table - Hi Experts, I have a table with more than 4 million records , I am updating values older than 2018 ,same...


SQL Server 2012 : SQL 2012 - General

Delete statement hangs - Hi all, Vendor gave me a statement to run to delete records from tables. The last output of the statement was: (20000 row(s)...

How SQL Server queries work so fast (when server is idle), when there are no indexes at all on large table ? - Experts, This is AG Readable Secondary Server. We have a table with close to 200 millions of data. Every second one records...


SQL Server 2012 : SQL Server 2012 - T-SQL

Delete Old Tables - dear Friends, Kindly help me, I want to make a syntax that compares if the number of rows in table A...

t-sql 2012 with parameter with multiple values -


SQL Server 2008 : SQL Server 2008 - General

How do I write a record for each day in a date range??? - Hi To make it simple I  have a @StartDate and @EndDate I choose students with an admit date in that range from the...


Cloud Computing : SQL Azure - Development

Ideas for setting Azure SQLmanaged instance for transaction and reporting - Hi, we plan to migrate several database application to Azure managed instances. Users will be using it for transaction and...


Career : Presentations and Speaking

Potential presentation idea: Intro to data warehousing - Hi folks... I'm contemplating what to do for new presentation topics, and am thinking about doing an intro to data warehousing. ...

This email has been sent to newsletter@newslettercollector.com. To be removed from this list, please click here.
If you have any problems leaving the list, please contact the webmaster@sqlservercentral.com.
This newsletter was sent to you because you signed up at SQLServerCentral.com.
Feel free to forward this to any colleagues that you think might be interested.
If you have received this email from a colleague, you can register to receive it here.
This transmission is ©2018 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved.
Contact: webmaster@sqlservercentral.com