Translate

Showing posts with label SQL Server. Show all posts
Showing posts with label SQL Server. Show all posts

Monday, August 30, 2021

Physical Join Operators in SQL Server

Every developer knows the Logical Operators such as Inner Join, Left Outer, Right Outer Join etc in SQL Server. 


Do you how these operators work internally. This article discusses the Internals of Physical Join Operators (Nested Loops Join, Hash Match Join & Merge Join) in SQL Server.



Thursday, April 8, 2021

Multi Language Support for SSAS


When you are asked to define the term data warehouse, You will say that it is a framework that will be used to analyse enterprise-level data If it is a framework, data warehouse user should have the option of using the data warehouse irrespective of the language that he is familiar with. 

This new article brings you how to analyse your data using multiple languages. This article explains, what are the modifications that you need to do for the SQL Server stack to incorporate multi-language into the data warehouse. 

There are multiple articles on SQL Server Analysis Service (SSAS). 

Tuesday, February 2, 2021

Dynamic Data Masking in SQL Server


Data Masking is an important aspect of data security. Though, it is not as strong as data encryption. it will provide some sort of security. The latest article on Data masking discusses the data masking in SQL Server as well as in SQL Azure. 

Please find the latest article at SQLShack in this link. 

Monday, February 1, 2021

Monitoring Long Running Transactions in TempDB

TempDB database plays a major role in SQL Server. Therefore, it is extremely important to monitor the health of the TempDB database. One of the major challenges in TempDB is maintaining it's log file. If there are transactions that use the TempDB and if those are long-running transactions, there can be situations where the log file will grow. Since these transactions are not closing, log space will not be returned and the entire server will not be able to run queries that use the TempDB. 

Recently, one of the Clients had a similar problem. One query was running for more than four days and it had consumed TempDB log file. This has caused empty disk space and the entire server is halted for operations.

In this situation, the easiest and laziest thing to do is the restart the server. Restart will kill all the transactions and return TempDB back to the original size. This is not something that you can do for a system of 24x7. 

However, we choose not to restart but to identify the long-running query from the following simple query.

SELECT  se_tr.session_id,

sec.login_name,

trn.database_transaction_begin_lsn,

trn.database_transaction_begin_time,

trn.database_transaction_log_record_count,

 trn.database_transaction_log_bytes_used,

 trn.database_transaction_log_bytes_reserved,

 t.text,

 q.query_plan

FROM sys.dm_tran_database_transactions trn

INNER JOIN sys.dm_tran_session_transactions se_tr ON trn.transaction_id = se_tr.transaction_id

INNER JOIN sys.dm_exec_sessions sec ON se_tr.session_id = sec.session_id

INNER JOIN sys.dm_exec_connections con ON con.session_id = sec.session_id

LEFT OUTER JOIN sys.dm_exec_requests req ON req.session_id = sec.session_id

CROSS APPLY sys.dm_exec_sql_text  (con.most_recent_sql_handle) t

OUTER APPLY sys.dm_exec_query_plan (req.plan_handle) q

WHERE trn.database_id =DB_ID('TempDB') 

This gave the option to identify the long running query and we killed the relevent session. With that, TempDB log file was emptied and by shrinking the tempdb log file, we were able to gain the disk space. 

Further, we took a pro-active decision by enabling an alert, so that if a query runs for more than 8 hrs (configurable) that will be altered the DBA so that he can kill the session straightway. 

Friday, January 29, 2021

SQL Server Workshops

Microsoft has provided a one-stop place for SQL Server Workshops at https://aka.ms/sqlworkshops. There are multiple categories of workshops such as SQL Server Data Platform,  Azure SQL, Programming, and Machine Learning and AI. All workshop material will be updated and you can follow them with your own pace. 
Watch the new video at Data Exposed here. 



Friday, January 15, 2021

Time Series in Microsoft SQL Server

In a previous blog post, it was said that new research was initiated in order to design and develop a framework for time series using agent technology. 

In order to proceed with the research, it was decided to perform of feature analysis in various tools such as Microsoft SQL Server, Weka, Orange, Azure Machine Learning and Rapid Data Miner. Please comment if you have better tools. 

The following figure shows the components for Microsoft SQL Server 


Microsoft SQL Server supports three types of algorithms such as ARIMA, ARTxp and Mixed. ARTxP and Mixed are supported for the cross prediction. Further, ARTxP works well for short term predictions while the ARIMA will work for long term predictions.

Fast Fourier Series is used to detect the seasonality in SQL Server. Missing values will be identified only when there are multiple time series are presented. Mean, Constant, Previous and Same curvature are the techniques used to replace the missing values. 

Further, Microsoft SQL Server has the capability of using the predicted values for further predictions.  

References

Further, every month Cheatsheet for the Time Series will be released. Please let me know your thoughts. 

Thursday, December 10, 2020

Customized Transaction Log Backups

Transaction Log backups are important in a Production environment. It will make sure that you manage your log file size and keeping backups in case of a need to restore.

I am pretty much sure, most of you have scheduled transaction log backups. If you have scheduled Transaction log backups every 15 minutes, then you will see four log backups every hour and will result in nearly 100 backup files a day and you are looking at around 700 log backups per day. Unlike differential backups, you need all your lob backups to recover. Sometimes, you might have less or no transactions but still, there will be a log backup. 

Now the question is, Can we create transaction log backup when there is sufficient size. Yes, you can if you are running SQL Server 2017 or later. 

In sys.dm_db_log_stats Dynamic Management Function (DMF), there is a new column called log_since_last_log_backup_mb tells you what is the log file size after the last log backup. 

Using the following script, you can perform transaction log backups when the log file size is more than a specific size. 

DECLARE @log_since_last_log_backup_mb NUMERIC(9, 2)
DECLARE @ThreasholdSize INT = 25
DECLARE @folderName VARCHAR(30) = 'D:\DBBACKUP'
DECLARE @DatabaseName VARCHAR(30) = 'LB1'

SELECT @log_since_last_log_backup_mb = log_since_last_log_backup_mb
FROM sys.dm_db_log_stats(db_id(@DatabaseName))

IF @log_since_last_log_backup_mb > @ThreasholdSize
BEGIN
   DECLARE @fileName NVARCHAR(400) = @folderName + '\' + 
   @DatabaseName + SUBSTRING(REPLACE(CONVERT(VARCHAR, GETDATE(), 111), '/', '') 
   + REPLACE(CONVERT(VARCHAR, GETDATE(), 108), ':', ''), 0, 13) + '.bak'

	BACKUP LOG [LB1] TO DISK = @fileName
	WITH NOFORMAT
		,NOINIT
		,SKIP
		,NOREWIND
		,NOUNLOAD
		,STATS = 10
END
ELSE
	PRINT 'No BACKUP'

Monday, November 16, 2020

Data Migration Service from Google

 According to Gartner, 75% of databases will be in the Cloud by 2023. Since we are not very far away from 2023, as organizations we need to look at the possibilities of Cloud Databases. One of the greater challenges will be data migrations. As we know, organizations have a lot of data already. To Cloud Databases to become a success story, you need mechanisms and techniques to migrate your data to cloud databases.


In that view, Google Cloud has launched new Data Migration Service (DMS). Currently DMS available in Preview in which customers can migrate MySQL, PostgreSQL, and SQL Server databases to Cloud SQL from on-premises environments or other clouds.

Customers can start migrating with DMS at no additional charge for native like-to-like migrations to Cloud SQL. Support for PostgreSQL is currently available for limited customers in Preview, with SQL Server coming soon.

You can read more details at

https://www.zdnet.com/article/google-cloud-launches-data-migration-service-to-land-database-workloads/

https://datacenternews.asia/story/google-cloud-launches-new-data-migration-service

Thursday, October 8, 2020

What is the Best Database

If someone asks you "What is the best database", what is your answer. Answers might be different depending on your job role, whether you are a developer or a database administrator or client.

However, there is a ranking done for the database every month and the following is the latest ranking of databases. 


You can look at the rank of all the 359 databases here. According to this ranking, first six databases, Oracle, MySQL, Microsoft SQL Server, PostgreSQL, MongoDB, IBM BD2 are remaining the same compare to the last year.  If you look at the entire list you will find that Azure SQL Server Database is a major improvement. Azure SQL Server Database ranked 17 this year where it was 25th in last year.  

Let us look at the trending of these databases. 


You can see that MySQL and Oracle are running closers whereas PostgreSQL and MongoDB are running a close encounter. 
This does not say one database is better than others. This ranking based on various factors, such as Number of mentions of the system on websites, Frequency of technical discussions about the system, Number of job offers, in which the system is mentioned, Number of profiles in professional networks, in which the system is mentioned, and Relevance in social networks etc. You can look at the complete ranking parameters here.

Monday, October 5, 2020

Data Mining in SQL Server

Data Mining or Prediction has become a buzz word not only in academia but also in the industry as well. SQL Server is providing a rich set of algorithms to support data Mining for a long time. However, most of these features are not used due to many reasons. The following article series which I completed at sqlshack provides details of how to use data mining in SQL Server. The major important advantage is that you can use the existing data in the SQL Server with the Data Mining itself. Further, you have to option of using MS BI family for data mining. 

Enjoy the article series here. 

Introduction to SQL Server Data Mining
Naive Bayes Prediction in SQL Server
Microsoft Decision Trees in SQL Server
Microsoft Time Series in SQL Server
Association Rule Mining in SQL Server
Microsoft Clustering in SQL Server
Microsoft Linear Regression in SQL Server
Implement Artificial Neural Networks (ANNs) in SQL Server
Implementing Sequence Clustering in SQL Server
Measuring the Accuracy in Data Mining in SQL Server
Data Mining Query in SSIS
Text Mining in SQL Server

40 Kms Journey to Create an Index

 A client called and they had a slow system. Their complain was very simple.

They are a garment production company. Those garment items are flowing in a belt and there are workers who have a task of swiping the picked item to the bar code reader. Their complaint was that it takes more than 5 secs to read one production item. Their experience is that at the start of the season, this was around 1-2 seconds. When this is taking more than 5 seconds, they archived the data to solve the issue. However, they are looking at a permanent solution as this has been troubling them for a while.  

Well, by the looks of it is very obvious that issue is an index. However, it was difficult to convince the customer, mainly client was not able to identify what is the index he should apply. Well, then it is decided to make the physical appearance by driving 40 kilometres.

At the client site, it took only ten minutes to find the troublesome query. SQL Profiler was initiated while asking the users to continue with the normal operations. The query was identified from the profiler and verified it by running it in the SQL Server Management Studio as in the query plan CX_PACKET was identified.

Then the index was applied to cover the where clause condition as it had only one column in the where clause. Well, 5 seconds was reduced to almost zero seconds making users very happy as they can earn more as an extra bonus.

The index is the most common problem in the database systems. However, the art of the index is identifying and creating them. It is something that needs a bit of experience. 

If you need more details on Index read this article. Further, if you need more details on CXPACKET, this is the article. 

Sunday, October 4, 2020

Recover from a Data Disaster – Point in Time Recovery Method

If you are a database administrator, you will never know when your database hit a disaster. When the disaster hit your database, you will be in a panic mode and you will take action which you won't take in modest conditions. However, we need to plan for a disaster. This article provides you with the importance of Point in Time Recovery Method in order to recover data.

This is a fantastic feature in databases but you will not realize how valuable this until you come across this situation. Leaving describing these features to separate time, let us first look at two cases. Incidentally, these two incidents occurred in one organization and moreover for one database but at different times.

Incident #1:  A developer was connected to both production and development instances of databases from one SQL Server Management Studio (SSMS) instance. If you have work with SSMS, you would understand how risky this is. If not, this incident tells you how risky it is. The DBA thinking that she is working on the developer instance has deleted data in a customer table in Production.

Incident #2: In the same organization, they decided to increase the column length to 50 from 15. This column is a critical column to the business. They increased the size of the column using the design view from a table. Guess what, before typing the 0, after removing the 1 the user has saved the designed, which had resulted in the truncation of the table column to 5 from 15 with a data loss!!

Action: In both cases, we were to help. The first question was “What is the recovery model?” if it is Simple, then nothing that we could do as Simple recovery model does not keep the transaction log history and nothing can be recovered. In these scenarios, the recovery model is Full means that we can recover data to a point of time. In this mechanism, we can recover to a given time. So, we got the full back up of database and restored to a different database instance with the recovery option on. Then we got a log backup and restored on top of the previously restored database with specifying a time which is just before the disaster recovery. After the database is restored fully, customer table and the other tables were transferred to the production database.

Lesson Learnt:
  • ·  Never connect to multiple databases instances from SSMS. Especially, with production and other database instances.
  • ·  Never use the SSMS designer, to modify the database schema. Always use scripting for schema design changes. 
  • ·  Always, use the Full recovery model for production.

  • If you need more details, read the article written by me at sqlshack. Further, you can use Log shipping to avoid data disasters as discussed in the latest article. 

Tuesday, May 30, 2017

SQL Server Sizing Guide

This document can be used when configuring hardware for physical and virtual SQL servers. It should be used as a guideline, with actual configuration depending on size of databases, reports, and types of usage.

Read more at http://www.ceservices.com/sites/default/files/resources/docs-protected/CES_SQLServerSizing.pdf


Wednesday, May 17, 2017

Best Practices for SQL Server Deployment in Healthcare

Though this article is specific about SQL Server security in health care,  we can apply the same principals for other environments as well,

Read more at http://healthitsecurity.com/news/best-practices-for-sql-server-deployment-in-healthcare

Monday, January 9, 2017

DB-Engines Ranking


It is very common to compare the databases for marketing or for fun. http://db-engines.com/en/ranking has done the ranking for the database engine.


SQL Server has the major gain while Oracle has the major slip though it is still gaining the number one position. Following is the trend for the ranking of Database Engine. 



Tuesday, November 29, 2016

Redgate Announces New SQL Server Database Cloning Tool

Redgate, a Cambridge-UK based software company that develops SQL Server tools, has launched the beta of its new database cloning tool called SQL Clone that enables databases to be cloned quickly, while saving up to 99% of disk space.
According to the company, the new technology resolves a long-standing issue in software development. Typically, this involves database administrators having to provision a copy of the database for each developer request, which takes up valuable time as well as disk space. The result is that teams end up working on outdated versions of the database in a shared environment, rather than having the freedom to work on isolated local versions that can be created and deleted rapidly.
Read more http://www.dbta.com/Editorial/News-Flashes/Redgate-Announces-New-SQL-Server-Database-Cloning-Tool-114985.aspx

Thursday, November 17, 2016

Microsoft announces the next version SQL Server for Windows and Linux



Microsoft’s announcement that it was bringing its flagship SQL Server database software to Linux came as a major surprise when the company first announced this in March. Until now, the preview was invite-only, but as Microsoft announced today, anybody who wants to give it a try can now download the bits. That public preview is part of the launch of the next version of SQL Server, which will be the first one that’s available for both Windows and Linux.

Read more at https://techcrunch.com/2016/11/16/microsofts-sql-server-for-linux-is-now-available-for-testing/

Tuesday, June 21, 2016

Demand for SQL Server Skills in India

India’s Information Technology sector is regarded as the biggest private sector employer, with over 10 million employees across India. Talent assessment platform Youth4work has announced its findings about the top five desired skill sets in the Indian IT sector. ASP.net is the most in-demand skill set in the IT sector followed by SQL Server, PHP, Advance Java and JavaScript.



Here are the salary comparison for SQL Server in India. 


Monday, June 20, 2016

Discontinued Database Engine Functionality in SQL Server 2016

Major discontinued feature of the SQL Server 2016 feature is that exclusion of 32 bit of the SQL Server. So now on, you have only 64 bit version.

Only other discontinued feature is, as usual dropping of the 3rd before compatible level which is 90 or SQL Server 2005.

-https://msdn.microsoft.com/en-us/library/ms144262.aspx

However, even in SQL Server 2014, 90 compatible level which is also an discontinued feature.

https://msdn.microsoft.com/library/ms144262(v=sql.120)

I don't understand the possibility of discontinuing a feature which is already discontinued. Typically Microsoft keeps three versions of backward compatibility. however, in SQL Server 2016 , 4 previous versions of backward compatibility is kept as shown below.