Problems displaying this newsletter? View online.
SQL Server Central
Featured Contents
Question of the Day
Redgate SQL Provision
The Voice of the DBA
 

Are Synonyms Useful?

Lately I've run into a few instances of synonyms in different situations. There have been more than a few questions lately about accessing code from different databases and the hassles this creates over time. Often the answer is to migrate to synonyms, which can decouple some of your code. Many experts seem to prefer this solution, though I've seen a few people push back as this being a complex or problematic solution.

Today, I'm asking how you feel about synonyms? If you have a reason to be pro or con, then perhaps you can leave a comment, or write an article if you've solved a problem with synonyms.

The other place I've seen this come up is with customers for Redgate that have multiple databases that are trying to automate their database DevOps process. Performing a validation of your code in a build is complex when there are dependencies on other databases. This can be a complex topic, and Kendra discusses this in our DevOps Advocate channel. Again, this is a way of avoiding some technical debt if you implement synonyms in your code. I think as we move to containerized database platforms, this will become even more important.

The last place I've run into synonyms is where a few users have tried to write a stored procedure that exists in one database, but runs in the context of whatever database it's called from. That doesn't work, though the BOL documentation is rather sparse on the stored proc and function use of synonyms. I wonder, do some of you use synonyms for those programmable objects? It's certainly better than writing three part naming, but likely not habit you have.

If you are using any sort of synonym in your work, and love or hate them, let us know why. This is (I think) and under-used feature of SQL Server, and one that more people should be aware of as an option in their daily work.

Steve Jones - SSC Editor

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

 
 Featured Contents

Keeping tables online during loading with schema swapping using SSIS

shubhankarthatte from SQLServerCentral.com

In this article, we discuss how schema swapping method can be used to keep tables online during the load process.

Practical steps for end-to-end data protection

Additional Articles from Redgate

If you plan to make production data available for development and test purposes, you'll need to understand which columns contain personal or sensitive data, create a data catalog to record those decisions, devise and implement a data masking, and then provision the sanitized database copies. Richard Macaskill show how to automate as much of this process as possible.

Help! SQL Server 2008 is Still Here!

Additional Articles from Brent Ozar Unlimited Blog

Your company is ignoring the news: SQL Server 2008 and 2008R2 are officially out of support as of today, but nothing’s changing at your company. You still have SQL Server 2008 in production, and you’re a little nervous. How should you approach the conversations with management? Brent Ozar will help: he;s been there too.

From the SQL Server Central Blogs - Refreshing dependent views after a DDL change

epivaral from SQL Guatemala

When you are in charge of databases with tons of objects, making a small change over an object can be difficult to replicate if you have a lot of...

From the SQL Server Central Blogs - Implement DevOps One Step At a Time

Grant Fritchey from The Scary DBA

In preparation for my upcoming DevOps training days (see the bottom of this post for details) and for some articles I’m working on, I’ve been building all new automation...

 

 Question of the Day

Today's question (by Owen White):

 

SQL Update Statement Awareness

I am tasked with updating some values in one of my data fields.  I find that there are three unique values in the table: 1, 2, and 3.  I only want to update the values of 1 and 2 to the values of 10 and 20 respectively.  I want to use the least amount of code so I use the following CASE statement to update the values:
UPDATE my_table SET my_field = CASE WHEN 1 THEN 10 WHEN 2 THEN 20 END;
If I run the following SQL statement, what will the list of unique values in the output show?
SELECT DISTINCT my_field FROM my_table;

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

 

 

 Yesterday's Question of the Day (by Evgeny Garaev)

Restore databases on SQL Server 2017

You have restored a database from a full backup on a SQL Server 2017 instance with NORECOVERY option. Now you need to apply a differential backup. Which T-SQL command would you use?

Answer: RESTORE DATABASE

Explanation: There is no RESTORE DIFF command, you should use RESTORE DATABASE Ref: Restoring Differential Backups - https://docs.microsoft.com/en-us/sql/t-sql/statements/restore-statements-transact-sql?view=sql-server-2017#restoring_full_n_differential_db_backups

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 - Administration
TLS 1.2 and Database mail - Hi, We use office 365, and just recently received an email from them saying we had a client using TLS 1.0.  I tracked this down to database mail.  I'm an accidental DBA (more a developer, but now a jack-of-all-trades IT), so don't know about security at all. We have MSSQL 2017 on Server 2016.  One […]
SQL Server 2017 - Development
Group and total by column Name - Guys, How do i group the below by type and date so i have a total for each day for each person by each type. So the desired results should look like: INTO #SampleData2 FROM ( VALUES ('2019-01-01', 'Dave', 'Break', 797), ('2019-01-01', 'Dave', 'Break', 746), ('2019-01-01', 'Dave', 'Break', 511), ('2019-01-01', 'Bethan', 'Break', 631), ('2019-01-01', 'Bethan', […]
What is wrong with my code? - Here is my code: CREATE TABLE ProjectCodes ( ProjectID varchar(22), ProjectName varchar(25), Level char(1), [Project Classification] varchar(14), [Project Type] varchar(11), Billable char(1), DEFAULT 'Y', [Allow Charging] char(1), DEFAULT 'Y', Active char(1), DEFAULT 'Y', [Contract No] char(17), [Task Order No] char(17), CONSTRAINT PK_ProjectCodes_ProjectID PRIMARY KEY CLUSTERED (ProjectID ASC) )   The error message is: Msg 142, […]
SQL Server 2016 - Administration
tempdb space reduction - How  can  we minimize the space utilization  of tempdb when we ran the dbcc integrity/check db  jobs ? we are geeting space issues every week when these jobs are running in weekends. if we choose sort in tempdb =off will it save the disk space  where tempdb resides?
-ExcludeJob with list dbatools - Hello everyone , I would like to transfer job sql lists through dbatools through the Copy-DbaAgentJob command only I want to exclude a list of jobs the lists is a long thank you for your help $Source = 'production\REF ' $Destination = 'localhost' $SharedPath = '\\production\migration' Copy-DbaDatabase -Source $Source -Destination $Destination -Database exploit -BackupRestore -SharedPath […]
How to send queued emails - After an upgrade,   sql server stopped sending emails.   Problem is not solved but during the breakdown some emails were not sent. I can see them with this query: SELECT * FROM msdb.dbo.sysmail_unsentitems; The status is: unsent Is there a way to sent them now that the problem is fixed? thanks
SQL Server 2016 - Development and T-SQL
Long name in TSQL is creating errors - Hello, This will be a simple problem to solve for many of you! I am sure of it I have a script created in SQL agent and when I run it with a simple path it works but not with the long name: SET @path = 'C:\SQLBackup\' SET @path = 'C:\Users\Administrator\OneDrive - My  Company […]
DATEADD(DAY, -30, GETDATE()) - Dear Everyone I wanted to know the statement below will it delete everything in the last 30 days or anything before the last 30 days? DELETE FROM tb_LogIP WHERE MsgLogID IN (SELECT MsgLogID FROM tb_LogGeneral WITH (NOLOCK) WHERE CLF_LogReceivedTime < DATEADD(DAY, -30, GETDATE())) I think this query will delete the most recent data in the […]
Administration - SQL Server 2014
Adding server to Alwayson - Hello Experts, For the first time i got a oppurtunity to work on Alwayson setup at configuration level.Till now already its configured and was maintaining and monitoring the Always on dbs. I am exited to perform below task. As it is a production servers with more than 2TB size i am seeking help from you […]
Development - SQL Server 2014
Left join not pulling all from left table - T has 57,000 distinct rows Z has over a million.  I did row over partition on the key field (Z.zpsh) When i run the following SQL, I only get 47,000 rows back. Shouldn't I get 57,000?   thanks   select * from #temp1 T left join #temp2 Z on T.entry = Z.zpsh where z.rownumber = 1
SQL 2012 - General
Upgrading tables without downtime - Hi, We are in the process of a larger upgrade of an existing database. Basically we are normalizing some of the tables which means we need to copy data from old table(s) to new table(s). The data migration is planned to be done from within an external application that reads from the old tables and […]
SQL Server 2008 - General
how to get 0 if records have empty or null values when column datatype is numeri - Hi I have one doubt in sql server how to get 0 when records have empty or null values when column datatype is numeric in sql server else get max(id) values in sql server Table : empid CREATE TABLE [dbo].[empid]( [id] [numeric](11, 0) NULL ) ON [PRIMARY] GO INSERT [dbo].[empid] ([id]) VALUES (NULL) GO INSERT […]
Reporting Services
Bulk Export of History Reports - We are shutting down a SQL Server and would like to know if there is any way to export the History Reports from Report Manager so they can be saved as either Excel, CSV or pdfs? Any suggestions? The data is being moved to new server however the reports on that new server are different […]
Integration Services
ForEach Loop shows Success before Completing all loops - I have an SSIS package I set up years ago and it always ran fine until recently.   There is a ForEach Loop Container.  Each loop runs a stored procedure (the stored procedure creates synonyms to point to a database), then loads a table from the data in that database.  I have a lot of these […]
How to run package (catalog) from PowerShell with Environment variable in DTExec - Hello Everyone, I am new to PowerShell. I don't even know the basics. I have used the below script and able to run the package successfully. But the problem with this script is it just triggering the package and returning the execution id. Not sure whether the package got succeeded or not. https://docs.microsoft.com/en-us/sql/integration-services/ssis-quickstart-run-powershell?view=sql-server-2017 Later I […]
 

 

RSS FeedTwitter

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

 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -