- SET STATISTICS IO
- SET STATISTICS TIME
- Parser
- Biding
- Execution Plan Generation
- OPtimization
- Components of the Execution Plan
- Ageing of the Execution Plan
- Analysing the Execution Plan Cache
- Execution Plan Reuse
- AdHoc Workload
- Optimize for an AdHoc Workload
- Froced Parmeterization
- Benefites of Stored Procedures
- sp_executesql
- Parameter Sniffing
- Query Plan Hash and Query Hash
- Execution Plan Cache Recommendations
- Actual Vs. Estimated Execution Plans
Sunday, June 28, 2020
SQL Server Performance Tuning and Query Optimization guidelines
SQL Server Database Design guidelines
- Balance Under-and-Over normalization
- Benefiting from Entity-Integrity Constraints
- Benefiting from Domain and Referential Integrity Constraints
- Adopting Index-Design Best Practices
- Avoiding the use of the sp_Prefix fpr Stored Procedure Names
- Minimizing the use of Triggers
SQL Server Query Design guidelines
- SET NOCOUNT ON
- Explicitly Define the Owner of an Object
- Avoid Non-sargable Search Condition
- Avoid Arithmatic Expression on the WHERE Clause Column
- Avoid Optimizer Hints
- Stay away from Nesting Views
- Ensure No Implicit Data Type Conversions
- Minimize Logging Overhead
- Adopt Best Practices for Reusing Execution Plans
- Adopt Best Practices for Database Tranactions
- Eliminate or Reduce the Overhead of Database Cursors
Performance Killer in SQL Server
- Poor Indexing
- Inaccurate Statistics
- Poor Query Design
- Poor Executaion Plans (usually caused by bad parameter sniffing)
- Excessive blocking and deadlocks
- Non set based operations (usually T-SQL cursors)
- Poor Database Design
- Excessive Fragmation
- Nonreusable Execution plans
- Frequnt recompilation of queries
- Improper configuration of the database log
- Improper usages of cursor
- Excessive or improper configuration of tempdb
Tuesday, June 16, 2020
SQL Server Versions, Editions and Database size capacity
First you see which SQL Server you used
SQL Server is available in various editions. This chapter lists the multiple editions with its features.
-
Enterprise − This is the top-end edition with a full feature set.
-
Standard − This has less features than Enterprise, when there is no requirement of advanced features.
-
Workgroup − This is suitable for remote offices of a larger company.
-
Web − This is designed for web applications.
-
Developer − This is similar to Enterprise, but licensed to only one user for development, testing and demo. It can be easily upgraded to Enterprise without reinstallation.
-
Express − This is free entry level database. It can utilize only 1 CPU and 1 GB memory, the maximum size of the database is 10 GB.
-
Compact − This is free embedded database for mobile application development. The maximum size of the database is 4 GB.
-
Datacenter − The major change in new SQL Server 2008 R2 is Datacenter Edition. The Datacenter edition has no memory limitation and offers support for more than 25 instances.
-
Business Intelligence − Business Intelligence Edition is a new introduction in SQL Server 2012. This edition includes all the features in the Standard edition and support for advanced BI features such as Power View and PowerPivot, but it lacks support for advanced availability features like AlwaysOn Availability Groups and other online operations.
-
Enterprise Evaluation − The SQL Server Evaluation Edition is a great way to get a fully functional and free instance of SQL Server for learning and developing solutions. This edition has a built-in expiry of 6 months from the time that you install it.
Now see the mostly used SQL Server database size capacity as per Editions.
SQL Server Enterprise Edition - 524 PB
(PetaByte)
SQL Server Standrad Edition - 524 PB (PetaByte)
SQL Server BI Edition - 524 PB (PetaByte)
SQL Server Express Edition - 10 GB (GigaByte)
SQL Server Enterprise Evalution Version Period for - 180 days
Now see the Evaluation version Create Date and Expiry Date.
SELECT create_date AS 'Installation Date', DATEADD(DD, 180, create_date) AS 'Expiry Date'
FROM sys.server_principalsWHERE NAME = 'NT AUTHORITY\SYSTEM'Now see the Developer version Create Date and Expire Date.
DECLARE @edition SQL_VARIANT
SELECT @edition = SERVERPROPERTY('Edition')IF (@edition = 'Enterprise Evaluation Edition' OR
@edition = 'Enterprise Evaluation Edition (64-bit)')BEGIN SELECT create_date AS 'SQL Server Installation Date', DATEADD(dd, 180, create_date) AS 'Expiry Date' FROM sys.server_principals WHERE NAME = 'NT AUTHORITY\SYSTEM'
ENDELSEBEGIN print 'Now you running ' + convert(VARCHAR(100), SERVERPROPERTY('Edition')) + ' which won''t expire.'END
Wednesday, June 3, 2020
Data Mask in SQL Server
USE tempdb
GO
-- Create a sample table [dbo].[Customer] with masked columns:
CREATE TABLE dbo.Customer (
CustomerID INT IDENTITY PRIMARY KEY,
FirstName VARCHAR(250),
LastName VARCHAR(250) MASKED WITH (FUNCTION = 'default()') NULL,
PhoneNumber VARCHAR(12) MASKED WITH (FUNCTION = 'partial(1,"XXXXXXXXX",0)') NULL,
Email VARCHAR(100) MASKED WITH (FUNCTION = 'email()') NULL,
CreditCardNo VARCHAR(16) MASKED WITH (FUNCTION = 'partial(4,"XXXXXXXXXX",2)') NULL,
);
-- Now insert some test records (fictitious figures):
INSERT INTO dbo.Customer (FirstName, LastName, PhoneNumber, Email, CreditCardNo) VALUES
('Arka', 'Gupta', '7001061958', 'arkagupto@gmail.com', '4563123456789012'),
('Rahul', 'Singh', '9842359873', 'rahul@gmail.com', '123456789092'),
('Visal', 'Sharma', '6700091129', 'visal@gmail.com', '567890123469'),
('Rajib', 'Agrawal', '9800002000', 'rajib@gmail.com', '345678901224');
-- 1. Now let’s create a Test Account and just Grant Read access to [dbo].[Customer] table:
CREATE USER user1 WITHOUT LOGIN;
GO
GRANT SELECT ON dbo.Customer TO user1;
GO
EXECUTE AS USER = 'user1';
SELECT * FROM dbo.Customer;
REVERT;
GO
-- 2. Removing Masking from a column by simple ALTER TABLE/COLUMN statement:
ALTER TABLE dbo.Customer
ALTER COLUMN LastName DROP MASKED;
GO
-- Let's check the table data again:
EXECUTE AS USER = 'user1';
SELECT * FROM dbo.Customer;
REVERT;
GO
-- 3. Granting the UNMASK permission to “user1”:
GRANT UNMASK TO user1;
GO
-- Let's check the table data again:
EXECUTE AS USER = 'user1';
SELECT * FROM dbo.Customer;
REVERT;
GO
-- 4. REVOLE UNMASK TO user1:
REVOKE UNMASK TO user1;
GO
EXECUTE AS USER = 'user1';
SELECT * FROM dbo.Customer;
REVERT;
GO
-- 5. FINAL CLEANUP:
DROP TABLE dbo.Customer;
GO
DROP USER [user1]
GO