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

Your Biggest Data Model Complaints

I've been working with databases for a long time and there are no shortage of things I've seen other people do that I don't like. Sometimes I shake my head a little. Sometimes I might groan inwardly (hopefully not aloud), and sometimes I might make an effort to convince someone else to do something differently.

Sometimes I'm really annoyed (or angry) and don't even know what to do.

I know that most people are trying to just get work done. They might rush through something and not do a good job, perhaps because of oversight, or perhaps they are naïve about the effects of their work. Maybe they have ingrained habits and are unwilling to change. Maybe there's another reason (let me know if there is one).

However, no matter the reason, it can be very frustrating to work on poor database designs. There might be other things that bother you, but today I'm focused on the data model. Do you see poor naming of objects? Are there problems with the way they structure their entities? A lack of indexes?

What are your biggest complaints about the structures in your databases?

While I am looking forward to your stories, I want you to be professional. We've all made mistakes, and there is likely some (most?) code we've written that we wish we could redo. Don't embarrass anyone or any organization, but let us know which types of problems or anti-patterns are your biggest complaints. Bonus points if you can do it in a humorous story.

Steve Jones - SSC Editor

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

 
  Featured Contents
SQLServerCentral Article

How to Download and Restore AdventureWorks 2022 Database

Noman072 from SQLServerCentral

Learn how to download and restore the AdventureWorks 2022 database in SQL Server with this step-by-step guide.

External Article

SQL Server Backup or Restore using Network Share with SSMS

Additional Articles from MSSQLTips.com

In this article, we look at how to create a SQL backup to network share or restore a backup from a network share.

Blog Post

From the SQL Server Central Blogs - T-SQL Tuesday #183 Roundup

Steve Jones - SSC Editor from The Voice of the DBA

I hosted this month’s T-SQL Tuesday party with my invitation asking about tracking permissions. I didn’t get my own post completed in time, but I’ll add it in the...

Blog Post

From the SQL Server Central Blogs - Top 10 Careers in Data

Kevin3NF from Dallas DBAs

Would you re-order these? Machine Learning Engineer $$$$$ Develop and deploy AI models Optimize machine learning algorithms for efficiency Work with big data frameworks to process large datasets Data...

Learn Microsoft Fabric: A practical guide to performing data analytics in the era of artificial intelligence

Site Owners from SQLServerCentral

A step-by-step guide to harness the power of Microsoft Fabric in developing data analytics solutions for various use cases

 

  Question of the Day

Today's question (by Alessandro Mortola):

 

Rows estimation with OPENJSON

Consider the following script for a Sql Server database with Compatibility Level at least 130 (Sql Server 2016):
create table tjson ( id int primary key, j1 varchar(max), j2 varchar(max), j3 varchar(max)); insert into tjson (id, j1, j2, j3) values (1, '[{"c11":"value11A", "c12":"value12A"},{"c11":"value11B", "c12":"value12B"}]', '[{"c21":"value21A", "c22":"value22A"},{"c21":"value21B", "c22":"value22B"}]', '[{"c31":"value31A", "c32":"value32A"},{"c31":"value31B", "c32":"value32B"}]');
How many rows does the Query Optimizer estimate for the following query?
select id, c1.c11, c2.c21, c2.c22, c3.c31, c3.c32 from tjson cross apply openjson(j1) with( c11 varchar(50) '$.c11', c12 varchar(50) '$.c12') c1 cross apply openjson(j2) with( c21 varchar(50) '$.c21', c22 varchar(50) '$.c22') c2 cross apply openjson(j3) with( c31 varchar(50) '$.c31', c32 varchar(50) '$.c32') c3;
 

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)

The Rank Window II

I have this table and data:

CREATE TABLE [dbo].[SalesTracking] ( [SalesDate] [datetime] NULL, [SalesPersonID] [int] NULL, [CustomerID] [int] NOT NULL, [PONumber] [varchar] (80) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [paid] [bit] NULL ) ON [PRIMARY] GO CREATE CLUSTERED INDEX [SalesTrackingCDX] ON [dbo].[SalesTracking] ([SalesDate]) ON [PRIMARY] GO INSERT dbo.SalesTracking (SalesDate, SalesPersonID, CustomerID, PONumber, paid, total) VALUES ('2024-03-15 10:45:55.067', 1, 1,'PO965' ,1, 100), ('2023-09-24 10:45:55.067', 1, 2,'PO627' ,1, 200), ('2022-07-02 10:45:55.067', 1, 3,'PO6' ,1, 300), ('2022-11-03 10:45:55.067', 1, 4,'PO283' ,1, 400), ('2022-11-26 10:45:55.067', 1, 5,'PO735' ,1, 500), ('2023-04-28 10:45:55.067', 1, 6,'PO407' ,1, 600), ('2022-09-09 10:45:55.067', 1, 7,'PO484' ,1, 700), ('2024-03-13 10:45:55.067', 1, 8,'PO344' ,1, 700), ('2024-04-24 10:45:55.067', 1, 9,'PO254' ,1, 800), ('2022-06-19 10:45:55.067', 1, 10,'PO344',1, 800) GO

When I run this query, how many unique values are returned for the SaleRank column?

SELECT st.SalesDate , st.SalesPersonID , st.total , DENSE_RANK () OVER (PARTITION BY st.SalesPersonID ORDER BY st.total desc) AS SaleRank FROM dbo.SalesTracking AS st; 

Answer: 8

Explanation: As with a previous question, this has 8 unique values. They are: 1, 2, 3, 4, 5, 6, 7, 8. The 1 and 2 values are duplicated. Ref: DENSE_RANK - https://learn.microsoft.com/en-us/sql/t-sql/functions/dense-rank-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 - Development
Fuzzy logic between two columns - Hello, I have tried various methods to accomplish this using functions like PATINDEX, DIFFERENCE, and the Levenshtein Distance function, but I haven't been successful. I have two columns of type VARCHAR, and I need to determine if a specific word exists in both columns. For example, in the rows below, the string "603260" matches. The input do […]
SQL Server 2019 - Administration
Sync SQL Server and Kafka in real time - Hello, Let say, my .NET API has been inserted successfully into SQL Server Database. It is possible, this data also inserted in Kafka in real time ? This transaction should be done in .NET API or should be done in SQL Server by configuration ? Please help me to understand more and better
T-SQL - Restore Database - Hey, I've previously used this or something like this: RESTORE DATABASE [DBNAME] FROM DISK = N'X:\Path\To\File\.bak' WITH FILE = 1 ,MOVE N'DBNAME' TO N'U:\Path\To\File\DBNAME.mdf' ,MOVE N'DBNAME_log' TO N'L:\Path\To\File\DBNAME_log.ldf' ,NOUNLOAD ,STATS = 5 But I've now encountered a DB with 27 data files (+1 log file). Is there a way to relocate the files on the […]
SQL Server 2019 - Development
Is anybody using Windows 2022 clustered SQL Failover cluster ( 2019 CU30 ) - How do you configure the cluster resources to be able to use Distributed Transactions ? Documentation ( 01/15/2014 ) is unclear and doesn't show a working solution. Begin Distributed Transaction fails ! Msg 8501, Level 16, State 3, Line 12 MSDTC on server 'VirtSQLServer\MyInstanceName' is unavailable.
Query Help to show record in single row - Hi All, need help with an SQL query. We have an existing table that's already formatted this way, and I am having trouble extracting the data in single record. Current Output: EXPECTED OUTPUT: The EndDate and EndTime I want it displayed in the same row where BName like '% Start' I tried to do this through […]
MSDTC not available on Windows 2022 clustered SQL 2019 CU30 - I connect to this clustered instance and run : begin distributed transaction Msg 8501, Level 16, State 3, Line 2 MSDTC on server 'ClusteredTargetServer\Instance' is unavailable. I have configured the clustered msdtc of this instance:   Test-Dtc -LocalComputerName $env:COMPUTERNAME -Verbose VERBOSE: ": Firewall rule for "RPC Endpoint Mapper" is enabled." VERBOSE: ": Firewall rule for […]
General
What Version MS SQL Server and SSMS Am I Running? and Git with MSSSQL - Information I've run across searching other topics led me to want to find out what version I'm running.  This was motivated by trying to learn if git/github would be good tools for version control on my database which led to the question of version. I found an article that told me to run SELECT @@version.  […]
Several Questions: Relationships and SSMS and Data Diagrams - I'm struggling setting relationships among tables.  I understand the one-to-many, many-to-one, many-to-many, and self-referential concepts.  It's implementing them that I find a bit vexing. I've used queries like this successfully: ALTER TABLE clan.parents ADD CONSTRAINT FK_FatherID_PeopleID FOREIGN KEY (parentsFatherId) REFERENCES clan.people (peopleID); How can I view relationships after I've completed queries like the above?  After […]
Time Outs Here - Several times in the last couple of days I've had submissions time out with a 504 error returned. After multiple submissions, I've eventually got my posts through.  I've learned to type the posts in a notepad from which they can be copied instead of having to retype them.
Data Diagrams: Data Types with Column Names - In the ss below I highlighted several rows in each block showing tables in diagram view to show where I think data type assignments could be displayed.  Is there a reason that SSMS doesn't display data types assigned to column names?  I've searched to see if there is a way to add them but came […]
Data Diagrams: Data Types with Column Names - In the ss below I highlighted several rows in each block showing tables in diagram view to show where I think data type assignments could be displayed.  Is there a reason that SSMS doesn't display data types assigned to column names?  I've searched to see if there is a way to add them but came […]
Data Diagrams: Data Types with Column Names - While this might not be an issue for those more knowledgeable and experienced than I am, I've come to wonder why the blocks that represent tables and contain the names of columns in those tables don't also include assigned data types in parentheses or brackets following column labels.  I highlighted the first 4 columns in […]
SQL Server 2022 - Administration
Have 3 SQL Server Database in different 3 Windows Server Machine - Hello, I am newbies in SQL Server Administration My planning is to setup - 3 SQL Server Database in Server A, Server B & Server C. All these 3 SQL Server Database have identical schema and the data should be identical. Other word, SQL Server Services without shared storage. All the database files are on […]
SQL Server 2022 - Development
Convert stored procedure into a Table-valued function - <sorry, duplicate> =(  
Convert stored procedure into a Table-valued function - Feel like I'm missing something blatantly obvious. I am trying to return the cost of each of a set of ingredients as of a specific date (so I can sum them in the next step, for example). It works fine if I create it as a stored procedure, but when I try to create a […]
 

 

RSS FeedTwitter

This email has been sent to [email protected]. To be removed from this list, please click here. If you have any problems leaving the list, please contact the [email protected]. 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.
[email protected]

 

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