Skip to main content

Posts

Showing posts from March, 2024

A Guide to MySQL General Query Logging - (Similar to MSSQL profiler)

  Setting Up MySQL General Logging Unlocking Insights: A Guide to MySQL General Query Logging In the bustling world of databases, monitoring query activities is paramount for optimizing performance, troubleshooting issues, and ensuring robust security. MySQL, one of the most popular database management systems, offers a powerful feature called General Query Logging, which allows you to capture detailed information about every query executed within your MySQL instance. In this guide, we'll walk you through setting up and leveraging MySQL General Query Logging to unlock valuable insights into your database activities. Setting the Stage: Creating the Logging Table To begin our journey, we'll create a dedicated table to store the logged query activities. Execute the following SQL script to create the mysql.general_log table: sql CREATE TABLE mysql.general_log ( event_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP , user_host mediumtext N

Removing HTML Tags from Text Using SQL Server User-Defined Function

  Introduction: In this blog post, we'll explore how to create and use a SQL Server User-Defined Function (UDF) to remove HTML tags from a text string. This function can be handy when you need to extract plain text from HTML content stored in your database. Creating the Function: First, let's create the SQL Server UDF named udf_StripHTML . This function takes a VARCHAR(MAX) parameter @HTMLText , which represents the HTML content from which we want to remove the tags. It returns a VARCHAR(MAX) value, representing the text stripped of HTML tags. sql SET QUOTED_IDENTIFIER ON GO  CREATE FUNCTION [dbo].[udf_StripHTML] ( @HTMLText VARCHAR (MAX)) RETURNS VARCHAR (MAX) AS BEGIN DECLARE @Start INT   DECLARE @End INT   DECLARE @Length INT   SET @Start = CHARINDEX( '<' , @HTMLText )  SET @End = CHARINDEX( '>' , @HTMLText , CHARINDEX( '<' , @HTMLText ))  SET @Length = ( @End - @Start ) + 1   WHILE @Start > 0 AND @End &g