SQLServerCentral - www.sqlservercentral.com

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

Featured Contents

The Voice of the DBA

Rewrite Your Code Tomorrow

One of the things that many developers learn over time is that they write better code with practice. In fact, some of the time a developer will find that if they write a bit of code to solve a problem, they'll come up with a better solution a day or two later, as they've had a chance to think about the problem. Even while moving on to other code, their brain will continue to examine the previous solution, inherently knowing the approach wasn't the best.

Many of us see this with our code over time. If we look back at something we wrote a year or two ago, many of us cringe. At least, most of us cringe, especially if we constantly look to improve our skills. We see that old code as poorly written, in a way that we might never want to repeat in our career. I think that's a good sign that we are moving forward and learning better patterns over time. If you don't view any of your old code as poorly written, I'd stop and get a second opinion. You certainly might have written some great routines that stand the test of time, but more often than not, I find places where I'd improve code. Having someone else review my work might help me build better skills.

One of the things I heard recommended recently was that developers solve some problem, commit the code in their VCS, and then tomorrow, redo the work. Start the day by deleting that section of code (that proc, method, class, etc.). Then move forward and rewrite the solution, not trying to remember what was there, but by resolving the issue. Plenty of application developers find they'll write similar logic, but better structured code. Even if you don't believe this, conduct an experiment on a small section of your code.

I don't know if we'd come up with the same results with T-SQL as many of us tend to solve the problems the same way across a short period of time. However, maybe you'd like to post a mock up of your challenge and solution, and ask for some opinions. We have great forums at SQLServerCentral and some really sharp SQL developers. You might get the validation that you built a great solution, or maybe you'd get some ideas on how to improve both your code and your skills.

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 ( 3.1MB) 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
Redgate Hub

Stop your database being a bottleneck

The new Redgate Hub is the shortcut to the latest insights into database development. Constantly updated with invaluable content, it’s the one resource you need to solve problems, share ideas, discover new tool features, and expand your database skills. Discover the Redgate Hub

SQL Clone

SQL Clone: Now supporting databases up to 64TB

Create copies of production databases and SQL backups in seconds and save up to 99% of disk space using SQL Clone. Redgate’s new tool removes much of the time and resource needed to create and manage database copies, allowing teams to work on local environments to develop, test and diagnose issues faster. Try it free

Featured Contents

 

Stairway to U-SQL Level 18: Populating a Data Lake with PowerShell

Mike McQuillan from SQLServerCentral.com

Learn how PowerShell can be used to manage files and folders in your Data Lake. More »


 

Free eBook: SQL Server Transaction Log Management

Press Release from Redgate

When a SQL Server database is operating smoothly and performing well, there is no need to be particularly aware of the transaction log, beyond ensuring that every database has an appropriate backup regime and restore plan in place. When things go wrong, however, a DBA's reputation depends on a deeper understanding of the transaction log, both what it does, and how it works. More »


 

Understanding Azure Data Factory – A Cloud Based Integration Service

Additional Articles from Database Journal

Azure Data Factory is a cloud based data integration service. This helps you to define, schedule and manage data pipelines to transfer and transform the data from disparate on premise and cloud data sources. Read on to learn more. More »


 

Database provisioning from backups using SQL Clone

This article offers a brief, step-by-step guide to provisioning databases from a backup using SQL Clone. More »


 

From the SQLServerCentral Blogs - Policy Based Management and Powershell

iainthepitman from SQLServerCentral Blogs

Introduction Policy Based Management (PBM) can be used to inform DBAs when an incorrect setting is being used on a SQL... More »


 

From the SQLServerCentral Blogs - DELETE data on SQL Server HEAP table – Did you know…

Cláudio Silva from SQLServerCentral Blogs

Before I complete my question let me provide context. I’ve received an alert saying that a specific database could not allocate... More »

Question of the Day

Today's Question (by Steve Jones):

I want to store Marvel data. My goal is to store a character name, a movie title, and a year of release. Which construct in R creates a data frame?

I have already set some variables:

> characters <- c('Iron Man', 'Iron Man', 'Spider-Man', 'Thor')
> movies <- c('Iron Man', 'The Avengers', 'Spider-Man', 'Thor')
> releaseyear <- c(2008, 2010, 2002, 2011)
 

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: R Language.

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

SQL Server T-SQL Recipes

SQL Server T-SQL Recipes is an example-based guide to the Transact-SQL language that is at the core of SQL Server. This edition has been lightly updated for SQL Server 2014 and provides ready-to-implement solutions to common programming and database administration tasks. Learn to create databases, create in-memory tables and stored procedures, insert and update data, generate reports, secure your data, and more. Get your copy from Amazon today.

Yesterday's Question of the Day

Yesterday's Question (by Steve Jones):

What does this code do?

DECLARE @d1 DATETIME = '20170101 09:42'
DECLARE @d2 DATETIME = '20170301 22:22'

SELECT DATEADD(DAY, DATEDIFF(DAY, @d2, @d1), @d2)

Answer: Returns the date from @d1 and the time from @d2

Explanation:

This codce will find the difference between the dates, which is -59 days (DATEDIFF(DAY, @d2, @d1)). This is added to the @d2, which brings the date of @d2 back to @d1, with the same time.

Ref: Datediff - click here

Dateadd - click here


» 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 2016 : SQL Server 2016 - Administration

Dynamically create table with full structure - Hello All, I have a large table "LARGETable" and till now my developers created a job that run every 2 minutes...


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

Merge to upsert when target table might have legitimate duplicate tuples - Am I correct in saying that it's no use to try to use the Merge statement for an Upsert (meaning,...

Having clause - Hi, Need to add having clause as tansaction_count>1 after group by clause in below query . Transaction_count is exist in table dbo.TABLEW Any...

select count of rows based on condition - Hi, Need to select count of rows based on codition from a table. Tried with this query , but no luck. select CASE WHEN...

Importing a DAT file - Hi, I have to import (ETL) a DAT file into one of our SQL databases but I'm having trouble getting the...

Running balance calculation - Hi all, I'm interested in creating a query that would calculate the balance of customers with an account open on the...

Current month to yesterday's date - Hi Guys, I am using the following code to pull back data based on the start of the month and yesterdays...

Strange COALESCE issue - All, I think it's correct to provide a table structure for any questions so I'll include that first: /****** Object: Table...

Object Dependency - Hi All, I am using SQL below to get the object dependency. select Obj.name,dep.referenced_entity_name from sys.sql_modules as Module,sys.objects AS Obj ,sys.sql_expression_dependencies as...

One of my Passed Exam of MCSA shows in MCSE, Why? - Hello, I passed MCSA today. When I see the requirement for MCSE, among the list, it shows an exam (70-762) to get...


SQL Server 2014 : Administration - SQL Server 2014

Linked servers cannot be used under impersonation without a mapping for the impersonated login - Hi all I have a stored procedure that selects data from two instances. If I run the stored procedure it works...


SQL Server 2014 : Development - SQL Server 2014

T-SQL - Script gone... bad? - I hope you can help me. I have been informed that the code I wrote does not have mutually exclusive...

Since looping is bad, how should I accomplish what I am trying to do? -

Code-first vs database-first, any new developments? - I'm discussing this topic with a developer, and I'm also performing due diligence and looking for other opinions on the...

TSQL Query help plz.. - Hi All, Need tsql help please. Below is the sample schema/tables and description is written at the end(my requirement). use master go...


SQL Server 2012 : SQL 2012 - General

Most efficient join - I am joining to two very large tables and trying to ensure I am doing it the most efficient method possible. The 2nd...


SQL Server 2012 : SQL Server 2012 - T-SQL

Return parents for children with certain condition - Ok, so here is my sample data I am testing against... declare @t table (   Id  int ,   Section int,   DateOccured DATE,     Missed int ); insert into...


Data Warehousing : Integration Services

Data Flow Task Error: The version of ODBC Source is not compatible with this version of the DataFlow - So, that is the error I am getting when I attempt to execute my extremely simple SSIS package.  How simple?...


SQL Server 2005 : SQL Server 2005 General Discussion

Strange Execution Plan !!!!!!!!!!!! - --------- table definition----------------------------- acct_id int acct_stub uniqueidentifier acct_num char(100 acct_status_id smallint acct_name char(100) acct_company char(100) acct_url char(100) acct_activate_date datetime acct_inactivate_date datetime reference_id ch


SQL Server 2005 : T-SQL (SS2K5)

Inserting rows into remote server with identity column - I am having troubles trying to copy some rows from a table on my local computer to a table on...

This email has been sent to {user_email}. 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 ©2017 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved.
Contact: webmaster@sqlservercentral.com