Search the Blog

Monday, April 25, 2022

SQL SERVER database TYPES

 

SYSTEM_DATABASESAll system databases (master, msdb, and model)
USER_DATABASESAll user databases
ALL_DATABASESAll databases
AVAILABILITY_GROUP_DATABASESAll databases in availability groups
USER_DATABASES, -AVAILABILITY_GROUP_DATABASESAll user databases that are not in availability groups
Db1The database Db1
Db1, Db2The databases Db1 and Db2
USER_DATABASES, -Db1All user databases, except Db1
%Db%All databases that have “Db” in the name
%Db%, -Db1All databases that have “Db” in the name, except Db1
ALL_DATABASES, -%Db%All databases that do not have “Db” in the name

SQL SERVER BACKUP SCRIPT ON LINUX

 BACKUP DATABASE [DMT] TO  

DISK = N'/var/opt/mssql/data/DMT.bak' 

WITH NOFORMAT, NOINIT,  NAME = N'DMT-

Full Database Backup', 

SKIP, NOREWIND, 

NOUNLOAD,  

STATS = 10

GO


SQL Server Performance Key Points

 

  • Application run slower
  • Long running queries
  • High CPU consumption
  • Inefficient memory consumption
  • Suddenly and abruptly getting slower queries
  • Lots of deadlocks
  • Frequent timeouts
  • Database log file growing continuously
  • Database backup slow or failing
  • Out of date index maintenance

SQL SERVER FUNCTION TO REMOVE CONSUCATIVE DUPLICATE CHARACTERS

 


CREATE FUNCTION REMOVE_DUPLICATE_CHAR_FROM_STRING(@val NVARCHAR(500))

RETURNS  NVARCHAR(500) 

as

begin

    DECLARE @result nVARCHAR(50);

set @result=''

    DECLARE @prev CHAR(1)

set @prev=''

    DECLARE @c CHAR(1) 

set @c=''

    DECLARE @i TINYINT 

set @i=1

    DECLARE @len TINYINT;


    SET @len = LEN(@val);

    WHILE(@i <= @len) 

begin

        SET @c = SUBSTRING(@val, @i, 1);

        IF @c != @prev 

begin

            SET @result = CONCAT(@result, @c);

            SET @prev = @c;

end

        else

begin

        SET @i = @i + 1;

end

    END 

    return  @result;

end


Translate