SansSQL: Database

Friday, October 20, 2023

Understanding the Differences: Database vs. Data Warehouse vs. Data Lake vs. Data Lakehouse

In today's data-driven world, businesses rely on various technologies to manage, analyse, and leverage their data effectively. Three key components in this data ecosystem are databases, data warehouses, and data lakes. Each serves a unique purpose and offers specific advantages. In this blog post, we'll explore the differences between these three data storage and management solutions, provide examples of when to use each, and highlight some popular tools for implementing them.

Picture Source

What is a Database?

Databases are structured, organized systems designed for efficient data storage and retrieval. They are typically used to support transactional applications and are optimized for read and write operations. Databases are ideal for managing structured data, such as customer information, inventory, and financial records.

Scenario:

Suppose you run an e-commerce website, and you need to store customer data, order details, and product inventory. In this case, you would use a relational database like MSSQL, MySQL, PostgreSQL, or Oracle to ensure data integrity and consistent transactions.

Common Database Tools:

  • MSSQL: A proprietary relational database management system developed by Microsoft.
  • MySQL: A popular open-source relational database management system.
  • PostgreSQL: Known for its extensibility and support for complex data types.
  • Oracle Database: A robust commercial database management system.

What is a Data Warehouse?

A data warehouse is designed for analytical processing and reporting. It acts as a central repository that stores data from various sources, making it easier to analyse and gain insights from historical data. Data warehouses are structured to support complex queries and reporting tools.

Scenario:

Imagine you are a retail company that wants to analyse sales data, track inventory trends, and gain insights into customer behaviour. You would consolidate data from your e-commerce platform, inventory systems, and customer relationship management (CRM) tools into a data warehouse. This allows you to run complex SQL queries and generate reports using tools like Tableau or Power BI.

Common Data Warehouse Tools:

  • Snowflake: A cloud-based data warehousing platform known for its scalability.
  • Amazon Redshift: A managed data warehouse service by AWS.
  • Google BigQuery: Google Cloud's serverless data warehouse for fast, SQL-like querying.

What is a Data Lake?

A data lake is a repository that stores vast amounts of raw data, including structured, semi-structured, and unstructured data. Data lakes are suitable for storing diverse data types, such as logs, images, videos, and more. Unlike data warehouses, data lakes allow for the storage of data without a predefined structure.

Scenario:

Suppose you're a tech company handling a massive amount of data, including user-generated content, logs, and sensor data. Storing all this information in a data lake (e.g., Amazon S3 or Azure Data Lake Storage) provides you with the flexibility to structure and analyse the data when necessary. You can use tools like Apache Spark or Hadoop to process and derive insights from the raw data.

Common Data Lake Tools:

  • Amazon S3: Amazon Web Services object storage service often used as a data lake.
  • Azure Data Lake Storage: Microsoft Azure's data lake storage solution.
  • Hadoop: An open-source framework for distributed storage and processing of large datasets.

What is a Data Lakehouse?

The data lakehouse is a relatively new concept that combines the best of data lakes and data warehouses. It aims to provide the flexibility of a data lake for storing diverse, raw data while adding structured query capabilities typically associated with data warehouses. This hybrid approach often uses technologies like Delta Lake, which adds ACID (Atomicity, Consistency, Isolation, Durability) transactions and schema enforcement to the data lake.

Scenario:

Consider a healthcare organization that needs to store a massive volume of patient data, including electronic health records, medical images, and diagnostic data. Using a data lakehouse with Delta Lake, they can ingest and store raw data from various sources and, at the same time, enforce data integrity, run complex queries, and generate reports for research and patient care.

Common Data Lakehouse Tools:

  • Delta Lake: An open-source storage layer that brings ACID transactions to data lakes.
  • Databricks: A unified analytics platform that supports Delta Lake for building data lakehouses.
  • AWS Glue: Amazon's data integration and ETL (Extract, Transform, Load) service for data lakehouse architecture.

Comparison Summary


Choosing the Right Solution

The choice between a database, data warehouse, data lake, or data lakehouse depends on the specific business needs and the nature of the data. Here's a quick summary to help you decide:

  • Use a database for structured data, transactional operations, and maintaining data integrity.
  • Opt for a data warehouse when you need to consolidate, analyse, and report on historical data for decision-making.
  • Employ a data lake when dealing with diverse, raw data types and want flexibility in structuring and processing.
  • Consider a data lakehouse when you need both flexibility and structured query capabilities, combining the best of data lakes and data warehouses.

In practice, many organizations use a combination of these solutions to meet their data storage and analysis requirements. By understanding the differences between databases, data warehouses, data lakes, and data lakehouses, you can make informed decisions and harness the full power of your data while embracing modern data management techniques.

Sunday, August 28, 2022

Connect to MySQL DB | This connector requires one or more additional components to be installed

This video describes how to connect to MySQL Database and fix an common issues with the Power BI MySQL connector  which says "This connector requires one or more additional components to be installed". 

Download link to MySQL NET Connector

Friday, August 17, 2018

Tips to Move SQL Server Database from One Server to Another - SQL Tutorial by Rajan Singh

Leading organizations always look to find different solutions for high-performance data replication and secure storage environment. One such step is to move SQL Server database from one server to its updated version. In fact, when you migrate SQL server database, it provides an opportunity to scale the organizations data ecosystem efficiently at an optimum cost.

Why should you migrate SQL server database from one server to another?
  1. Advancement in Technology: Technology advancement may be a buzzword of today but it is essential to be up-to-date when it refers to Tech-world and to stay ahead, organizations need to accommodate the innovative style of Business Intelligence and ensure agility and higher productivity. Moving database from old SQL version to the latest and advanced technology provides users with an edge over the competition. 
  2. Reduce Cost: Moving SQL server database may be time taking and expensive initially, although the costs are lowered significantly in the long run 
  3. Achieve higher ROI: One of the significant reasons to switch from a lower version to a higher version or from a different database to SQL server database is to achieve a higher rate of interest on investments. 
  4. Consolidate data: Sometimes, data is scattered across different platforms. This is specifically valid in case of mergers and acquisitions. Then consolidating data on a single platform is conducive for users and easy to maintain for SQL administrators. 
  5. Secure Storage Environment: Security is a priority for any and all database and database security is ensured through protection rules and compliances. As per the survey conducted by National Institute of Standards and Technology, SQL server is most secure and least vulnerable database and hence the most preferred Storage environment.
Key Challenges in migrating SQL Database from one server to another

Once the organization decides about migration, the Administrator has to analyze the challenges in moving the database from one platform to another. Following key challenges may create hindrance in smooth movement:
  1. SQL Database Corruption
    Moving SQL Database from one server to another may lead to database corruption. 
  2. Database backup not update
    Many times, when database gets corrupt and backups are also not up-to-date, then the administrator is unable to restore from backup.
  3. Database backup not available
    If backup is not implemented and the organization’s database gets corrupt then the chances of database recovery are next to nil unless the organization employs a reliable and performing software like Stellar Phoenix SQL Database Repair.  
  4. Cost involved in moving Database
    Moving database from one Database Management System (DBMS) to another involves cost to be incurred in deploying a new server and the cost of data migration and the cost of old server which is rendered non-functional. 

    The downtime cost is also considered. Database will remain inaccessible during database migration from one server to another. 
Methods to move SQL Server Database from one server to another
  1. Backup SQL Database and Restore to another server
    The easiest solution is to take the latest backup of database and restore on another server. However, in most cases, SQL Admins and Backup Admins are different and there are chances that backup is not up-to-date. 
  2. Create a Duplicate Database in SQL Server
    If the earlier database is using SQL database and you want to move database to a higher version, then one of the methods is to create a duplicate copy of database in SQL server. However, Admins need to have more than 100% free space. This is not a feasible option and may lead to corrupt SQL Database. 
  3. Move SQL Database to New Server
    SQL Server Management Studio enables copying database from one server to another. To proceed further, you should get acquainted with:
    1. Source Server
    2. Destination Server
    3. Use Windows Authentication
    4. Using SQL Server Authentication 
    Steps to move:
    • Go to Object Explorer and launch SQL Server Management Studio and connect with the Source Server
    • Right click on the database to select the ‘Tasks’ option and select ‘Copy Database’ option ‘Copy Database Wizard’ screen displays. 
    • Fill in the details of Source Server and select the option ‘Use Windows Authentication’ followed by User ID and Password  
    • Next, fill in the details of Destination Server, and its Windows Authentication credentials
    • Checkbox for ‘Use the SQL Management Object method’
    • Select the Database from the available options and click on Copy option. Click Next to migrate SQL database to the destination server
    • Verify MDF files and Log file path on the destination server 
    • Copy all other jobs. If the SQL Management Studio fails to copy jobs then opt for the following:
      • System Event View
      • Local Path
      • Click on Windows Event Logs followed by Next button
      • To schedule the SSIS page, Click on Run immediately
      • Complete the Wizard message displays. Tick mark this option and click on Finish to complete the process. 
  4. Stellar SQL Repair to copy SQL Server Database from one server to another
    Deploying a trustworthy software to copy SQL Server Database. One such software is Stellar Phoenix SQL Database Repair software. This software allows users to repair a corrupt SQL server database. Once you have saved the repaired database as a New or Live database, then the next step is to deploy SQL Server Management Studio or SSMS. SSMS detaches the database from the source server and attaches it to the destination server.

    Reasons to deploy Stellar software for SQL recovery before using manual method are:
    • Database may get corrupt during migration. Stellar software repairs the corrupt MDF file and ensures smooth migration
    • In case MDF files or any other associated file is not detached properly, then the SQL Database will not give appropriate results
Conclusion
Error-free Migration of SQL Server database is possible when the different files associated with SQL Database are properly detached from the Source server and attached with the Destination server. However, there are times, when Admins are unable to detach the files and if these files are not detached from the source location, there is low possibility of getting these attached at the destination. In such circumstances, the best solution is to repair the database using Stellar Phoenix SQL Database Repair, save it as New Database and then move this SQL server database from one server to another. By following this procedure, SQL Administrators can ensure error-free and smooth data migration.

Checkout the MVP’s feedback about Stellar Phoenix SQL Database Repair is available here.

About Rajan Singh 
Rajan Singh is a Sr. Technology Consultant at Stellar Data Recovery Inc. and has published several article on MS Exchange emails, IOT, APIs, bug fixing etc.

Social Media Profiles
Google Plus: https://plus.google.com/101490924635563531512

Wednesday, June 13, 2018

Trouble in Opening MDF File because it Says SQL Error 5171? - A guest Post by Andre Williams

MS SQL Server is the most widely used and deployed database server in organizations. But, there are times when the SQL Server database gets corrupted due to various reasons. Error messages like SQL Error 1571 are also frequent with SQL Server. Let’s learn more about the SQL error 1571, its reasons and solutions.

Symptoms of SQL Error 5171:
With SQL Error 5171, you may face failures while logging in to SQL Server, restoring SQL database files, creating a tempdb database, and attaching MDF files successfully to the SQL Server database. Instead you will receive an error saying – “.mdf is not a primary database file. (Microsoft SQL server 5171)”

Possible Reasons for SQL Error 5171:
MDF file saves data in the form of pages, and each page occupies space of 8KB. The initial first page is the header page containing important database details such as signature, file size, compatibility, and much more. Rest all the other pages stores the actual data.
When the header page or related page of the file does not get recognized by the SQL Server database, it results in the SQL Error 1571 as the entire MDF is not considered to be a valid file.

Solution to Fix SQL Error 5171:
There are multiple reasons due to which SQL Error 5171 occurs. Some scenarios are mentioned below with their possible fix solution.

Scenario 1:
Usage of a mirror database in MS SQL Server by a user encounters the Error 5171, when database is set online by executing ALTER DATABASE command

Scenario 2:
When the SQL Server is upgraded to a latest or newer version, there are possible chances of Error 5171. As, you will have to first detach the database and then upgrade it to the new version. Hence, when you will try to attach it back to the MS SQL Server, it will fail to do so and error 5171 might encounter.

Below mentioned are the possible solutions for this error:

Method 1: For database mirroring
Step 1: First set, the principal database
Step 2: Use ALTER DATABASE MODIFY FILE command to modify the information.
Step 3: Now, stop the SQL server instance.
Step 4: Copy MDF and LDF files in a separate directory
Step 5: Now, restart SQL Server and attach the database files

Method 2: For attaching the database
Step 1: To troubleshoot the error, use the sp_attach_db command
Step 2: The command will attach the detached database files after upgrading is completed.
Please note: This method will work only in the case where you have used the sp_detach_db command to detach the database

Method 3: Automated Method to FIX SQL Server Error 5171
The above methods can easily remove the SQL Error 5171. However, if you still face the error after trying the above workaround methods, then you can opt for the automated solution. You can use Kernel for SQL Database Recovery tool, one of the most recommended methods by the database experts. The tool smoothly repairs and recovers all the database objects of corrupt or inaccessible MDF and NDF files. It flawlessly recovers large-sized MDF and NDF files.

Final Words:
You can always opt to use the manual methods for SQL recovery if you are an experienced database professional. But if you’re a naïve user of SQL database and you are not skilled enough to understand the errors of the database, then we suggest you restore your database files with the help of the automated solution.  
Hope the solutions help you to resolve the issues related to MS SQL Server. If you have any queries, please mention in the comments. We will get back to you with a possible resolution.

About Andre Williams
Andre Williams, with more than three year's experience in SQL related technologies, contributes articles, blogs, and how-to tips regularly.

Social Media Profiles

Thursday, April 13, 2017

T-SQL to List all Permissions for a Given Role

This script lists all the permissions for a given role.

SELECT DB_NAME() AS DatabaseName
      ,DatabasePrincipals.name AS PrincipalName
      ,DatabasePrincipals.type_desc AS PrincipalType
      ,DatabasePrincipals2.name AS GrantedBy
      ,DatabasePermissions.permission_name AS Permission
      ,DatabasePermissions.state_desc AS StateDescription
      ,SCHEMA_NAME(SO.schema_id) AS SchemaName
      ,SO.Name AS ObjectName
      ,SO.type_desc AS ObjectType
  FROM sys.database_permissions DatabasePermissions LEFT JOIN sys.objects SO
    ON DatabasePermissions.major_id = so.object_id LEFT JOIN sys.database_principals DatabasePrincipals
    ON DatabasePermissions.grantee_principal_id = DatabasePrincipals.principal_id LEFT JOIN sys.database_principals DatabasePrincipals2
    ON DatabasePermissions.grantor_principal_id = DatabasePrincipals2.principal_id
WHERE DatabasePrincipals.name = 'Test' -- Change the Role Name

You can download the script from here.

Thursday, April 6, 2017

T-SQL to get Get Database Files Usage information

Here is an handy T-SQL script to get Database files usage Information
DECLARE @FreeSpaceThreshold int
SET @FreeSpaceThreshold = 20 -- Change this Threshold Value. Any number between 0 to 100

CREATE TABLE #GetDetails
( 
 ServerName nvarchar(100),
 DatabaseName nvarchar(100),
 LogicalFileName nvarchar(100),
 FileType nvarchar(10),
 FileLocation nvarchar(max),
 [FileSize(MB)] decimal (15,2),
 [UsedSpace(MB)] decimal (15,2),
 [FreeSpace(MB)] decimal (15,2),
 [UsedSpace(%)] decimal (15,2),
 [FreeSpace(%)] decimal (15,2)
 )

EXEC sp_MSforeachdb 'Use [?];
INSERT INTO #GetDetails
SELECT @@SERVERNAME AS ServerName,
    DB_NAME() AS DatabaseName,
    name AS LogicalFileName, 
    type_desc AS FileType, 
    physical_name AS FileLocation,
    CAST(size/128.0 AS decimal(15,2)) AS [FileSize(MB)],
    CAST(FILEPROPERTY(name, ''SpaceUsed'')/128.0 AS decimal(15,2)) AS [UsedSpace(MB)],
    CAST(size/128.0 AS decimal(15,2)) - CAST(FILEPROPERTY(name, ''SpaceUsed'')/128.0 AS decimal(15,2)) AS [FreeSpace(MB)],
    CAST(((FILEPROPERTY(name, ''SpaceUsed'')/128.0 ) /  (size/128.0))*100 AS decimal(15,2)) AS [UsedSpace(%)],
    CAST((((size/128.0) - FILEPROPERTY(name, ''SpaceUsed'')/128.0 ) /  (size/128.0))*100 AS decimal(15,2)) AS [FreeSpace(%)]
FROM sys.database_files'

SELECT * FROM #GetDetails Where [FreeSpace(%)] < @FreeSpaceThreshold
DROP TABLE #GetDetails

Download this script from https://gallery.technet.microsoft.com/T-SQL-to-Get-Database-f16f60c7?redir=0

Ads