T-SQL TUESDAY #143: Short code examples

Thank you John McCormack for hosting this month of T-SQL Tuesday.

For the past couple of years as a DBA, I migrated several databases and used many handy scripts that helped me made my work easier. These scripts may be simple but if you have a migration project involving several SQL Servers with some hundreds of databases, test and production database migrations becomes tedious. I would like to share some of then here which you might already known them very well.

  1. I used this script answered by AlexK (look for the script with most accepted answer) to kill all connections to a database. I used this script in Development/Test/QA/Production during database migrations. A very handy script. I used this script while migrating 200 servers from SQL Server 2000 to SQL Server 2016.
  2. Other Script that I have used for migrations are sp_help_revlogin to transfer the logins during migrations.
  3. When using transactional replication between the servers, I used to see several distribution job failures when a new snapshot generated or during the subscriber reinitialization. The snapshot generating the .sch files for replication with ANSI_PADDING turned OFF instead of ON. I found a very handy PowerShell script answered by Asaf Mohammad in Microsoft forum which will search the .sch file having SET ANSI_PADDING OFF in all the folders and subfolders of the snapshot and replace them with SET ANSI_PADDING ON. Thanks to Asaf for saving many hours. As per the recommendation from this forum, I used this script as a second step in my snapshot agent job so this setting is fixed within the snapshot agent job. After using this PowerShell script, my distribution job worked fine.

None of the scripts I mentioned above were written by me. It is the hard work of other professionals who created these scripts and freely shared the scripts to the world helping other professionals. Kudos to all of them. There are several other scripts that I use on regular basis but I wanted to keep this post short and only mention the ones which I used frequently since past couple of years.

I am looking forward to see what other SQL family members post about their favorite handy scripts!

T-SQL Tuesday #141 Work/Life Balance

I always thought I never had a work-life balance. I am a mother of two little kids. When someone asks me how I manage kids and work at the same time (especially during the pandemic), I mostly respond that it has been a hell of a lot of work when kids are at home and it’s been difficult to handle kids and work at the same time but I love to see my children in front of my eyes.

Whenever I hear about Work/Life balance, I get stressed out and get worried thinking I might doing something entirely wrong. I feel this way because I know I do not have a balance that I would like to have. I always dreamed of having that perfect family time every day but something comes up and that story goes on. As each day passed by, my guilt of not spending as much time with my family has built up doing nothing.

So I thought, what am I doing wrong here or why am I feeling guilty or being so stressed about it? Then I thought, let me think about it for a second. I am doing my job, taking care of my kids, doing household chores, and spending the rest of my time with my kids and family. All the things I do are important for me and my family. I am not wasting any time here. What if I can make little changes and mindfully think of where I am losing much time, I may make things better.

I spend many months thinking of that perfect time to spend with family or to have some self-time focusing on mind and body. I understood later that there will never be a perfect time. Stressing out or feeling guilty doesn’t help. We may have a busy work schedule. That is completely fine. It is really important of how happy we are once we are done with our work. It may be a couple of hours a day or even an hour a day. We always want to spend more time with our family because that’s our life.

I thought, instead of worrying about If I am being right in spending enough time with family, I tried making little changes in my schedule every day which slowly added up some free time. For example, starting my work early in the morning so I can log off a little bit early and can complete my chores a bit early so I can spend more time reading books with my kids and doing some artwork with them. I feel better as I make some changes to my schedule. I still have a lot of things to adjust and make changes to. It is a continuous process.

Everyone’s life is different. Everyone have their priorities. Nothing is right or wrong. Some people love working for more hours. That doesn’t mean they do not care their personal life. They just love their work. It’s all about what makes you happy. Some people love gardening. They find peace in it. I love having a cup of coffee and having some self-time 🙂

It is about finding happiness in the little things we do every day!

Little changes in our schedules can add a lot of time. Observe where you are spending your time and make changes accordingly.

Thanks, Tjay Belt for hosting this month of T-SQL Tuesday!

T-SQL Tuesday #139: Hybrid World!

With the invitation from Ben Weissman for the June month of T-SQL Tuesday, here are some of my thoughts about Hybrid world. Thanks Ben for hosting this month of T-SQL Tuesday!

With the increasing amount of data in our databases, handling the resources might get tough. Many shops currently have their databases spread across different environments like on-premises and on the cloud. While they plan to completely move their data into the cloud, process might be not easy if they are dealing with lot of data across different datacenters. That’s when the Azure Arc data services can really help manage all of these in a single secure location. We can manage SQL managed instances, Postgres SQL instances or in any other public cloud in one single panel. We can run this on our infrastructure or in any other public cloud.

Azure Arc data services in SQL

For the companies who are on-premises, Azure Arc provides the latest technologies like the evergreen SQL which means there will be no end of support for their old versions of databases. This technology provides continuous automatic updates and the features supporting databases. This will help in the capacity optimization and scale-out smoothly for the data workloads on-premises databases with no application downtime.

I did not yet had a chance to work with the companies using the hybrid environments. That doesn’t have to limit me from learning these amazing technologies Microsoft has to offer. I already started my learning journey with Azure Arc data services. It is a bit overwhelming to understand everything at once as there is so much to learn about this new technology. It is never too late to begin the learning. As many companies started moving to cloud, its never too late to improve the skills. With this T-SQL Tuesday invitation from Ben, I started learning about the Azure Arc data services. Here are the list of resources I am following and plan to follow to get started with Azure Arc data services, Kubernetes and Big data clusters:

  1. Big Data Clusters for the Absolute Beginner: Thank you Mohammad Darab for this amazing introduction session to Big Data Clusters. Am sure you are going to give a big kudos to Darab after watching this session. It’s that Amazing! Also, don’t forget to look at the playlist from Darab youtube channel focusing on Big Data clusters.
  2. Azure Arc-enabled Data Services: The Big Picture: This is an excellent 52 minute course by Ben Weissman which I definitely recommend to watch if you wanted to get the overview and start the journey with Azure Arc enabled data services learning. I watched this course yesterday and I love it.
  3. Microsoft Learn: Microsoft offers free training. Customize the path you wanted to learn and start the learning journey. Also, you can get free Azure account for free worth of $200 credit for a month to get hands on experience.
  4. Azure Arc-Enabled Data Services Revealed: Here is the link to the book written by Ben Weissman and Anthony E. Nocentino who are specialized in this area. Understand the core concepts of Kubernetes, fundamentals and architecture of Azure Arc-enabled data services and get in-depth knowledge on these concepts.
  5. Microsoft Azure: Youtube channel for free Microsoft Azure trainings

I hope these above resources will be helpful to you in starting your Hybrid learning journey 🙂

I would like to learn from other SQL professionals about their journey in the Hybrid world!

Thanks for reading!

T-SQL Tuesday: How Do You Respond When Technology Changes Under You?

With the invitation from AndyLeonard for the May month of T-SQL Tuesday, here are my thoughts on how to respond to technology changes.

As there is a saying, “When there is no Change, there is no Growth”

This is true in every aspect of life including technology. As the Technology changes, it is helping our lives to be more simpler and easier than before. With the continuous advancements in the technology, many professionals find themselves rushing in learning the new technologies. These advancements in the technologies adding up new features to previously existed technologies improve in performance and solve problems making our lives easier. The only question is how quickly can we cope with this change?

The only answer I believe is to train the employees with the new changes in the technologies. It is really important for the companies to not only bring the latest technologies to the companies for the use but also to mainly focus on the employee trainings to use the latest technologies efficiently.

Apart from the trainings, there are many employees who love and always look for the ways to learn new technologies. For every new technologies we have now, a free training platform may already be available to train the individuals so they have ease in using those technologies in their work. For example, Microsoft Azure. We do have a free training from Microsoft known as Microsoft learn. Microsoft also offers a free azure account so professionals can go ahead and get that hands on experience as they learn. This platform has helped many professionals across the world including me and helping in advancing our careers. Huge thanks to Microsoft for taking this initiative.

To keep ourselves updated with the latest evolving technologies, I follow several resources out there along with the technical documentation itself. There are several blogs related to specific technologies, communities helping each other to learn these new technologies and several technical newsletters and publications to keep us updated. I follow social media articles and posts from linkedin and twitter to be updated as much as possible with upcoming technologies.

Along with these, there are several youtube channels providing the concepts of the new technologies as they evolve. There are other training companies who can actually provide trainings especially from beginner to advance level along with hands on labs.

Keeping us up to date to know what is going on is not a tough job but investing time and interest in learning these technologies to effectively use in our daily work life is really important.

At the beginning, everything seems to be so confusing. If we see the number of technologies evolving at the same time, it is overwhelming for sure but if we can take one technology at a time and if we can focus on how the new technologies can actually simplify our daily work, we will be embracing the new technologies for the latest innovations they can offer.

Finally, it is very important to be ready for more and more advancements and to anticipate the changes. As the technology evolves, it becomes much easier to use. Keeping ourselves updated is the only way to keep growing!

Change is Good 🙂

T-SQL Tuesday #137: Jupyter Notebooks

With the invitation of Steve Jones for April month of T-SQL Tuesday, I am going to share some of my thoughts on using Jupyter notebooks.

Jupyter Notebook is an open-source web application that can serve us to create, share code and documents with others. It provides that beautiful way to document your code, text, images and query results. Jupyter notebooks in Azure data studio can run PySpark, Python 3, Spark R and Scala, as well as PowerShell. Run and visualize the data as you see the results without having to leave the environment. This is an excellent tool for documenting things. You do not have to write your long emails attaching bunch of screenshots any more. Once you start using the Jupyter notebooks, it will save you so much time and give you peace of mind. This tool can not only be used for documentation purposes but also can be used for your presentations for your demo purposes. Not only for the SQL code, this is a very nice tool for doing machine learning models, visualizing data and much more. Your code can be written in different cells which can be executed individually. This can help us to run specific part of the code in the project. This tool supports Python, R as well.

There are some magic commands that you can use to make your work easier. %clear, %autosave, %debug and %mkdir are some of the commands and these magic commands can be used in two ways. Linewise and cellwise. Linewise is when you wish to run a single command and cell-wise is when you wish to run an entire block of code.

There are also interactive dashboards in Jupyter notebooks.

When you wish to share these jupyter files and as they are in json format. You can save the notebook using different file options like a CSV, Excel, JSON or XML file . You can also convert your notebook into different formats by using the nbconvert option. For analytical queries, you can also build a chart for the data.

You can use the Jupyter notebooks for giving presentations to your customers and clients about your projects.

Jupyter notebooks is an amazing tool as you can document everything what you do. Once we start using Jupyter notebooks, you would definitely do not want to turn back to the previously used tools anymore. I recommend this tool to anyone who would like to explore and take advantage of many features the Jupyter notebooks has to offer.

T-SQL Tuesday #136: Least Favorite Data Type

With the Invitation of Brent Ozar for this month T-SQL Tuesday, I would like to share some thoughts on least favorite data type in SQL Server. Thank you Brent for hosting March month of T-SQL Tuesday.

VARCHAR(MAX)

Though VARCHAR(MAX) is suitable in situations with large strings of data, it has its own complications that we need to consider. In my career as a DBA, I at least saw couple of times SQL developers using VARCHAR(MAX) when they should not. Fixing the datatypes once in production is painful and causes risks.

When the data is stored in VARCHAR(n) datatype column, these values get stored in standard data page. VARCHAR(MAX) uses IN_ROW_Data up to 8000 bytes of data but if the data in more than 8000 bytes, it uses LOB_Data page and a pointer (reference) is stored in the IN_ROW_Data_page. We cannot create an Index on the VARCHAR(MAX) data type as a key column in the index. You can add the column of VARCHAR(MAX) as an included column but that wouldn’t be seekable and will duplicate the column completely which is lot of storage. We cannot compress the LOB data and the data retrieval from the LOB data is relatively slow. If the LOB data is stored as IN-ROW, it can be compressed but only when we compress the table with the PAGE level compression. LOB data cannot be compressed if you use ROW level compression and doesn’t depend if the LOB data is stored as in row or out of row.

Any variable you declare in VARCHAR(MAX) as the datatype will automatically spills to Tempdb which can cause performance problems. If you are using the VARCHAR(MAX) datatype column in your queries and sorting them, that requires so much memory to sort this data which may cause the memory issues. For selecting data having this datatype more than 8000 bytes can cause several off page I/O’s.

Recommendations:

If you are running queries and searching on column, that column should always be used as a fixed length column instead of VARCHAR(MAX) data type. If your row size can be managed to be less than 8000 bytes, that will store the data IN_ROW_Data_page which can avoid any page splits and avoids locking or latching during the updates. Limiting the length of the strings is really important for designing any database. Using VARCHAR(n) is recommended over VARCHAR(MAX) when ever possible.

I am really looking forward to what other SQL family members have to say about their least and the most favorite data types!

T-SQL Tuesday #135: Tools of the Trade

With the Invitation of Mikey Bronowski for this month T-SQL Tuesday Tools of the Trade, I would like share some useful tools that make my job easier:

  1. OBS Studio: This is a free and open source software for video recording and live streaming. I mostly prerecord my sessions using OBS. I personally love this tool as we have pretty much good content on YouTube that teach us how to use this tool.
  2. SentryOne Plan Explorer: Plan explorer is an amazing tool to analyze your execution plan and tune your queries very quickly. Its completely free.
  3. SQL Search: It is a free search for databases. If you need to find any specific object/column or any string on any database on the server, this tool is very useful. I use SQL search regularly.
  4. SQL Compare: SQL compare tool is very useful to compare the database schema and data between environments. I use this tool regularly.
  5. SQLQueryStress: It is a lightweight performance testing tool, designed to load test individual queries. I personally use this tool for my demos and testing any queries for performance.
  6. Zoomit: ZoomIt is a free screen zoom and annotation tool for presentations. I use it regulary and I am sure most of the speakers already know about the tool.
  7. Diffchecker: A very useful too to compare code/documents.
  8. Adobe Lightroom: This is a photo editing tool which I personally liked. It is professional and used by many photographers across the world.
  9. Free Download Manager: I use this tool for my downloads. It is much faster to download files. I use this tool especially for YouTube downloads. If you need to download the playlists at a time in a single shot, this tool is really useful. It is completely free.
  10. Nimbus Screenshot: It is a chrome extension. This tool is really useful when you wanted to take the screenshot of entire page. You can select the area you wanted to take the screenshot by scrolling the page. Very useful.

These are some of the useful tools I use regularly. I would also like to see the list of the tools others feel useful. I would love to start using those tools as well.

T-SQL Tuesday #134

T-SQL Tuesday #134

With the Invitation of James McGillivray for this month T-SQL Tuesday about taking a break when you’re stuck at home, I would like share some tips of how I manage stress by taking breaks.

It is a challenging time for each one of us during this pandemic. It is very important to be mentally strong during these hard times. Below are some of the tips I followed to take a break when we are stuck in home

  1. Reading moral stories to kids. Kids really enjoy me reading for them. As I explain the moral values to them, I learn along with them. This will instantly calm me down and make me think the wider perspective of life.
  2. I love arts and crafts. I love shopping for the material to make any new crafts from the ideas I have since long time. Putting something in action and seeing the craft coming out the way you saw in your mind gives so much satisfaction. Below picture is one of the crafts I made “3D wall Garden”.

3. I listen to David Goggins (Former navy seal) podcasts. He explains how a person can be mentally strong and how much a human being can accomplish just by changing the way we look at life. I started reading his book “Can’t Hurt Me”. This book has already changed me. I learned how to be mentally strong during the hardest times of life.

4. Watching thriller movies. I love watching thriller movies as they take me to a complete different world for few hours. Its a true refreshment.

5. Spending some time myself with a cup of coffee. No distractions with any social media, mobile phones or TV. Solely, its a self time. This is the best time to analyze how our mind wanders around. Controlling mind chattering is very important for mental health. Watching the thoughts pass through the mind freely and with mindfulness is like a meditation.

These are some of the tips I follow to take a break, I would love to see the tips from other participants for this month T-SQL Tuesday!

T-SQL Tuesday #133: What (Else) Have I Learned from Presenting?

Thank you Lisa Griffin for the invitation to December month of T-SQL Tuesday.

After I started presenting, I learned many technical concepts but here I would like to quickly mention couple of them:

  1. Memory grant connections are stored in a memory component in the SQL Server which is called as Fixed memory. As the fixed memory cannot be expanded or shrinked when there is a memory pressure, SQL server requests the other components of memory like for example, evict the plans out of the plan cache and dirty pages out of the buffer pool to release the memory as memory grants for executing the queries. These memory grants are allocated before the query goes to the execution phase. Memory grants for any query are allocated based on the hashes, sorts in the execution plan and Cardinality estimates. When there are many queries requesting more memory and when the Fixed memory is already full, these other memory components releases the memory as there is an internal pressure with in the SQL Server. Once the memory grant is allocated to the query, the memory will only be released once the query execution completes. Resource Semaphore is responsible for satisfying memory grant requests while keeping overall memory grant usages within the server limit.
  2. Redundant joins between the tables will be only removed by the SQL Server automatically on the background only if the referential integrity is maintained by the foreign key constraint defined between both the tables. If there is no Constraint defined, then as SQL Server doesn’t know about the relationship between two tables, SQL Server will perform a join scanning one table to find matching values from other table.
  3. SQL Server needs a NOEXPAND hint to create a query plan that uses an indexed view. When NOEXPAND is specified, automatic stats are created on index view same as it happens with the ordinary tables.

I would also like to hear from other community members of what else they have learned from presenting!