r/SQLServer • • Nov 03 '23

Three months into a banking DBA job, holy hell how much SQL Server is used

59 Upvotes

I'm not complaining at all as it's job security, but 75% of the business users touch SQL server, with a small percentage in Oracle or DB2. I know the back end servers will be different, but I honestly didn't realize how much banks used SQL server.


r/SQLServer • • Dec 10 '20

Brent Ozar's Yearly Salary Survey

59 Upvotes

r/SQLServer • • Nov 09 '19

Here is my typical SSIS design pattern to build a SQL Data Warehouse. What do you do differently?

59 Upvotes

I keep refining the way that I build a SQL DW. I'm going to share, here, what I've settled into. Please feel free to compare and contrast this with what you do.

Random stuff:

  • My SQL DW builds are no longer consumed by users and reports. They are just data staging for SSAS Tabular. (That changes the indexing needs.)

  • Despite the above, I still adhere to a classic DW naming convention. I'll share some of that below.

  • My default handling of slowly changing dimensions (SCD) is Type 1: overwrite.

  • I will offer the option to handle an SCD as Type 2 and at the same time sell them on Type 1 (keep it simple).

  • I work as a contractor, and I have not been an in-house dev for more than 18 years. This effects my commenting, naming, source control habits, and constant desire to keep it simple (as stated above).

  • Sometimes SSIS drives me crazy. That thing when you open a package in VS and it's just a blank page? WTF? (quick fix is to rename the package to see the components in the designer)

  • Despite the idiosyncrasies of VS and SSIS, when I am on a roll, I find some kind of peacefulness about developing ETL solutions in SSIS. Sometimes I can do it in the evening hours and chill out, like it's a fun activity.

  • I no longer use stored procedures. Some of my clients do not want my project code easily modifiable (i.e. ALTER PROCEDURE).

  • As a contractor I almost never have access to cool third-party components. I believe that's often a good thing for projects that are handed off by third parties (me), and often not maintained.

Here is what my packages look like in my latest DW builds -- this is something I continue to tweak. If/when I go to use Database Projects that will mix things up for me. ; - )

000 EXEC Pkgs - New DB, All Objects No Data
001 EXEC Pkgs - Full Stage and Build
002 EXEC Pkgs - Full Stage and Build with Legacy
101 EXEC Pkgs - Create All Tables
111 Create Functions
112 Create Tables - Meta
113 Create Tables - Logging
114 Create Tables - Dimension Staging
115 Create Tables - DIM
116 Create Tables - Fact Staging
117 Create Tables - FACT
201 EXEC Pkgs - Stage All No Legacy
202 EXEC Pkgs - Stage Legacy Only
211 Pre Process Logging
212 Pre Process Drop PK FK Constraints
213 Pre Process Drop Indexes
221 Data Copy - Legacy Data
222 Data Copy - Master Data
223 Data Staging - Dimensions
224 Data Staging - Facts
301 EXEC Pkgs - Build DIMs and FACTs
311 Build DIM
312 Build FACT
313 Build Coverage Tables
314 Post Process Create PK FK Constraints
315 Post Process Logging
316 Post Process Build Indexes
399 Post Process Drop Staging Tables (optional)
999 Useful Scripts

Each of those EXEC Pkg packages are single packages that contain ONLY Execute Package components (with a control flow). There is no ETL logic in them. They are meant for me to use in the debugger. BTW I use all caps on EXEC so it stands out, easily found when I am developing and I want to execute some processes when I am using Visual Studio.

I prefer that my deployments, when called by SQL Agent, *not* call any packages that call other packages because then the SQL Agent history only shows the single package call (success/fail/timing). That makes job setup a big darn hassle to setup in SQL Agent, though. It also means that changing control flow package to package requires modifying the SQL Agent. I'm not sure which is the lessor of the two evils.

It helps me to alphabetize my CREATE TABLE tasks in the designer. I use the standard Execute SQL Components. Manually alphabetizing the components makes them easy to find. If you have 25 create table tasks and you're looking for a particular one to edit, you save a lot of time when they're alphabetized. The way these are used, they don't need to be "strung together" with precedence constraints (on sucess, etc.), so the alpha sorting is doable, but it's a purely manual effort.

Staging:

  • Some people like to have unfiltered data staged (all records for entity), not me.

  • I like the business rule filtering to happen on the extraction for a couple reasons: less wasted capacity; the JOINs in the extraction are already affecting your record count anyway -- may as well filter it; I can check my referential integrity when I go from staged FACT to built FACT by looking for record count dropoff (typically, not always).

  • I try to avoid any need to control flow inside of packages -- no concern for order of operations. Most of my dependencies are handled by the control flow of one package to the next.

  • That is not true for staging processes that are multi-step and use temporary tables for things like cleanup or de-dupe.

  • For those kinds of processes, I put the steps in a sequence container, with control flow inside the container. Then the sequence container sits in the package along with everything else.

  • My final staged tables remain denormalized, ready to pickup the associated foreign key values during next phase -- the build.

  • My staging tables are named the same as the built tables, pre-pended with STAGE_

  • I only use two SQL schemas: the default "dbo" and one called "etl"

  • The etl schema is for everything that is not meant to be consumed. The thought behind this is that it's easy to exclude access to these objects with security referencing the schema.

  • In new projects I no longer use the etl schema, or any schemas at all. This is one of those things that is like a conviction for some. Sorry if I've offended you! Here are databases that, to the best of my knowledge do not even support schemas: MySQL pre 5.7, SQLite, Oracle (if not configured). Schemas also have no place in the semantic layer. Also when writing code with intellisense, if you don't know what schema a table is in you practically don't have intellisense. Intellisense won't complete a partial table name if it's not in the default (dbo) schema unless you typed the schema name.

  • While I'm happily not using schemas, don't confuse my preference with being all willy-nilly with prefixing object names with the object type. I prefix functions, views, stored procedures appropriately with fn, v, sp or the existing standard in place if there is one.

  • Furthermore, a table function that didn't get the prefix "fn" looks like just another table in code. That can be frustrating when you're looking for a non-existent table (among all the real tables).

  • I use Pascal Case for a portion of my table naming, the portion of the table name that is within the business entities such as: Employee, EmployeeTime, Invoice, InvoiceDetail [those are not complete table names]

  • Pascal Case LooksLikeThis, and Camel Case isActuallyLikeThis. Often, people call ThisConvention Camel Case, and I'm OK with that. When someone says Camel Case I just imagine Pascal Case unless the context is C++ (and the writer is well experienced). ;-) ...didn't mean to rant

  • Then I use underscores to describe the type of object in relation to the DW such as: DIM_Employee, FACT_EmployeeTime, and etl.STAGE_DIM_Employee or etl.TEMP_STAGE_DIM_Employee.

  • All my staging tables for dimensions get surrogate primary keys (INT seed by 1). The ID values they get in staging will remain the same in the build.

  • Modern approaches steer people to use GUIDs for record IDs. Unless you NEED the benefits of GUIDs, do not use them here. Indexed INT IDs and table JOINs are much faster with simple integers.

  • I don't use any in-memory temp tables. I also do not drop temp tables. I leave them in case I need to troubleshoot.

  • If I have a multi-step process that involves temp tables, those tables should be named almost identically with the sequence number appended, such as: TEMP_STAGE_DIM_Account_Process1, TEMP_STAGE_DIM_Account_Process2, etc.

Going from Stage to Build:

  • I use the verb "build" to describe the process of loading the final, to-be-consumed FACT or DIM from staging.

  • This is important to stay out of trouble with dependencies: my build queries only reference staging tables. For example, when I build a FACT table it goes like this:

SELECT EE.EmployeeID... etc., etc.,
FROM etl.STAGE_FACT_EmployeeTime as F
JOIN etl.STAGE_Employee as EE on F.EmployeeID = EE.EmployeeID

  • I used to call my time dimension DIM_Time. Now, though, I call it DIM_Calendar unless there is a lot of reporting by time of day. I have a script to build it that I've borrowed from online finds and I have added a little bit to it and tweaked it to my liking. Then in Power BI (or whatever the semantic layer is) that becomes just "Calendar."

  • I like to work without constraints. Primary key (PK) and foreign key (FK) constraints are not part of my CREATE TABLE process. I drop all FK then PK constraints in a package just before I stage everything. This makes it easier for me, in development, to work on a single table, truncating it and not getting blocked by FK constraints.

  • At the end of the build process, I have a package that creates PK and FK constraints.

  • I get it, my way of dropping and adding constraints removes the integrity constraints from the ETL process. I'm OK with that. When I add them on in the end (in deployment), it will throw an error that can be handled, logged, etc.

Cool Stuff I Rarely Use:

  • I created some metadata tables, one for tables and one for columns.

  • They are dynamically generated and update with every build (in case the schema changed).

  • The metadata tables are used as the basis of my logging tables. That makes my logging process dynamic, so I don't have to explicitly log each table.

  • I use logging mostly to get record counts. Each row is a table per run, with current row count and last run row count.

  • That style of logging can help you spot something "bad" that otherwise doesn't throw an error -- like a really big record drop off compared to last run. (or the opposite, a JOIN that multiplies records)

  • I have intended log columns containing NULLs and maybe even store a metabase where I can flag those columns where NULLs are allowed and compare. I haven't done this yet. I have the groundwork for this in place.

  • I have started to make a metabase on some transactional data, and then create a system to mark tables and columns that need to be extracted, the extracted names, transformation rules, etc. -- sort of like a dynamic extraction capability. No one has asked for this, but it's something I'd like to finish one day.

Facts and Measures:

  • I only create base facts in the SQL DW. Things that have to come from transactional data.

  • I do not do currency exchange in SQL. All amounts are stored in the native currency (of the transaction) along with the currency (USD, EU, etc.).

  • I never aggregate data in SQL (this should be obvious). That happens in the semantic layer when you define your measures.

  • In Power BI or the semantic layer, hide the base fact (such as InvoiceLineAmount), and create the base measure in DAX (or language of choice), such as Revenue = SUM(InvoiceLineAmount).

  • IMPORTANT: setup base measures for all measure types (like "Revenue") and then define the derived measures off of the base measures, such as Revenue YTD, Revenue MTD, etc.

This was pretty stream of consciousness. I'm sure there were some significant details that I left out. Sorry for that. If you have any good ideas to share, let me know.

EPILOGUE
(edit/added on 2019-11-10)

I often think about the experience I gained from the person who pretty much taught me how to build a dimensional model SQL DW. He gave me a lot of what seemed to be unhelpful (at the time) guidance, and he backed it up by saying, "There is no right or wrong way to do that, it all depends upon the data and the way that you like to work." He was right.

In that situation (again, I was not an in-house dev), the company was an international, name-brand consulting firm. The multiple DWs that we developed were all offline from the clients' locations. We would get a bunch of extracts monthly, pull them in a landing area, and so on... There were three of us that supported the design, build, and on-going refreshes of about 20 data warehouses. There was a standard, re-used SSAS Solution that the SQL DW would interface with (and a visualization layer, I forget which one). We would transfer the completed/refreshed SSAS databases to the clients' sites every month.

Needing so many adaptable standards toward DW creation is a growing trend -- our customers increasingly demand more analytics-ready data, and they usually want it more rapidly than we can deliver. I always feel like I'm under that sort of pressure. It's uncomfortable on a daily basis, but ultimately, it's a good thing. I would bet many of you who are reading this thread can relate.


r/SQLServer • • May 31 '22

Holy sort batman

Post image
58 Upvotes

r/SQLServer • • Sep 18 '20

Question Is this cool?

Post image
58 Upvotes

r/SQLServer • • Mar 10 '16

There's your problem.

Thumbnail
imgur.com
58 Upvotes

r/SQLServer • • Oct 11 '22

Community Share Gentle intro to Heaps vs Clustered Tables

Post image
57 Upvotes

r/SQLServer • • Apr 17 '21

Next version of SQL Server will have GREATEST/LEAST functions

Thumbnail
feedback.azure.com
56 Upvotes

r/SQLServer • • Oct 03 '19

Just finished a SQL workshop on migrating to the cloud; here's the training, slides, and PDF for what we learned.

Thumbnail
github.com
56 Upvotes

r/SQLServer • • Dec 11 '17

Passed 70-761!

56 Upvotes

I just thought I'd share briefly how I passed the exam. As a note, the below is how I studied and what I studied, it may or may not be what was on the exam as they change the exams and I cannot discuss what was on the exam directly. I can share how I got to the point to where I felt comfortable taking and then passing the exam however.

For background, I have roughly 7 years of database and IT experience with the last four years being much more intensive in SQL than the first three. The timing for working for a company who would pay for my cert and also having the time and ability to study for the cert finally synced up and I decided to go for it. 70-762 is my next exam. 70-761 was hard but fair, it was both easier and harder than I expected it to be.

Everyone else has said it but I'll say it too. Use your test taking abilities.

If you can go back to a question that is taking you a long time, mark it for review and continue with the test and go back to it at the end. I used every second of the 2 1/2 hours of the exam. I don't know if having more time would have necessarily changed my score, but I feel 30 more min would have made me felt more comfortable and less rushed.

If you can narrow down the answers you have to pick from, do that at the very least even if you are stumped on the question. From the narrowed down answers you can at least guess.

Don't leave any answer blank and try to answer them all.

For study material, I read the entire 70-461 exam prep book, re-read sections in the 70-761 exam prep book. Especially on the XML / JSON / Temporal tables, I had heard you need to focus heavily on this from other forums. One note I've read is that MS likes to really drill you on things new to the cert. So I focused heavily on studying things that were new from 2014 to 2016. I read a large portion and looked at various chapters in the book T-SQL Fundamentals too.

I used additional resources from Cathrine's website and MS SQL Tips. I did the XML stairway series on SQL Central and watched a lot of videos on indices and T-SQL. JSON and Temporal tables was hard to find good resources for. I ended up reading the entirety of the MSDN tech notes on Temporal tables and read a lot and practiced similar to XML with JSON. I had the privledge to try and incorporate full text search at work, so I felt comfortable there and most other features I've used. Anything I haven't used regularly I made sure to read on.

To schedule the exam, I broke out every topic covered in the description of the test and decided between the things I needed to learn, review, and skip. I then also broke down how much reading and how long each reading session would take. I gave myself an estimated time period for each of the topics I had to learn and review as well and kept a notebook tracker with the topics, days until the test, and how much reading was left. Based on how much time I thought it would take to learn, I allocated myself 30 minutes of time to study per day and divided my total time I thought I would spend studying by that, and scheduled the test out that many days. Some days I got to study for 30 min, some days I couldn't study at all. Other days like weekends, I could double down and put in a few hours at once. I would also record what I studied on what day with what resource and about how long I put into it.

I would try to go through the areas I had to learn online and find fake problems or try to do something simple in adventure works with the topics and then if I struggled, I'd go back and re-read or try the content in the books or find another article online. If you aren't feeling overly confident in an area, try looking for another online resource. If you can find sites that can test your knowledge in areas, that is a fantastic approach to realizing what areas you are lacking in information. Being able to explain something to someone is also a good indicator of how well you understand something.

I would also listen to podcasts and videos while running each morning, but I honestly don't think that helped much for the test. The most beneficial part besides using most of the technology day in and day out was following the exam book and following the sites I listed. I also watched the video's on Cathrine's site twice each.

For topics I found the hardest, I'd start by reading the prep chapter. Then I'd look for some reputable and good videos on the topics, read an additional online blog or two, and then I would create practice problems. If I still felt unsure, I'd look for a podcast on the topic to listen to loosely during free time like driving or running, and then I would also look for flash cards and quizzes online.

If I were to do it again, I'd probably do more flash cards on definitions of terms in my studying and will try that for 70-762. If I were really uncertain, I'd probably take the official pre-test. My test will probably not be the same as you will have and you need to look over the content you can be tested on via the MS site for the cert.

My favorite resources:

https://www.cathrinewilhelmsen.net/2015/01/28/preparing-for-and-taking-exam-70-461-querying-microsoft-sql-server-2012/

https://www.mssqltips.com/sqlservertip/4644/sql-server-exam-70761-study-material-for-querying-data-with-transactsql/

https://www.amazon.com/T-SQL-Fundamentals-3rd-Itzik-Ben-Gan/dp/150930200X

http://www.accelerated-ideas.com/70761-practice-test-questions.aspx#.WeeTWVtSypo

https://www.mssqltips.com/sqlservertip/4015/introducing-json-for-sql-server-2016/

https://www.mssqltips.com/sqlservertip/4073/sql-server-2016-advanced-json-techniques--part-1/

https://docs.microsoft.com/en-us/sql/relational-databases/json/json-data-sql-server

https://www.mssqltips.com/sqlservertip/3680/introduction-to-sql-server-2016-temporal-tables/

https://docs.microsoft.com/en-us/sql/t-sql/queries/select-group-by-transact-sql

https://www.mssqltips.com/sqlservertip/1958/sql-server-cross-apply-and-outer-apply/


r/SQLServer • • Apr 14 '26

Community Share SQL Server Management Studio 22.5 is now available!

55 Upvotes

Blog post is here:

https://techcommunity.microsoft.com/blog/sqlserver/announcing-sql-server-management-studio-22-5/4511289

So there are no surprises, it's a long blog post. Please read to the end (and not just because I wrote it). There's important info for folks that use GitHub Copilot in SSMS and I don't want it to get lost.

Thanks, and tell your friends 🙃


r/SQLServer • • Mar 18 '26

Community Share Introducing Automatic Index Compaction

55 Upvotes

We just released a MSSQL engine feature that might just make the whole index maintenance debate obsolete (or should at least make it less boring). Auto index compaction is now in public preview in Azure SQL and Fabric SQL.

Announcement blog: Stop defragmenting and start living: introducing auto index compaction.

Documentation (with an FAQ): Automatic Index Compaction | Microsoft Learn.

Would you use this instead of your own index maintenance? Tell us what you think.


r/SQLServer • • Dec 07 '22

Community Share Microsoft: November updates break ODBC database connections

Thumbnail
bleepingcomputer.com
55 Upvotes

r/SQLServer • • Sep 22 '22

Blog [Bitesized] Quick recap on Binary Search Trees

Post image
55 Upvotes

r/SQLServer • • Sep 08 '16

Plan Explorer is now completely free, no premium version!

Thumbnail
blogs.sqlsentry.com
55 Upvotes

r/SQLServer • • Nov 04 '19

SQL Server 2019 available now

Thumbnail
microsoft.com
54 Upvotes

r/SQLServer • • Feb 07 '19

Microsoft's Telemetry Service is totally spying on you and can't be turned off.

Thumbnail
brentozar.com
54 Upvotes

r/SQLServer • • Oct 01 '26

Discussion My transition away from hardcore SQL server DBA roles finally happened...

52 Upvotes

Never thought this would happen. But saw an internal opening in my company for a DB Engineering position. While I only had SQL and Azure SQL experience, I did not have the requisite other experience (python, automation, etc). However, I had a chat with the manager, and he decided to take me on.

I'll be coming on as a subject matter expert, evaluating their SQL requirements for some critical products, with the understanding I'll be learning other technologies in the DB engineering track such as a ansible, Azure DevOps, etc

It can happen, it's a long road, but no more on call support work and I can sleep better (that was a big motivator for me TBH).


r/SQLServer • • Sep 07 '26

Question Should I be worried about our company's SQL Server DBAs?

52 Upvotes

Hello! I’m hoping to get a sanity check from the experts here before I make a big thing out of this with management. I’ve already notified my immediate manager, but I want to make sure this is a real and serious problem.

My company runs an ASP.NET MVC web app backed by a Microsoft SQL Server 2022 database server, configured to run clustered in a high availability group. The majority of our PK indexes are auto-incrementing (identity) 32-bit int fields. I am a web developer for this app, writing C#, SQL, JS, HTML, and CSS. I am pretty good at T-SQL but I am NOT trained in database management. I did not set up the database servers and I don’t have access to the production database servers at all.

A few years ago, I was investigating why a process we run frequently on our production database which refreshes some table data was resulting in the database constantly growing. I discovered that with non-SIMPLE recovery modes, the transaction log file was continuously growing, and our company’s IT/DBA department was never backing up the transaction log. Since you need to to a transaction log backup in order to truncate the transaction log, this meant that for over a decade all of our production databases’ transaction log files had been getting bigger and bigger, some of them taking up 50+ GB of space on our database server. It was only after I notified them of this that they started doing regular transaction log backups and truncating them to keep the file sizes under control. They were doing regular full database backups, just not transaction log backups, and they had been dealing with the transaction log bloat by throwing hardware at the problem.

A few days ago I was trying to reclaim some disk space on our development environment’s dedicated SQL Server, and I started looking into the DBCC SHRINKFILE command to try to compact the database files. I saw a warning that you should rebuild indexes after doing this because it fragments the indexes, and out of curiosity I ran some queries against some of our development databases which had been backed up from production and restored onto the development server.

I found that both PK and non-clustered indexes of some of our largest tables in many of the restored backups had an enormous amount of index fragmentation. For example, an IDENTITY INT PK index for one of our most important tables with 725,000 pages had 85% fragmentation, another with 660,000 pages had 92%, etc. We had several dozen indexes with 10,000+ pages and 80-98% fragmentation. We have many databases, some up to 12 years old, and I have no reason to think this is an outlier; it’s likely that they all have heavily fragmented indexes.

I looked into it and I’m pretty sure that fragmentation of indexes is preserved across database backups and restores, so I think this means the production databases also have heavily fragmented indexes. I found advice that you should reorganize large indexes with 10-30% fragmentation and rebuild indexes when over 30%, and this is far beyond that. I did search this subreddit and I found that this is likely somewhat outdated and it depends also on index size and how sparse the index pages are and whether you’re running an HDD or SSD (I am not sure what our production servers are using).

Isn’t index maintenance one of the core responsibilities of a DBA? How concerned should we be that our IT/DBA department is ignorant / incompetent / negligent? Note that I’m not just asking about index maintenance here; the fact that they weren’t doing transaction log backups/truncates from 2014-2023 until a programmer educated them on the topic seems bad. Is it a huge red flag that they are not only not doing these things, but are apparently unaware that they’re even supposed to be doing these things? At this point, should we be worried about what other things a DBA is supposed to be doing to maintain a SQL server that they might not be doing? Should I recommend to my manager that he push for the IT/DBA department to undergo some kind of audit to find out what they’re supposed to be doing vs what they’re actually doing?


Thank you in advance for your advice and opinions.


r/SQLServer • • Jan 17 '24

Question How "big" does your data have to be before a relational database is no longer efficient?

52 Upvotes

I know the answer is "it depends" but humor me please. What is the largest SQL Server relational database you have personally ever worked with?

The rest of this post is basically a rant I just need to get off my chest, and inspired me to post here. If you don't want to read it stop here.

I worked for years as an ETL/SSIS/SQL Server database developer, then recently joined a new company in a business role. The tech team has a convoluted data solution on Azure Databricks that has constant data integrity issues that take forever to resolve. They get their data from a Snowflake data warehouse that has endless gobs of duplicate data and no real sense of referential integrity. My suggestion during a meeting was to incorporate a normalized relational db into the mix that feeds off the Snowflake data warehouse, and was basically scoffed at because "relational databases don't scale" and we can't do that old school stuff because we are "BiG DaTa" here. The thing is when all of this "big" data is deduped and properly normalized, I'm estimating something like 10s of GBs in size, at most 100 to 200 GB total if my estimates are way off. Am I crazy for reccomending a relational DB? I know from a quick google search SQL Server can technically store data in the petabytes but I'm curious what reddit thinks. What's the largest relational database you've personally worked with?

Apologies for formatting, typos, etc. I'm typing this on my phone at the bar.


r/SQLServer • • Jan 31 '19

Emergency Forget snowmageddon, it's dropageddon in Azure SQL world: Microsoft accidentally deletes customer DBs

Thumbnail
theregister.co.uk
52 Upvotes

r/SQLServer • • Dec 12 '16

Monday morning queries.

Post image
52 Upvotes

r/SQLServer • • Jun 27 '16

Community Share The Microsoft SQL Server Tooling team will be holding an AMA here on 6/30!

52 Upvotes

Hey there /r/sqlserver! We have some exciting news today!

The Microsoft SQL Server Tooling team will be joining us this coming Thursday, 6/30, from 10 AM to 3 PM PDT.

We'll have a thread stickied earlier Thursday to allow the community to start queuing up questions. Special thanks to /u/MattLoflin for offering the community this awesome AMA!

Check back on this thread as the date approaches for more details.

Update: AMA thread is live here!