<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Eric Cobb, Author at The SERO Group</title>
	<atom:link href="https://theserogroup.com/author/ericc/feed/" rel="self" type="application/rss+xml" />
	<link>https://theserogroup.com/author/ericc/</link>
	<description>SQL Servers Healthy, Secure, And Reliable</description>
	<lastBuildDate>Mon, 21 Apr 2025 17:53:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>

<image>
	<url>https://theserogroup.com/wp-content/uploads/2024/07/cropped-Canister-only-1-32x32.png</url>
	<title>Eric Cobb, Author at The SERO Group</title>
	<link>https://theserogroup.com/author/ericc/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">121220030</site>	<item>
		<title>How to Troubleshoot SQL Server Database Mail Issues Using Built-In View</title>
		<link>https://theserogroup.com/sql-server/how-to-troubleshoot-sql-server-database-mail-issues-using-built-in-view/</link>
		
		<dc:creator><![CDATA[Eric Cobb]]></dc:creator>
		<pubDate>Wed, 23 Apr 2025 12:00:30 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Database Administration]]></category>
		<category><![CDATA[Script Library]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server Management]]></category>
		<guid isPermaLink="false">https://theserogroup.com/?p=7334</guid>

					<description><![CDATA[<p>Sending emails from a SQL Server via sp_send_dbmail is common, but troubleshooting problems can be frustrating. Fortunately, SQL Server logs every email attempt, making it easier to find and fix issues. View All Messages Processed By Database Mail The sysmail_allitems view shows every email that Database Mail has tried to process, whether it was successful&#8230; <br /> <a class="read-more" href="https://theserogroup.com/sql-server/how-to-troubleshoot-sql-server-database-mail-issues-using-built-in-view/">Read more</a></p>
<p>The post <a href="https://theserogroup.com/sql-server/how-to-troubleshoot-sql-server-database-mail-issues-using-built-in-view/">How to Troubleshoot SQL Server Database Mail Issues Using Built-In View</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Sending emails from a SQL Server via <a href="https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-send-dbmail-transact-sql?view=sql-server-ver16"><em>sp_send_dbmail</em></a> is common, but troubleshooting problems can be frustrating. Fortunately, SQL Server logs every email attempt, making it easier to find and fix issues.</p>



<h3 class="wp-block-heading" id="h-view-all-messages-processed-by-database-mail">View All Messages Processed By Database Mail</h3>



<p>The <a href="https://msdn.microsoft.com/en-us/library/ms175056.aspx" target="_blank" rel="noreferrer noopener"><em>sysmail_allitems</em></a> view shows every email that Database Mail has tried to process, whether it was successful or not. This view can help you identify problems by showing you the details of the messages that were sent compared with the messages that weren’t sent by giving you the status of each email.</p>



<p>Here are the status values you’ll see:</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><tbody><tr><td>sent</td><td>The message was successfully sent.</td></tr><tr><td>unsent</td><td>The message is waiting to be sent.</td></tr><tr><td>retrying</td><td>Send attempt failed; retrying soon.</td></tr><tr><td>failed</td><td>The message could not be sent.</td></tr></tbody></table></figure>



<h3 class="wp-block-heading" id="h-view-sent-messages">View Sent Messages</h3>



<p>Use <a href="https://msdn.microsoft.com/en-us/library/ms174372.aspx" target="_blank" rel="noreferrer noopener">sysmail_sentitems</a> to see which messages were successfully sent. Database Mail marks a message as sent when it is successfully submitted and accepted by the SMTP mail server. However, just because an email was accepted by the mail server does not mean it was actually delivered to the recipient. This just means that SQL Server succeeded in giving the message to the email server, and it is up to the email server to actually send the email. If something went wrong after SQL Server passed it off (like a bounce or spam filter snag), you won’t see that here. Those kinds of issues are up to the mail server to handle and won’t show up in SQL Server logs.</p>



<h3 class="wp-block-heading" id="h-view-unsent-messages">View Unsent Messages</h3>



<p>Use the <a href="https://learn.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sysmail-unsentitems-transact-sql?view=sql-server-ver16">sysmail_unsentitems</a> view to find emails still waiting to be sent or retrying after a failure.<br>Messages marked unsent or retrying remain in the mail queue and could be sent at any time.<br>Normally, you will not see many messages here unless there is a delay or email processing issue.</p>



<p>Database Mail marks a message as unsent when it waits in the queue but has not yet been processed.<br>If a message shows a retrying status, Database Mail tried to send it but could not reach the SMTP server. Retry behavior depends on the settings for Account Retry Delay and Account Retry Attempts.<br>(<em>For configuration details, see the</em> <em><a href="https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sysmail-configure-sp-transact-sql?view=sql-server-ver16">sysmail_configure_sp</a> stored procedure</em>.)</p>



<h3 class="wp-block-heading" id="h-view-failed-messages">View Failed Messages</h3>



<p>The <a href="https://msdn.microsoft.com/en-us/library/ms187747.aspx" target="_blank" rel="noreferrer noopener"><em>sysmail_faileditems</em></a> view is used to return only the messages with the <em>failed </em>status.  Use this view to determine which messages were not successfully sent by Database Mail and get message details to help you identify the nature of the problem. </p>



<p>To search for errors that are related to failed emails, use the <em>sysmail_faileditems</em> view to get the <em>mailitem_id</em> of the failed email, and then search for that <em>mailitem_id</em> in <a href="https://learn.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sysmail-event-log-transact-sql?view=sql-server-ver16"><em>sysmail_event_log</em></a>.</p>



<p>Microsoft also offers this extensive list of <a href="https://learn.microsoft.com/en-us/troubleshoot/sql/tools/troubleshoot-database-mail-issues">Database Mail troubleshooting techniques</a>. </p>



<h3 class="wp-block-heading" id="h-view-email-attachments">View Email Attachments</h3>



<p>Use the <a href="https://msdn.microsoft.com/en-us/library/ms187954.aspx" target="_blank" rel="noreferrer noopener">sysmail_mailattachments</a> view to list each attachment sent by Database Mail and its properties, such as file name and file size. This view does not store the attachment content, but it lets you track and verify attachments associated with each email. To link attachments to specific emails, cross-reference the <em>mailitem_id</em> with the other Database Mail views listed above.</p>



<h2 class="wp-block-heading" id="h-take-control-of-your-database-mail">Take Control of Your Database Mail</h2>



<p>Don’t let email issues slow you down. Proactive SQL Server Database Mail troubleshooting keeps your environment stable and your team confident.</p>



<h2 class="wp-block-heading" id="h-tired-of-troubleshooting-sql-server-issues-alone">Tired of Troubleshooting SQL Server Issues Alone?</h2>



<p>Let The SERO Group help you keep your SQL Servers running smoothly. <a href="https://theserogroup.com/contact-us/" target="_blank" rel="noreferrer noopener">Schedule a quick, no-pressure discovery call</a> today.</p>
<p>The post <a href="https://theserogroup.com/sql-server/how-to-troubleshoot-sql-server-database-mail-issues-using-built-in-view/">How to Troubleshoot SQL Server Database Mail Issues Using Built-In View</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">7334</post-id>	</item>
		<item>
		<title>Should You Use SQL Server Compression to Optimize Storage and Performance?</title>
		<link>https://theserogroup.com/sql-server/should-you-use-sql-server-compression-to-optimize-storage-and-performance/</link>
		
		<dc:creator><![CDATA[Eric Cobb]]></dc:creator>
		<pubDate>Wed, 26 Mar 2025 12:00:28 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Database Administration]]></category>
		<category><![CDATA[Database Development]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server Management]]></category>
		<guid isPermaLink="false">https://theserogroup.com/?p=7279</guid>

					<description><![CDATA[<p>If you’ve worked around database systems for long, you’ve no doubt encountered the issue of ensuring efficient storage. As your databases grow, so do your storage sizes (and costs!). Thankfully, SQL Server provides a powerful feature that can help alleviate this problem: compression. Compression in SQL Server is a feature that helps to reduce the&#8230; <br /> <a class="read-more" href="https://theserogroup.com/sql-server/should-you-use-sql-server-compression-to-optimize-storage-and-performance/">Read more</a></p>
<p>The post <a href="https://theserogroup.com/sql-server/should-you-use-sql-server-compression-to-optimize-storage-and-performance/">Should You Use SQL Server Compression to Optimize Storage and Performance?</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>If you’ve worked around database systems for long, you’ve no doubt encountered the issue of ensuring efficient storage. As your databases grow, so do your storage sizes (and costs!). Thankfully, SQL Server provides a powerful feature that can help alleviate this problem: compression.</p>



<p>Compression in SQL Server is a feature that helps to reduce the amount of storage needed for tables and indexes. Think of it like compressing a large file into a smaller one. You’re taking the same data but making it more compact and efficient. The goal is to save space, reduce I/O, and make the most of your storage resources. When data is compressed, the storage required to hold the same data is reduced, which can lead to more efficient use of disk space and faster read operations.</p>



<p>SQL Server provides two main types of compression: <strong>row-level compression</strong> and <strong>page-level compression</strong>. Each has its strengths and specific use cases, depending on your data and workload.</p>



<h2 class="wp-block-heading" id="h-row-level-compression">Row-Level Compression</h2>



<p>Row-level compression focuses on the individual rows within a table. In SQL Server, data types like <em>CHAR</em>, <em>INT</em>, and <em>BIGINT</em> are usually stored in fixed-length formats. This means that if a column is defined to be 100 characters long, but only 10 characters are used, the remaining 90 characters are just sitting there, wasting space. Even if you don’t need all the space, SQL Server still reserves it.</p>



<p>Row-level compression addresses this issue by converting those fixed-length columns into variable-length columns. For example, that 100-character CHAR column would only store the 10 characters you actually need, along with a small amount of overhead for metadata. The result is a more compact representation of your data because SQL Server only stores what it needs, cutting down on the unnecessary padding.</p>



<p>Row-level compression also gets rid of the redundancy of <em>NULL</em> values, replacing them with a more efficient marker. And for small data types like boolean values, SQL Server uses a technique called<em> bit-packing</em>, which allows multiple small values to be stored together in a single byte, saving even more space. The result is smaller, more efficient data storage.</p>



<p>Row-level compression also gets rid of the redundancy of <em>NULL </em>values, replacing them with a more efficient marker. And for small data types like boolean values, SQL Server uses a technique called <em>bit-packing</em>, which allows multiple small values to be stored together in a single byte, saving even more space. The result is smaller, more efficient data storage.</p>



<h2 class="wp-block-heading" id="h-page-level-compression">Page-Level Compression</h2>



<p>While row-level compression is a great first step, page-level compression takes it a bit further. SQL Server organizes data in “pages” behind the scenes, and each page uses 8KB of storage. With page-level compression, SQL Server compresses entire pages of data, not just individual rows. The idea here is that, rather than just compressing individual rows, SQL Server applies a two-step process to an entire page of data. It’s like compressing a whole chapter of a book instead of just one sentence.</p>



<p>First, SQL Server applies row-level compression to each row within the page, making the data smaller. But then it goes a step further and looks for repeating patterns across rows on the same page (like repeated values) and stores them more efficiently. Let’s say there’s a column in your table with a lot of repeated values, like a date or <em>NULL</em>s. Rather than storing that repeated data over and over again, SQL Server will build a dictionary of those repeated values and store a reference to them instead. This is a huge win in terms of space savings, especially for large tables with lots of repetitive data.</p>



<h2 class="wp-block-heading" id="h-is-sql-server-compression-right-for-you">Is SQL Server Compression Right for You?</h2>



<p>Compression can offer significant benefits, but it’s not a one-size-fits-all solution. For starters, there may be a slight CPU overhead. Compression isn’t free. Compressing and decompressing data requires processing power. In some cases, especially with page-level compression, this may put a slight strain on the CPU, which might slow down write operations like inserts, updates, and deletes.</p>



<p>Another potential downside is that compression doesn’t always yield massive savings depending on the nature of your data. For example, if your tables are relatively small, you might not see much benefit from compression. Also, if you are storing images in your database (and you really, really shouldn’t be), SQL Server will not be able to compress those. Compression tends to shine most when you have large datasets with lots of redundant values or many <em>NULL</em> entries.</p>



<p>On the flip side, if you’re dealing with a read-heavy workload, compression can significantly improve performance by reducing the amount of data that needs to be read from disk. This is where the benefits of compression really stand out, as it can cut down on I/O and make your database queries faster.</p>



<p>SQL Server compression is a powerful feature for saving space and potentially improving read performance. It helps with both storage and I/O efficiency, especially for large databases with repetitive data. But it’s important to keep in mind that there could be slight trade-offs, particularly when it comes to CPU usage. Testing is key: before you apply compression across your entire database, it’s worth evaluating the impact on both CPU resources and storage.</p>



<h2 class="wp-block-heading" id="h-want-to-work-with-the-sero-group">Want to work with The SERO Group?</h2>



<p>Want to learn more about how The SERO Group helps organizations take the guesswork out of managing their SQL Servers? <a href="https://theserogroup.com/contact-us/" target="_blank" rel="noreferrer noopener">Schedule a no-obligation discovery call</a>&nbsp;with us to get started.</p>
<p>The post <a href="https://theserogroup.com/sql-server/should-you-use-sql-server-compression-to-optimize-storage-and-performance/">Should You Use SQL Server Compression to Optimize Storage and Performance?</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">7279</post-id>	</item>
		<item>
		<title>Clustered vs. Non-Clustered Indexes: How to Optimize SQL Server Performance</title>
		<link>https://theserogroup.com/sql-server/clustered-vs-non-clustered-indexes-how-to-optimize-sql-server-performance/</link>
		
		<dc:creator><![CDATA[Eric Cobb]]></dc:creator>
		<pubDate>Wed, 26 Feb 2025 13:00:00 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Database Administration]]></category>
		<category><![CDATA[Database Development]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server Management]]></category>
		<guid isPermaLink="false">https://theserogroup.com/?p=7094</guid>

					<description><![CDATA[<p>Indexes are an essential part of any SQL Server database. One of the keys to improving performance is understanding how indexes work. Indexes help speed up data retrieval, optimize query performance, and improve the overall efficiency of your database. SQL Server offers several index types, but clustered and non-clustered indexes are the most important. Understanding&#8230; <br /> <a class="read-more" href="https://theserogroup.com/sql-server/clustered-vs-non-clustered-indexes-how-to-optimize-sql-server-performance/">Read more</a></p>
<p>The post <a href="https://theserogroup.com/sql-server/clustered-vs-non-clustered-indexes-how-to-optimize-sql-server-performance/">Clustered vs. Non-Clustered Indexes: How to Optimize SQL Server Performance</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Indexes are an essential part of any SQL Server database. One of the keys to improving performance is understanding how indexes work. Indexes help speed up data retrieval, optimize query performance, and improve the overall efficiency of your database. SQL Server offers several index types, but clustered and non-clustered indexes are the most important. Understanding their differences helps you design better-performing databases.</p>



<h3 class="wp-block-heading" id="h-what-is-a-clustered-index">What is a Clustered Index?</h3>



<p>Think of a clustered index as the primary organizer of your data. It defines the physical order of the data rows in a table. When you create a clustered index on a table, SQL Server sorts the data in that table according to that clustered index. Essentially, the table itself becomes the index, and the data rows are sorted and stored in the same order as the clustered index key.</p>



<p>The catch: you can only have <strong>one</strong> clustered index per table.This is because there can only be one way to physically organize the data on the hard drive. This index is often created on the primary key column, but it doesn’t have to be.</p>



<p>Earlier SQL Server documentation called the clustered index the most important index for a table. Microsoft values clustered indexes so highly that SQL Server automatically creates one on the primary key if you don’t specify it!</p>



<h3 class="wp-block-heading" id="h-what-is-a-non-clustered-index">What is a Non-Clustered Index?</h3>



<p>Unlike clustered indexes, non-clustered indexes do not define the physical order of the data rows. Instead, they create a separate structure that helps SQL Server find data more quickly. A good way to think of a non-clustered index is like a miniature copy of your table containing just the columns listed in the index. As data is added or modified in your table, SQL Server automatically keeps the non-clustered indexes in sync.</p>



<p>Non-clustered indexes are what make your queries run faster. Having smaller, more targeted data sets allows SQL Server to more quickly hone in on the data it is after. For example, if you’re frequently filtering your data by customer name or order status, a non-clustered index on those columns can help make those queries faster. And, with non-clustered indexes, you can have multiple indexes on a table, which is useful when you need to optimize searches on different columns.</p>



<p>Another cool thing about non-clustered indexes is that they can be used as something referred to as <em>covering indexes.</em> A covering index contains all of the data your query needs, so SQL Server can retrieve the data directly from the index without even touching the actual table. This can save a lot of time and reduce the number of I/O operations. Covering indexes are great for smaller, frequently run queries.</p>



<h3 class="wp-block-heading" id="h-having-too-many-non-clustered-indexes">Having Too Many Non-Clustered Indexes</h3>



<p>Non-clustered indexes boost query performance, but too many can hurt your database. Each added index increases storage requirements. More importantly, modifying data forces SQL Server to update every related index. More indexes mean slower operations, especially in write-heavy databases.</p>



<p>For example, if you have 1 table that has 10 non-clustered indexes on it, inserting 1 row will actually result in 11 inserts (1 insert for the table and 1 additional insert for each of the 10 indexes). Every time the data is modified in the table, the indexes must also be updated to reflect the changes.</p>



<p>Thankfully, SQL Server provides tools that let you see which indexes are being used and which ones are not. You can query SQL Server’s Dynamic Management Views (DMVs), such as <em><a href="https://learn.microsoft.com/en-us/sql/relational-databases/system-dynamic-management-views/sys-dm-db-index-usage-stats-transact-sql">sys.dm_db_index_usage_stats</a></em>, to identify indexes that are rarely used. Drop unhelpful or unused indexes to reduce overhead and improve performance.</p>



<p>Both clustered and non-clustered indexes improve SQL Server performance, but using them correctly is crucial. Clustered indexes define data order, while non-clustered indexes speed up queries. Balance your index strategy by choosing the right indexes for each query.</p>



<h3 class="wp-block-heading" id="h-want-to-work-with-us">Want to Work with Us?</h3>



<p>Want expert help managing your SQL Servers? The SERO Group takes the guesswork out of optimization. <a href="https://theserogroup.com/contact-us/" target="_blank" rel="noreferrer noopener">Schedule a no-obligation discovery call</a> with us today to get started.</p>
<p>The post <a href="https://theserogroup.com/sql-server/clustered-vs-non-clustered-indexes-how-to-optimize-sql-server-performance/">Clustered vs. Non-Clustered Indexes: How to Optimize SQL Server Performance</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">7094</post-id>	</item>
		<item>
		<title>How Proper Database Design Improves SQL Server Performance and Scalability</title>
		<link>https://theserogroup.com/data-strategy/how-proper-database-design-improves-sql-server-performance-and-scalability/</link>
		
		<dc:creator><![CDATA[Eric Cobb]]></dc:creator>
		<pubDate>Wed, 29 Jan 2025 13:00:00 +0000</pubDate>
				<category><![CDATA[Data Strategy]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Database Administration]]></category>
		<category><![CDATA[Database Development]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Management]]></category>
		<guid isPermaLink="false">https://theserogroup.com/?p=6993</guid>

					<description><![CDATA[<p>When a SQL Server database is the backbone of your application, its design will have a huge impact on the application&#8217;s performance. While many developers just view the database as a container for storing data, the truth is that a well-designed database is critical to your application’s speed, reliability, and ability to scale with your&#8230; <br /> <a class="read-more" href="https://theserogroup.com/data-strategy/how-proper-database-design-improves-sql-server-performance-and-scalability/">Read more</a></p>
<p>The post <a href="https://theserogroup.com/data-strategy/how-proper-database-design-improves-sql-server-performance-and-scalability/">How Proper Database Design Improves SQL Server Performance and Scalability</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>When a SQL Server database is the backbone of your application, its design will have a huge impact on the application&#8217;s performance. While many developers just view the database as a container for storing data, the truth is that a well-designed database is critical to your application’s speed, reliability, and ability to scale with your business needs. A poorly designed database can quickly become a bottleneck, leading to performance issues and costly overhauls.</p>



<p>Here are a few of the ways your database design can impact your application’s success:</p>



<h3 class="wp-block-heading" id="h-faster-data-retrieval">Faster Data Retrieval</h3>



<p>A well-designed database makes it easier and faster to find the data your application needs. For example, properly structuring your tables and relationships and having good indexes in place allows SQL Server to quickly locate the right information in your database.</p>



<p>Without these optimizations, your database has to do more work, leading to slower response times. Over time, as your database grows, these delays can pile up, frustrating users and affecting your app’s overall performance.</p>



<h3 class="wp-block-heading" id="h-structured-for-future-growth">Structured for Future Growth</h3>



<p>Applications often start small but grow in complexity and size over time. A good database design prepares your application to handle increasing data volumes and user loads. For example, splitting a large table into smaller partitions based on date ranges or geographical regions helps ensure queries are faster because they only have to search the relevant data.</p>



<p>As your app attracts more users, it will face increased demand for data access and processing, and your database needs to be able to handle this pressure. Techniques like indexing, query optimization, and using appropriate isolation levels play a big role in maintaining performance under heavy loads.  And strategies like row-level locking or read replicas can ensure that high traffic doesn’t impact the user experience.</p>



<p>If these types of strategies aren’t considered during the design phase, you might face significant challenges as your application tries to scale.</p>



<h3 class="wp-block-heading" id="h-more-efficient-resource-utilization">More Efficient Resource Utilization</h3>



<p>Good database design ensures that your application uses system resources like CPU, memory, and storage as effectively as possible. This means your app can perform well even with limited or less expensive hardware, saving money and avoiding unnecessary upgrades.</p>



<p>For example, choosing the right data types for your data columns can reduce storage requirements and speed up processing. And indexing, when done correctly, significantly improves the read performance of your queries and can cut down on memory and CPU usage, while missing indexes can slow down your entire application.</p>



<h3 class="wp-block-heading" id="h-in-conclusion-sql-server-database-design-matters">In Conclusion: SQL Server Database Design Matters</h3>



<p>Taking the time to plan your database properly can save you headaches down the road and ensure your application is fast, reliable, and ready for anything.</p>



<h3 class="wp-block-heading" id="h-want-to-work-with-the-sero-group">Want to Work With The SERO Group?</h3>



<p>Want to learn more about how The SERO Group helps organizations take the guesswork out of managing their SQL Servers? <a href="https://theserogroup.com/contact-us/" target="_blank" rel="noreferrer noopener">Schedule a no-obligation discovery call</a>&nbsp;with us to get started.</p>
<p>The post <a href="https://theserogroup.com/data-strategy/how-proper-database-design-improves-sql-server-performance-and-scalability/">How Proper Database Design Improves SQL Server Performance and Scalability</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">6993</post-id>	</item>
		<item>
		<title>How to Encrypt Sensitive Text in SQL Server with ENCRYPTBYPASSPHRASE</title>
		<link>https://theserogroup.com/data-security/how-to-encrypt-sensitive-text-in-sql-server-with-encryptbypassphrase/</link>
		
		<dc:creator><![CDATA[Eric Cobb]]></dc:creator>
		<pubDate>Wed, 23 Oct 2024 12:00:00 +0000</pubDate>
				<category><![CDATA[Data Security]]></category>
		<category><![CDATA[Data Strategy]]></category>
		<category><![CDATA[DBA]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Database Administration]]></category>
		<category><![CDATA[Database Development]]></category>
		<category><![CDATA[Script Library]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Security]]></category>
		<guid isPermaLink="false">https://theserogroup.com/?p=6786</guid>

					<description><![CDATA[<p>Storing sensitive information in a database, like passwords or social security numbers, is common practice. However, storing them securely is less common. Unfortunately, one of the most typical approaches is to store sensitive information in a table as clear text. That means that anyone with access to that table can see all of that sensitive&#8230; <br /> <a class="read-more" href="https://theserogroup.com/data-security/how-to-encrypt-sensitive-text-in-sql-server-with-encryptbypassphrase/">Read more</a></p>
<p>The post <a href="https://theserogroup.com/data-security/how-to-encrypt-sensitive-text-in-sql-server-with-encryptbypassphrase/">How to Encrypt Sensitive Text in SQL Server with ENCRYPTBYPASSPHRASE</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Storing sensitive information in a database, like passwords or social security numbers, is common practice. However, storing them securely is less common. Unfortunately, one of the most typical approaches is to store sensitive information in a table as clear text. That means that anyone with access to that table can see all of that sensitive data.</p>



<p>Just to be clear, storing sensitive information as a clear text string is a really, really,&nbsp;<em>really</em>&nbsp;bad idea.</p>



<p>Not encrypting information in a database can cause serious problems. As just one example, if the database is compromised, all user passwords could be exposed. Data breaches are becoming more and more common. If the authorities come knocking on your door, you need to be able to show them that you at least made a concerned effort to protect that data.</p>



<h2 class="wp-block-heading" id="h-encrypting-text-that-will-need-to-be-decrypted">Encrypting text that will need to be decrypted</h2>



<p>In some cases, you may be able to store your sensitive data as strongly encrypted text that will never need to be decrypted. For example, hashing a password used for your application login and then just comparing the hashed password for the login instead of the actual password. But, in most cases, being able to decrypt the sensitive data is going to be necessary.</p>



<p>In these cases,  <a href="https://docs.microsoft.com/en-us/sql/t-sql/functions/encryptbypassphrase-transact-sql" target="_blank" rel="noreferrer noopener">ENCRYPTBYPASSPHRASE</a> (available in SQL Server 2008 and up) offers one of the simplest ways for you to encrypt sensitive information in a way that can also be decrypted (by using <a href="https://docs.microsoft.com/en-us/sql/t-sql/functions/decryptbypassphrase-transact-sql" target="_blank" rel="noreferrer noopener">DECRYPTBYPASSPHRASE</a>). At its very basic, ENCRYPTBYPASSPHRASE requires two mandatory arguments: a passphrase used to generate the encryption key and the text to be encrypted.  Notice that it specifies a pass<strong><em>phrase</em></strong>, not pass<strong><em>word</em></strong>. There is an important difference between these two.</p>



<h2 class="wp-block-heading" id="h-a-passphrase-vs-a-password">A passphrase vs. a password</h2>



<p>As described in the ENCRYPTBYPASSPHRASE documentation:&nbsp;</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p><em>A passphrase is a password that includes spaces. The advantage of using a passphrase is that it is easier to remember a meaningful phrase or sentence than to remember a comparably long string of characters.</em></p>
</blockquote>
</blockquote>



<p>Many people don’t realize that you can use a space as a legitimate special character in most passwords. By doing this, you can generate a much more secure password sentence (or phrase) instead of a single word. An example of a passphrase may be something like “I forgot my password!”</p>



<p>Just to be clear, a space is <strong><em>not </em></strong>required in your passphrase for ENCRYPTBYPASSPHRASE. If you wanted to use a GUID for your passphrase or a random string such as “Zgt9$Ex%*unZO8Z},” that is perfectly acceptable.</p>



<h2 class="wp-block-heading" id="h-using-nbsp-encryptbypassphrase">Using&nbsp;ENCRYPTBYPASSPHRASE</h2>



<p>For the examples in this post, I am going to use the encryption passphrase “This is my Passphrase!”, and the text to be encrypted is “ABC123”.</p>



<p>The basic syntax is:<br>ENCRYPTBYPASSPHRASE(‘encryption passphrase’, ‘text to encrypt’)</p>



<p>There are other arguments that can be used with&nbsp;ENCRYPTBYPASSPHRASE (see&nbsp;<a href="https://docs.microsoft.com/en-us/sql/t-sql/functions/encryptbypassphrase-transact-sql" target="_blank" rel="noreferrer noopener">MSDN Doc</a>), but for this simple example we are just using the&nbsp;two mandatory arguments.</p>



<p>To view the encrypted value of the text “ABC123”, you would use this script:</p>



<pre class="wp-block-code"><code>SELECT ENCRYPTBYPASSPHRASE(N'This is my Passphrase!', N'ABC123');</code></pre>



<p>That SELECT statement will return a&nbsp;VARBINARY value such as:&nbsp;<em>0x0100000093EEC20B790EF208B1FB631F0AB3028E3A8C196643C4BD578528A0DFAE7AB45B</em></p>



<p>It is important to note that the VARBINARY value returned from ENCRYPTBYPASSPHRASE is <a href="https://en.wikipedia.org/wiki/Nondeterministic_algorithm" target="_blank" rel="noreferrer noopener">nondeterministic</a>, meaning that even with the same input it will not generate the same output every time.  So you can run the exact same SELECT statement multiple times and get a different result each time.</p>



<p>Thankfully, this output has no bearing on using the DECRYPTBYPASSPHRASE function. As long as you have the correct passphrase, DECRYPTBYPASSPHRASE will successfully decrypt any of those VARBINARY results to their original value.</p>



<h2 class="wp-block-heading" id="h-storing-an-encrypted-value-in-a-table">Storing an encrypted value in a table</h2>



<p>Now that we know how to encrypt a sensitive text string, let’s take a look at how to store that encrypted value in a table. &nbsp;Since the value returned from&nbsp;ENCRYPTBYPASSPHRASE is a&nbsp;VARBINARY data type, that is how we want to store it since this is also the data type required by DECRYPTBYPASSPHRASE.</p>



<p>The first thing we need to do is determine the size of our encrypted column in our table. The VARBINARY values returned by ENCRYPTBYPASSPHRASE can vary in size, with maximum size of 8,000 bytes. The size of the returned value is going to depend on the size of the actual text being encrypted. You can use the <a href="https://docs.microsoft.com/en-us/sql/t-sql/functions/datalength-transact-sql" target="_blank" rel="noreferrer noopener">DATALENGTH</a> function to help figure that out. If you have a way to control the maximum allowed length of the sensitive text value you want to encrypt, use that size for your table column, but try not to use VARBINARY(8000) if you don’t have to.</p>



<p>Here is a simple example of storing our encrypted text in the [Password] column of a table:</p>



<pre class="wp-block-code"><code>CREATE TABLE dbo.Users (&#91;UserName] VARCHAR(50), &#91;Password] VARBINARY(50))
 
INSERT INTO dbo.Users (&#91;UserName], &#91;Password])
VALUES ('Charlie Brown', ENCRYPTBYPASSPHRASE(N'This is my Passphrase!', N'ABC123'))
 
SELECT &#91;UserName], &#91;Password]
FROM dbo.Users</code></pre>



<h2 class="wp-block-heading" id="h-using-decryptbypassphrase">Using DECRYPTBYPASSPHRASE</h2>



<p>Now that we have our sensitive text encrypted, we need to be able to decrypt it as well. &nbsp;This is easily done by using the&nbsp;DECRYPTBYPASSPHRASE function with the same passphrase we encrypted our text string with. However, DECRYPTBYPASSPHRASE also returns a VARBINARY value, which we will have to convert to a string. &nbsp;This can be done by adding a CONVERT function to our SELECT statement.</p>



<pre class="wp-block-code"><code>SELECT &#91;UserName], CONVERT(NVARCHAR, DECRYPTBYPASSPHRASE(N'This is my Passphrase!', &#91;Password]))
FROM dbo.Users</code></pre>



<p>Now you should see your decrypted value returned correctly in clear text. ENCRYPTBYPASSPHRASE offers a quick and easy way for you to encrypt text in SQL Server and can be useful for encrypting sensitive information if you need to be able to decrypt it later. </p>



<h2 class="wp-block-heading" id="h-want-to-work-with-the-sero-group">Want to work with The SERO Group?</h2>



<p>Want to learn more about how The SERO Group helps organizations take the guesswork out of managing their SQL Servers? <a href="https://theserogroup.com/contact-us/" target="_blank" rel="noreferrer noopener">Schedule a no-obligation discovery call</a>&nbsp;with us to get started.</p>
<p>The post <a href="https://theserogroup.com/data-security/how-to-encrypt-sensitive-text-in-sql-server-with-encryptbypassphrase/">How to Encrypt Sensitive Text in SQL Server with ENCRYPTBYPASSPHRASE</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">6786</post-id>	</item>
		<item>
		<title>Useful Scripts For SQL Server Logins and Permissions</title>
		<link>https://theserogroup.com/dba/useful-scripts-for-sql-server-logins-and-permissions/</link>
		
		<dc:creator><![CDATA[Eric Cobb]]></dc:creator>
		<pubDate>Wed, 25 Sep 2024 12:00:00 +0000</pubDate>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Database Administration]]></category>
		<category><![CDATA[Database Development]]></category>
		<category><![CDATA[Script Library]]></category>
		<category><![CDATA[SQL Security]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Management]]></category>
		<guid isPermaLink="false">https://theserogroup.com/?p=6676</guid>

					<description><![CDATA[<p>Since security and permissions are a big part of a DBA’s job, it&#8217;s important to be able to find out things like who has elevated login permissions or when a login was last used. Here are a few queries to help you check your server and database access. Most of these scripts are based off&#8230; <br /> <a class="read-more" href="https://theserogroup.com/dba/useful-scripts-for-sql-server-logins-and-permissions/">Read more</a></p>
<p>The post <a href="https://theserogroup.com/dba/useful-scripts-for-sql-server-logins-and-permissions/">Useful Scripts For SQL Server Logins and Permissions</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Since security and permissions are a big part of a DBA’s job, it&#8217;s important to be able to find out things like who has elevated login permissions or when a login was last used. Here are a few queries to help you check your server and database access. Most of these scripts are based off of sys.dm_exec_sessions, a DMV that shows information about all active user connections. </p>



<p>I should also mention that the results of these queries will <strong>only go back to the last SQL Server start time</strong>. Anything that occurred before then won&#8217;t be available.</p>



<h3 class="wp-block-heading" id="h-logins-vs-users">Logins Vs. Users</h3>



<p>First, let&#8217;s take a look at the difference between “logins” and “users” in SQL Server, as people sometimes get them confused, or think they&#8217;re the same thing. A “login” allows access to a SQL Server instance. A “user” allows access to a specific database on that instance. Usually, a user is tied to a login, although you can have a user that is not tied to a login (known as a loginless user).</p>



<h3 class="wp-block-heading" id="h-when-was-the-last-time-a-login-was-used">When was the last time a login was used?</h3>



<pre class="wp-block-code"><code>--list of logins and last time each logged in
SELECT &#91;Login] = login_name 
	,&#91;Last Login Time] = MAX(login_time)
FROM sys.dm_exec_sessions
GROUP BY &#91;login_name];</code></pre>



<h3 class="wp-block-heading" id="h-which-logins-have-logged-in-within-the-last-x-hours">Which logins have logged in within the last X hours?</h3>



<pre class="wp-block-code"><code>--all logins in the last 4 hours
SELECT &#91;Login] = login_name
	,&#91;Last Login Time] = login_time
	,&#91;Host] = HOST_NAME
	,&#91;Program] = PROGRAM_NAME
	,&#91;Client Interface] =  client_interface_name
	,&#91;Database] = DB_NAME(database_id)
FROM sys.dm_exec_sessions
WHERE &#91;login_time] &gt; DATEADD(HH,-4,getdate())--modify date as needed
ORDER BY &#91;login_time] desc</code></pre>



<h3 class="wp-block-heading" id="h-how-many-times-has-each-login-logged-in-within-the-last-x-hours">How many times has each login logged in within the last X hours?</h3>



<pre class="wp-block-code"><code>--login counts for the last 4 hours
SELECT &#91;Login] = login_name
	,&#91;Last Login Time] = MAX(login_time)
	,&#91;Number Of Logins] = COUNT(*)
FROM sys.dm_exec_sessions
WHERE &#91;login_time] &gt; DATEADD(HH,-4,getdate())--modify date as needed
GROUP BY &#91;login_name]
ORDER BY &#91;Login] desc</code></pre>



<h3 class="wp-block-heading" id="h-which-logins-have-sysadmin-access">Which logins have Sysadmin access?</h3>



<pre class="wp-block-code"><code>--check for logins with sysadmin access
SELECT &#91;Login] = name
	,&#91;Login Type] = type_desc
	,&#91;Disabled] = is_disabled
FROM     master.sys.server_principals 
WHERE    IS_SRVROLEMEMBER ('sysadmin',name) = 1
ORDER BY &#91;Login]</code></pre>



<h3 class="wp-block-heading" id="h-checking-a-user-s-access-to-databases">Checking A User’s Access To Databases</h3>



<p>This query will return a list of databases that the specified user has access to. This will work for SQL Server Logins as well as Active Directory Logins.  This is done by specifying&nbsp;<a href="https://docs.microsoft.com/en-us/sql/t-sql/statements/execute-as-transact-sql" target="_blank" rel="noreferrer noopener">EXECUTE AS LOGIN</a>&nbsp;just before the query. (also be sure to specify&nbsp;<a href="https://docs.microsoft.com/en-us/sql/t-sql/statements/revert-transact-sql" target="_blank" rel="noreferrer noopener">REVERT&nbsp;</a>after the query runs)</p>



<p>It should be noted that this query only shows you what databases the user can access, not the permissions the user has on the databases.</p>



<pre class="wp-block-code"><code>EXECUTE AS LOGIN = 'YourDomain\User.Name' --Change This
	SELECT &#91;name]
	FROM MASTER.sys.databases
	WHERE HAS_DBACCESS(&#91;name]) = 1
REVERT</code></pre>



<h2 class="wp-block-heading" id="h-want-to-work-with-the-sero-group">Want to work with The SERO Group?</h2>



<p>Want to learn more about how The SERO Group helps organizations take the guesswork out of managing their SQL Servers? <a href="https://theserogroup.com/contact-us/" target="_blank" rel="noreferrer noopener">Schedule a no-obligation discovery call</a>&nbsp;with us to get started.</p>
<p>The post <a href="https://theserogroup.com/dba/useful-scripts-for-sql-server-logins-and-permissions/">Useful Scripts For SQL Server Logins and Permissions</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">6676</post-id>	</item>
		<item>
		<title>Tracking Deprecated Features in SQL Server</title>
		<link>https://theserogroup.com/sql-server/tracking-deprecated-features-in-sql-server/</link>
		
		<dc:creator><![CDATA[Eric Cobb]]></dc:creator>
		<pubDate>Wed, 21 Aug 2024 12:00:00 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Database Administration]]></category>
		<category><![CDATA[Script Library]]></category>
		<category><![CDATA[Shared Disks]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server Management]]></category>
		<guid isPermaLink="false">https://theserogroup.com/?p=6472</guid>

					<description><![CDATA[<p>With each new release of SQL Server, we gain exciting new features—but also face the reality of deprecated features that should be phased out. Although these deprecated features aren’t immediately disabled, they won’t be supported in future SQL Server versions. Ideally, you should start removing them from your code now to avoid potential issues during&#8230; <br /> <a class="read-more" href="https://theserogroup.com/sql-server/tracking-deprecated-features-in-sql-server/">Read more</a></p>
<p>The post <a href="https://theserogroup.com/sql-server/tracking-deprecated-features-in-sql-server/">Tracking Deprecated Features in SQL Server</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>With each new release of SQL Server, we gain exciting new features—but also face the reality of deprecated features that should be phased out. Although these deprecated features aren’t immediately disabled, they won’t be supported in future SQL Server versions. Ideally, you should start removing them from your code now to avoid potential issues during future upgrades.</p>



<p><em>Ideally. &nbsp;</em></p>



<p>But let&#8217;s be honest—how often does that happen? Even if you’re committed to staying current, finding out which deprecated features are still in use can be a challenge. Fortunately, SQL Server tracks this information for you. Simply run the following query against&nbsp;<em><a href="https://msdn.microsoft.com/en-us/library/ms187743.aspx" target="_blank" rel="noreferrer noopener">sys.dm_os_performance_counters</a></em>&nbsp;to get a list of deprecated features and how many times each of them has been used.</p>



<pre class="wp-block-code"><code>SELECT  object_name, instance_name, cntr_value
FROM	sys.dm_os_performance_counters
WHERE   counter_name = 'Usage'</code></pre>



<p>According to the MSDN doc on the <a href="https://msdn.microsoft.com/en-us/library/bb510662(v=sql.120).aspx" target="_blank" rel="noreferrer noopener">Deprecated Features Object</a>, doing this:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p><em>provides a counter to monitor the features designated as deprecated. In each case the counter provides a usage count that lists the number of times the deprecated feature was encountered since SQL Server last started.</em></p>
<cite>Microsoft SQL Server, Deprecated Features object</cite></blockquote>



<p>(That MSDN doc also has a description of what each of the deprecated features is, which is very useful.)</p>



<p>While this won’t tell you&nbsp;<em>where</em>&nbsp;a deprecated feature is being used, it will tell you&nbsp;<em>which ones</em>&nbsp;are being used.&nbsp;Knowing which deprecated features are still in use is crucial when planning a migration to a new SQL Server release, especially if those features will no longer be supported. This insight helps prevent disruptions and ensures a smoother transition to the updated system.</p>



<h2 class="wp-block-heading" id="h-want-to-work-with-the-sero-group">Want to work with The SERO Group?</h2>



<p>Want to learn more about how The SERO Group helps organizations take the guesswork out of managing their SQL Servers? <a href="https://theserogroup.com/contact-us/" target="_blank" rel="noreferrer noopener">Schedule a no-obligation discovery call</a>&nbsp;with us to get started.</p>
<p>The post <a href="https://theserogroup.com/sql-server/tracking-deprecated-features-in-sql-server/">Tracking Deprecated Features in SQL Server</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">6472</post-id>	</item>
		<item>
		<title>A Manual Adjustment: Compatibility Level Settings in SQL Server</title>
		<link>https://theserogroup.com/sql-server/a-manual-adjustment-compatibility-level-settings-in-sql-server/</link>
		
		<dc:creator><![CDATA[Eric Cobb]]></dc:creator>
		<pubDate>Wed, 24 Jul 2024 12:00:00 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Database Administration]]></category>
		<category><![CDATA[Database Development]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server Management]]></category>
		<guid isPermaLink="false">https://theserogroup.com/?p=6344</guid>

					<description><![CDATA[<p>A database on a specific SQL Server version doesn&#8217;t automatically have all features enabled. For example, a database on SQL Server 2019 can still use SQL Server 2014 compatibility, missing some 2019 features. Each database has a Compatibility Level setting that activates certain features of its version. When SQL Server 2014 introduced the Cardinality Estimator,&#8230; <br /> <a class="read-more" href="https://theserogroup.com/sql-server/a-manual-adjustment-compatibility-level-settings-in-sql-server/">Read more</a></p>
<p>The post <a href="https://theserogroup.com/sql-server/a-manual-adjustment-compatibility-level-settings-in-sql-server/">A Manual Adjustment: Compatibility Level Settings in SQL Server</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>A database on a specific SQL Server version doesn&#8217;t automatically have all features enabled. For example, a database on SQL Server 2019 can still use SQL Server 2014 compatibility, missing some 2019 features.</p>



<p>Each database has a Compatibility Level setting that activates certain features of its version. When SQL Server 2014 introduced the Cardinality Estimator, you could disable it by setting the Compatibility Level to SQL Server 2012. For a full list of enabled features at each level, see the <a href="https://docs.microsoft.com/en-us/sql/t-sql/statements/alter-database-transact-sql-compatibility-level" target="_blank" rel="noreferrer noopener">Differences Between Compatibility Level sections of the MSDN Docs</a>.</p>



<p>Unfortunately, most people don&#8217;t realize that updating the compatibility level setting is a manual process. SQL Server won&#8217;t automatically match the database compatibility level to the server version. This also applies when upgrading an existing SQL Server. It&#8217;s actually very common to see databases on newer servers with older compatibility levels.</p>



<h2 class="wp-block-heading" id="h-the-one-exception-to-this-rule">The one exception to this rule</h2>



<p>When migrating a database to a new server, SQL Server automatically upgrades the database’s compatibility level to the lowest version supported by the new server. For example, a database with SQL Server 2005 compatibility will be upgraded to 2008 when restored on SQL Server 2019, as 2008 is the earliest version supported by SQL Server 2019.</p>



<h2 class="wp-block-heading" id="h-how-can-i-find-my-database-s-compatibility-level">How can I find my database’s compatibility level?</h2>



<p>Find the compatibility level for you database by querying the <a href="https://docs.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-databases-transact-sql" target="_blank" rel="noreferrer noopener">sys.databases</a> DMV.</p>



<pre class="wp-block-code"><code>-- Find Compatibility Level for all databases on the server
SELECT name, compatibility_level  
FROM sys.databases; 
 </code></pre>



<p>You can also view the compatibility level under Options in the Database Properties:</p>



<figure class="wp-block-image size-full"><a href="https://theserogroup.com/wp-content/uploads/2024/07/image-1.png"><img fetchpriority="high" decoding="async" width="691" height="204" src="https://theserogroup.com/wp-content/uploads/2024/07/image-1.png" alt="" class="wp-image-6345" srcset="https://theserogroup.com/wp-content/uploads/2024/07/image-1.png 691w, https://theserogroup.com/wp-content/uploads/2024/07/image-1-300x89.png 300w" sizes="(max-width: 691px) 100vw, 691px" /></a></figure>



<h2 class="wp-block-heading" id="h-how-do-i-change-my-database-s-compatibility-level">How do I change my database’s compatibility level?</h2>



<p>To change your database compatibility level, simply change the Property above. You can also run the following ALTER DATABASE command:</p>



<pre class="wp-block-code"><code>--change compatibility level to 2019 for your database
ALTER DATABASE &#91;YourDatabase]
SET COMPATIBILITY_LEVEL = 150;  
GO</code></pre>



<p>Notice that the compatibility level setting in the ALTER DATABASE command is actually a numerical value. As seen in the database properties screenshot above, each compatibility level has a numerical value assigned to it, and that is what we use in the database settings. Be sure to check this list of <a href="https://docs.microsoft.com/en-us/sql/t-sql/statements/alter-database-transact-sql-compatibility-level" target="_blank" rel="noreferrer noopener">Supported Compatibility Level Values</a> for the version of SQL Server you are running.</p>



<h2 class="wp-block-heading" id="h-want-to-work-with-the-sero-group">Want to work with The SERO Group?</h2>



<p>Want to learn more about how The SERO Group helps organizations take the guesswork out of managing their SQL Servers? <a href="https://theserogroup.com/contact-us/" target="_blank" rel="noreferrer noopener">Schedule a no-obligation discovery call</a>&nbsp;with us to get started.</p>
<p>The post <a href="https://theserogroup.com/sql-server/a-manual-adjustment-compatibility-level-settings-in-sql-server/">A Manual Adjustment: Compatibility Level Settings in SQL Server</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">6344</post-id>	</item>
		<item>
		<title>Quick Tips for Faster SQL Servers: When (Not) to Use NOLOCK</title>
		<link>https://theserogroup.com/sql-server/quick-tips-for-faster-sql-servers-when-not-to-use-nolock/</link>
		
		<dc:creator><![CDATA[Eric Cobb]]></dc:creator>
		<pubDate>Wed, 17 Jul 2024 12:00:00 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Database Administration]]></category>
		<category><![CDATA[Database Development]]></category>
		<category><![CDATA[SQL]]></category>
		<guid isPermaLink="false">https://theserogroup.com/?p=6324</guid>

					<description><![CDATA[<p>Many developers mistakenly use WITH (NOLOCK) in their SELECT statements without fully understanding its effects. While they might aim to speed up queries or prevent deadlocking, NOLOCK can actually lead to invalid results. What does NOLOCK do? A SELECT statement in SQL Server locks data to prevent modifications during querying. The lock is released after&#8230; <br /> <a class="read-more" href="https://theserogroup.com/sql-server/quick-tips-for-faster-sql-servers-when-not-to-use-nolock/">Read more</a></p>
<p>The post <a href="https://theserogroup.com/sql-server/quick-tips-for-faster-sql-servers-when-not-to-use-nolock/">Quick Tips for Faster SQL Servers: When (Not) to Use NOLOCK</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Many developers mistakenly use WITH (NOLOCK) in their SELECT statements without fully understanding its effects. While they might aim to speed up queries or prevent deadlocking, NOLOCK can actually lead to invalid results.</p>



<h2 class="wp-block-heading" id="h-what-does-nolock-do">What does NOLOCK do?</h2>



<p>A SELECT statement in SQL Server locks data to prevent modifications during querying. The lock is released after the query finishes, allowing data changes to resume. These locks ensure SELECT statements return only valid data, not data that&#8217;s in the process of being modified.</p>



<p>Using NOLOCK in your query removes data protection safeguards. It&#8217;s the same as setting the <a href="https://msdn.microsoft.com/en-us/library/ms173763.aspx">Transaction Isolation Level</a> to READ UNCOMMITTED, which allows the query to pull in data that is in the process of being modified and has not been committed to the database yet. In SQL Server terms, this is called a &#8220;Dirty Read&#8221; and should not be trusted. With a Dirty Read, the data returned by your query may or may not exist, depending on the outcome of other T-SQL statements that may be running at the same time.</p>



<p>In most cases within a transactional (OLTP) database, the results from a SELECT statement using NOLOCK should not be relied upon for accuracy. However, there are occasional exceptions (details below).</p>



<h2 class="wp-block-heading" id="h-why-does-nolock-make-my-query-faster">Why Does NOLOCK Make My Query Faster?</h2>



<p>Too often, NOLOCK is used as the &#8220;turbo-boost&#8221; button for your queries. While it&#8217;s true that a SELECT query will run faster when using NOLOCK, it does so by ignoring the safeguards put in place to ensure that your query is returning accurate data. By not putting these locks in place, you reduce the overhead of the query and bypass part of the process SQL Server normally uses when processing your query, thereby making it run faster.</p>



<p>However, some of the side effects of using NOLOCK include missing rows, reading rows twice, reading multiple versions of the same row, and returning rows that have been deleted. </p>



<p><strong>What&#8217;s the point in having a faster query if it doesn’t return the correct results?</strong></p>



<h2 class="wp-block-heading" id="h-when-should-i-use-nolock">When should I use NOLOCK?</h2>



<p>NOLOCK can be useful when querying data that doesn’t change often, or in the case of an analytical (OLAP) database where data writing only occurs during a scheduled time, like a data warehouse that only runs INSERT/UPDATE/DELETE statements at night and where users do reporting during the day.</p>



<p>For example, think about a &#8220;States&#8221; table that just contains a list of US states. The list isn&#8217;t going to change, and you won&#8217;t have to worry about that data being modified while you&#8217;re querying it. In a case like this, using NOLOCK shouldn&#8217;t cause any issues.</p>



<p>Alternatively, there are situations where your query can accept certain inconsistencies. For instance, when querying sales trends over the last 6 months, real-time precision may not be necessary.</p>



<p>The main advantage of using NOLOCK is that you can avoid deadlocks with concurrent queries. However, frequent deadlocks may indicate that using NOLOCK will return incorrect results.</p>



<h2 class="wp-block-heading" id="h-avoid-nolock-to-maintain-data-consistency-and-integrity">Avoid NOLOCK to Maintain Data Consistency and Integrity</h2>



<p>You should rarely, if ever, use NOLOCK in a transactional database. You certainly shouldn&#8217;t be using it blindly in all of your SELECT queries. If you can tolerate some data inaccuracy in your results, then NOLOCK may be OK. Overall, I&#8217;d still recommend prioritizing data integrity by steering clear of NOLOCK.</p>



<h2 class="wp-block-heading" id="h-want-to-work-with-the-sero-group">Want to work with The SERO Group?</h2>



<p>Want to learn how SERO Group simplifies SQL Server management? <a href="https://theserogroup.com/contact-us/">Schedule a no-obligation discovery call</a> to get started.</p>
<p>The post <a href="https://theserogroup.com/sql-server/quick-tips-for-faster-sql-servers-when-not-to-use-nolock/">Quick Tips for Faster SQL Servers: When (Not) to Use NOLOCK</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">6324</post-id>	</item>
		<item>
		<title>Quick Tips for Faster SQL Servers: Don&#8217;t Name Your Stored Procedures Using The &#8220;sp_&#8221; Prefix</title>
		<link>https://theserogroup.com/sql-server/quick-tips-for-faster-sql-servers-dont-name-your-stored-procedures-using-the-sp_-prefix/</link>
		
		<dc:creator><![CDATA[Eric Cobb]]></dc:creator>
		<pubDate>Tue, 02 Jul 2024 21:23:49 +0000</pubDate>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Database Administration]]></category>
		<category><![CDATA[Database Development]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server Management]]></category>
		<guid isPermaLink="false">https://theserogroup.com/?p=6113</guid>

					<description><![CDATA[<p>A common mistake database developers make in SQL Server is naming their stored procedures with the &#8220;sp_&#8221; prefix. Organizations sometimes even adopt this as a standard convention (along with the &#8220;tbl_&#8221; prefix for tables!). So, why is this considered a bad practice? It&#8217;s inefficient. The &#8220;sp_&#8221; prefix is used by SQL Server to designate internal&#8230; <br /> <a class="read-more" href="https://theserogroup.com/sql-server/quick-tips-for-faster-sql-servers-dont-name-your-stored-procedures-using-the-sp_-prefix/">Read more</a></p>
<p>The post <a href="https://theserogroup.com/sql-server/quick-tips-for-faster-sql-servers-dont-name-your-stored-procedures-using-the-sp_-prefix/">Quick Tips for Faster SQL Servers: Don&#8217;t Name Your Stored Procedures Using The &#8220;sp_&#8221; Prefix</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>A common mistake database developers make in SQL Server is naming their stored procedures with the &#8220;sp_&#8221; prefix. Organizations sometimes even adopt this as a standard convention (along with the &#8220;tbl_&#8221; prefix for tables!).</p>



<p>So, why is this considered a bad practice?</p>



<h2 class="wp-block-heading" id="h-it-s-inefficient">It&#8217;s inefficient.</h2>



<p>The &#8220;sp_&#8221; prefix is used by SQL Server to designate internal system procedures. So, whenever SQL Server sees “sp_” at the beginning of a stored procedure, it looks in the master database first. </p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<figure class="wp-block-image size-full"><a href="https://theserogroup.com/wp-content/uploads/2024/07/image.png"><img decoding="async" width="800" height="160" src="https://theserogroup.com/wp-content/uploads/2024/07/image.png" alt="" class="wp-image-6164" srcset="https://theserogroup.com/wp-content/uploads/2024/07/image.png 800w, https://theserogroup.com/wp-content/uploads/2024/07/image-300x60.png 300w, https://theserogroup.com/wp-content/uploads/2024/07/image-768x154.png 768w" sizes="(max-width: 800px) 100vw, 800px" /></a></figure>
<cite><a href="https://learn.microsoft.com/en-us/sql/t-sql/statements/create-procedure-transact-sql?view=sql-server-ver16&amp;redirectedfrom=MSDN">CREATE PROCEDURE (Transact-SQL) &#8211; SQL Server</a>, 2023, learn.microsoft.com</cite></blockquote>



<p>So, using the &#8220;sp_&#8221; prefix for a stored procedure is like giving SQL Server bad directions and then wondering what&#8217;s taking it so long.</p>



<h2 class="wp-block-heading" id="h-it-causes-conflicts-with-system-procedures-with-the-same-name">It causes conflicts with system procedures with the same name.</h2>



<p>If you accidentally named your stored procedure the same thing as one of those system procedures, SQL Server will execute the system procedure instead of your database procedure.</p>



<h2 class="wp-block-heading" id="h-it-means-taking-the-long-way-around-every-time">It means taking the long way around every time.</h2>



<p>This what SQL Server is triggered to do every time an &#8220;sp_&#8221; stored procedure is called:</p>



<ol class="wp-block-list">
<li>Stop processing in your database.</li>



<li>Jump over to the master database.</li>



<li>Scan every stored procedure.</li>



<li>Come back to your database.</li>



<li>Find and execute the procedure you were looking for in the first place.</li>
</ol>



<p>All of those steps take time. Multiplying that time by the number of stored procedures, then multiplying that by the number of times those procedures are called per day, you can end up with significantly slower performance. </p>



<h2 class="wp-block-heading" id="h-the-simple-solution">The simple solution</h2>



<p>When you avoid the &#8220;sp_&#8221; prefix, you ensure that SQL Server immediately looks in your database. This makes the procedure faster to find and execute. What&#8217;s not to like about that?</p>



<h2 class="wp-block-heading" id="h-one-exception-utility-procedures">One exception: utility procedures</h2>



<p>If you&#8217;re creating a utility procedure, like&nbsp;<a href="https://whoisactive.com/downloads/" target="_blank" rel="noreferrer noopener">sp_whoisactive</a>,&nbsp;that you intend to run everywhere, then using the &#8220;sp_&#8221; prefix can be useful. Do so sparingly and only when creating a procedure in the master database that you want to have accessible from all other databases.</p>



<h2 class="wp-block-heading" id="h-want-to-work-with-us">Want to work with us?</h2>



<p>Want to learn more about how The SERO Group helps organizations take the guesswork out of managing their SQL Servers? <a href="https://theserogroup.com/contact-us/" target="_blank" rel="noreferrer noopener">Schedule a call</a> with us to get started.</p>
<p>The post <a href="https://theserogroup.com/sql-server/quick-tips-for-faster-sql-servers-dont-name-your-stored-procedures-using-the-sp_-prefix/">Quick Tips for Faster SQL Servers: Don&#8217;t Name Your Stored Procedures Using The &#8220;sp_&#8221; Prefix</a> appeared first on <a href="https://theserogroup.com">The SERO Group</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">6113</post-id>	</item>
	</channel>
</rss>
