Posts

Showing posts with the label SQL Server

Azure SQL Managed Instance

Image
 Azure SQL Managed Instance is the intelligent, scalable cloud database service that combines the broadest SQL Server database engine compatibility with all the benefits of a fully managed and evergreen platform as a service. Azure SQL database and Azure SQL Managed Instance are PaaS SQL Managed Instance provides support for instance-scoped features enabling easy migration of existing applications, as well as sharing resources among databases With SQL Managed Instance, confidently modernize your existing apps at scale by combining your experience with familiar tools, skills and resources and do more with what you already have. Azure SQL Managed Instance Connection String Server=test-azuresqlmanagedinstance-demo.public.43eb3ae38165.database.windows.net,3342;Persist Security Info=False; User ID=demouser;Password=demouser#1234;MultipleActiveResultSets=False; Encrypt=True;TrustServerCertificate=False;Connection Timeout=30; If you enable Public end point then we can access SQL Managed I...

What is Contained DataBase?

SQL Server 2012 Onwards we have a new solution termed as contained database. Contained database is defined as a database which has the database user without logins. It includes all settings related to databases along with its metadata, thus system will be having no dependency with SQL server login. Users can easily connect to a contained database without having to go through the log in at DB engine. Contained database feature provides two containment modes: None – By default each database has its mode set as NONE. This means there is no contained database feature being used. Partial – With partially contained databases, we can define boundaries between databases and the server, so the metadata will exist inside the databases. It makes SQL Server databases more portable and less dependent on underlying hosts.  A contained database is a database that is isolated from other databases and from the instance of SQL Server that hosts the database Isolated from other databases Isolated fro...

SQL SERVER global variables and Functions

SQL SERVER global variables and Functions like @@ROWCOUNT, SCOPE_IDENTITY, DBCC CHECKIDENT, IDENTITY_INSERT @@ROWCOUNT:- It returns the total number of rows affected in the last operation .i.e. SELECT/INSERT/UPDATE/DELETE SCOPE_IDENTITY: It returns the last value of the identity column of any table in the current session and the current scope. It must be referred immediately after INSERT, SELECT INTO, or bulk copy statement is completed or after an INSERT TRIGGER to get the correct value. @@IDENTITY: It returns the last value of the identity column of any table in the current session, across all scopes. Failed statements and transactions can change the current identity for a table and create gaps in the identity column values. The identity value is never rolled back even though the transaction that tried to insert the value into the table is not committed. IDENT_CURRENT: It returns the last value of the identity column for a specific table in any session and any scope. It wor...

Top 5 excellent features in SQL Server 2016

SQL server 2016 provides several features that helps to increase the performance, security, simplify the maintenance and data transformation.  1. Always encrypted This feature helps to encrypt only specific columns instead of whole database.  Data are encrypted always i.e both in rest and in motion. It helps to avoid man-in-middle attacks. To use this feature , the connection string in the client application should include the attribute Column Encryption Setting = enabled; 2. JSON Support JSON stands for Java Script Object Notation. SQL server has a built in JSON support which helps to parse relational data into JSON formatted data and also vice versa.  To export relational data into JSON, simply include FOR JSON [ auto | path] 3. Dynamic data Masking Helps to provide security to our data. We can choose, 1. default masking : For masking full data 2. partial masking : For masking part of the data 3. email masking : For retaining email format 4. random maskin...

Splitting string in SQL Server

For sql server 2016 before, Try to create user defined function like below and use it CREATE FUNCTION [dbo].[SplitString] (  @Input NVARCHAR(MAX), @Character CHAR(1) ) RETURNS @Output TABLE ( Item NVARCHAR(1000) ) AS BEGIN DECLARE @StartIndex INT, @EndIndex INT SET @StartIndex = 1 IF SUBSTRING(@Input, LEN(@Input) - 1, LEN(@Input)) <> @Character BEGIN SET @Input = @Input + @Character END WHILE CHARINDEX(@Character, @Input) > 0 BEGIN SET @EndIndex = CHARINDEX(@Character, @Input) INSERT INTO @Output(Item) SELECT SUBSTRING(@Input, @StartIndex, @EndIndex - 1) SET @Input = SUBSTRING(@Input, @EndIndex + 1, LEN(@Input)) END RETURN END SELECT * FROM [SplitString]('John,Jeremy,Jack',',') You can use the below statement for split the string in sql. It is available in 2016 onwards SELECT * FROM STRING_SPLIT(' John,Jeremy,Jack ',',')

Splitting String in SQL Server

SQL SERVER 2016 SELECT * FROM STRING_SPLIT('John,Jeremy,Jack',',') STRING_SPLIT is built - in - function sql server 2016 and you can directly use it. I f SQL SERVER is Below 2016 then Write user defined function which returns tabular value like below CREATE FUNCTION [dbo].[SplitString] (           @strString NVARCHAR(MAX),       @splitCharacter CHAR(1) ) RETURNS @Output TABLE (       Item NVARCHAR(1000) ) AS BEGIN       DECLARE @StartIndex INT, @EndIndex INT       SET @StartIndex = 1       IF SUBSTRING(strString , LEN(strString ) - 1, LEN(@strString)) <> @splitCharacter        BEGIN             SET @strString = @strString + @splitCharacter        END       WHILE CHARINDEX(@splitCharacter  @strString) > 0       BEGIN...