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

The Number that shouldn't be a number

This editorial was originally published on Feb 2, 2015. It is being republished as Steve is on holiday.

Sometimes I get really confused by the data types people choose for their tables. Take this example from one of the popular SQL forums:

Why, why, why did they choose an integer for the telephone number? Sure, it's probably ultimately numeric, but does that really mean it should be an integer? Is it likely that the phone number needs to be added to something? How often do need to find the square root of a phone number? Or invert one? Is one ever likely to need to do something like this:

log2(sin(TelephoneNumber2)/pi)?

If so, I'd certainly love to see the reason.

Telephone numbers, despite being composed of numeric digits, are not numbers. They are strings. They are not likely to be manipulated mathematically, and leading zeros are meaningful.

I've seen similar strange choices with postal codes, which in South Africa are four digits long, and where leading zeros are, again, meaningful. Cape Town's postal code is 0001, not 1. Storing a postcode in a SMALLINT is possible, but not necessarily a good option.

My general rule is that if the column isn't going to be mathematically manipulated, it's probably a string, not a number.

I remember the pain of working with a system where a developer had chosen the TIME data type to store the number of hours worked in a day. Anyone want to figure out how you add two TIME columns together? I'll wait…

I've also seen BIGINT used for the number of open orders that a customer has (optimistic), INT for dates, FLOAT for dates, NVARCHAR(MAX) for a true/false column. The list is endless.

Here is my call to arms: if you're designing a table, think about the domains for each of the attributes, think about what the maximum and minimum values can be, and then think very carefully about the best data type for that attribute. And don't get fancy. For financial data, while it might be possible to convert the value into hex and store it in a Binary column, storing it in a Numeric is probably easier.

Finally, what are the weirdest data type choices you've seen?

Gail Shaw (Guest Editor).

Gail Shaw

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

 
 Featured Contents
SQLServerCentral Article

Streaming Event Data through RabbitMQ to a Microsoft Fabric Eventstream

Koen Verbeeck from SQLServerCentral

In this article, you will learn how to send messages through a RabbitMQ queue and deliver those to a Microsoft Fabric Eventstream.

External Article

Add Indexes to Improve SQL DELETE Performance

Additional Articles from MSSQLTips.com

This article examines whether creating indexes can help when deleting data from a SQL Server table.

External Article

Four steps towards tackling the complexity of managing multiple database platforms

Additional Articles from Redgate

79% of us are now using two of more database platforms - fantastic for leveraging a range of benefits, but not so great when it comes to levels of complexity. Looking for ways to overcome this? Here are four steps to take towards multi-database simplicity.

Blog Post

From the SQL Server Central Blogs - Data Technology Learning Resources

Grant Fritchey from The Scary DBA

Hey all! Quick one here. Tracy Boggiano, awesome person that she is, has put together an interesting collection of data over on GitHub. It’s titled DBA Resources, but it...

Blog Post

From the SQL Server Central Blogs - Take the SQL Saturday Topic Survey

Steve Jones - SSC Editor from The Voice of the DBA

What topics do you want to see presented at a future SQL Saturday (or other event)? Steve Rezhener has built a survey that you can take. Take the survey...

SQL Server 2022 Revealed

SQL Server 2022 Revealed: A Hybrid Data Platform Powered by Security, Performance, and Availability

Additional Articles from SQLServerCentral

Know how to use the new capabilities and cloud integrations in SQL Server 2022. This book covers the many innovative integrations with the Azure Cloud that make SQL Server 2022 the most cloud-connected edition ever. The book covers cutting-edge features such as the blockchain-based Ledger for creating a tamper-evident record of changes to data over time that you can rely on to be correct and reliable.

 

 Question of the Day

Today's question (by Steve Jones - SSC Editor):

 

What's Wrong with this Table?

What's wrong with this code and causes an error?
CREATE TABLE Customer
(
    CustomerID INT NULL,
    FirstName NVARCHAR(50) NOT NULL,
    LastName NVARCHAR(50) NULL,
    Email NVARCHAR(100) NOT NULL,
CONSTRAINT CustomerPK PRIMARY KEY (CustomerID, LastName)
);


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

 

 

 Yesterday's Question of the Day (by Steve Jones - SSC Editor)

Reducing Backup and Restore History

How do I easily reduce the old data contained in the backup and restore tables in the msdb database?

Answer: Run sp_delete_backuphistory

Explanation: The sp_delete_backuphistory procedure will remove entries for backups and restores older than the date passed into the procedure. Ref: sp_delete_backuphistory - https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-delete-backuphistory-transact-sql?view=sql-server-ver16

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
side effects of giving permissions to run traces - Hi All, I would like to know the downsides of giving permissions to run traces in lower environments (DEV/QA/UAT). Our DB team has only two members: one supports PST hours, and the other supports IST hours. The PST resource is on leave for a month, so I have to cover both time zones as needed. […]
Select permission denied despite group having db_datareader - I am at a loss and could use a second pair of eyes. We have a Server with database A and database B, a windows security group (MyDom\MyGroupName) which is created with dbo schema as its default in both databases, and a service account in this group. MyDom\MyGroupName has db_datareader in both databases. There are […]
SQL Server 2017 - Development
Split fields sql 2017 - I am trying to split fields in sql 2017.  The column holds the following.  I am pulling the first 50 characters and now I need to split those into 2 fields. This is a test name1                          3006              […]
SQL Server 2016 - Administration
connection does not open from SSMS - Dear Friends, Would be grateful if anybody can advise why one of my servers, doesnt allow a connection anymore from SSMS on my terminal. The IP address is the unchanged. SQL server port was changed I remember, that i am anyways providing in with the IP as IP:portnumber..Thanks in advace.
How to improve index rebuild for very large table. - My online index rebuild job for a 200G table with 40mil rows took me up to 30hrs to complete, this is a once off activity done since we have an allocated downtime for server maintenance. I would want to know, is there any way for me to do it faster? I had an idea of […]
SQL 2012 - General
SQL code needed for the WHERE clause.. - I have a table with data appending on a daily basis. We plan to keep the set of data in this table for one full year and delete everything after August 1st of every year. I am stuck with the query logic to do this.  The situations are like this: If today's date is August […]
SQL Server 2019 - Administration
Database growth report by full back file and send by email in graph and or html - Hello Gurus, How I am in need of all databases growth in 10 instance and send the report by an email. What's the best way to accomplish such task. If anyone has scripts or point me to a website that would be very helpful. thanks in advance.
Backuips are failing - After  CU 27  update in sql 2019  backups are  failing and  all  mainnaytainence  jobs are  also  faling . we did not find  any  error on  sql logs , pls  assist on ho wto resolve this   Message Executed as user: NT Service\SQLSERVERAGENT. Microsoft (R) SQL Server Execute Package Utility Version 15.0.4375.4 for 64-bit Copyright (C) […]
Query Store with AOAG stuck on waiting - Hey Folks, I have a database on SQL 2019 CU24 in an AOAG with 1 primary and 2 secondary.  I have enabled Query Store but it will not open and just shows Waiting on the primary. I have QS setup on standalone SQL 2016 databases and they seem to be working fine. Any help is […]
SQL Server 2019 - Development
Web API Procedure will not run in SQL Server Agent Job - I have a stored procedure that pulls JSON data from a US government web API. The procedure executes fine manually but fails with the error below when executed from a job.  I've checked permissions of the SQL Agent and ensured it has permission to execute sp_OACreate and sp_OAMethod  procdures. Extremely grateful for any help or […]
Logic similar to EXIST to make all values the same if it meets a criteria - Hello everyone, I have a question. Please let me know if someone has any ideas. I need a logic with maybe EXIST(?) to check separately if for one Chain there is a field in REPLENTYPE with a value ‘SINGLE’ – I need all fields for this UPC at a specific Masterchainname to be ‘REPLENISHABLE’ for […]
Reporting Services
SSRS Header not Keeping with report - Hi all, I have an SSRS report issue is when printing to PDF. i have a subreport that works fine, but when there is ONLY enough space for the header, it will stay at the bottom then the rest of the subreport continues on the next page. here is a screenshot of the subreport, mainly […]
SQLServerCentral.com Website Issues
Weird redirect after reporting post - I just tried reporting this post: https://www.sqlservercentral.com/forums/topic/fuhrerschein-umtauschen-49-176-44678273-motorbike-fuhrerschein-2 After clicking the 'Report post' button, I was redirected to this post: https://www.sqlservercentral.com/forums/topic/null If I then return to the original spammy post, there is no indication that the report function worked.
SQL Server 2022 - Administration
SQL Server 2022 Std edition eval version - Hi We are planning to upgrade our SQL Server 2014 Ent edition to 2022 Standard and i want to test Basic Availability Groups future. Is there a free evaluation version for SQL Server 2022 Standard edition? At least i could not find one Thank You
SQL Server 2022 - Development
how to bulk insert a file on a azure sql server managed instance - Don't know if this is the right place for this topic. I have an internal azure sql server managed instance and am trying to read or write a file to the file system. As i understand, there is no file system on a sql server managed instance. Is there a way to add a file […]
 

 

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

 

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