Skip to main content

Policy Based Management (PBM) in SQL Server

 1: To restrict users to prefix "sp_"  for User Defined Stored procedure

To restrict users to prefix "sp_"  for User Defined Stored procedure due to following reasons:
  • For performance:

The master db will always be checked first because of the prefix of sp_ which is time consuming.  All system defined stored procedure name starts with prefix "sp_".
  • Possible conflict of user created stored procedures with system stored procedures:

If a user-defined stored procedure has the same name as a system stored proc, the user-defined procedure will never be executed.

2. To follow a particular naming convention for procedures Eg ‘usp_’

3. A company policy prohibits enabling Database Mail or SQL Mail. A policy is created to check the server state of those two features. An administrator compares the server state to the policy. If the server state is out of compliance, the administrator chooses the Configure mode and the policy brings the server state into compliance.

4. The AdventureWorks2012 database has a naming convention that requires all stored procedures to start with the letters AW_. A policy is created to enforce this policy. An administrator tests this policy and receives a list of stored procedures that are out of compliance. If future stored procedures do not comply with this naming convention, the creation statements for the stored procedures fail.

5. Enforce SQL Server Database Naming Conventions. Standard naming convention for databases would likely include the following rules:

  • Does not include any special characters CREATE DATABASE [embedded.period]
  • Does not start with a number; Eg: CREATE DATABASE [1_start_number];
  • Does not have embedded or trailing spaces; CREATE DATABASE [trailing_space ]
  • On demand policy to ensure that all the databases have the Auto Shrink option set to True. By default, a database that is created has Auto Shrink set to False, as shown in the figure below.

Benefits: 

  • Policy Based Management is considered as one of ‘standard’ method to administer database proactively.
  • It allows DBAs to create various policies to enforce certain rules to single database, to group of databases or to whole server.
  • It is possible to combine more than one condition into one policy.
  • Policy based management is loaded with several advantages. It can help you implement various policies for reliable configuration of the system.
  • It also provides additional administration assistance to DBAs and helps them effortlessly manage various tasks of SQL Server across the enterprise.

Limitation:

  •  Policies can affect how some SQL Server features work.For example, change data capture and transactional replication both use the systranschemas table, which does not have an index. If you enable a policy that all tables must have an index, enforcing compliance of the policy will cause these features to fail.
  •  Certain policies can’t be enforced i.e. they will not have the option “On Change : Prevent” applied to them and so you won’t get the option in evaluation Mode drop down at the bottom

Comments

Popular posts from this blog

  Microsoft Power BI- Solve Problem  "Map and Filled Map Visuals aren't Enabled"   When you try to use Map or Filled Map from Visuals for the 1st time , you may get the following warning : "Map and Filled Map Visuals are disabled". This means you need to go to Options and have to enable these Visuals. Go to File ->Options and Settings-> Options -> Security-> Enable Map and Filled Map Visuals. (After this, in some cases you may need to close and reopen Power BI desktop) Now Go to Add Visual Then double click on Map or Filled Map. After that, you will be able to add Location, Legends etc. without any issues.

Difference between Clustered Index Scan and Index Scan in SQL Server

1.Clustered Index Scan ✅ What it is: A Clustered Index Scan means SQL Server is scanning every row of the entire table,  essentially performing a "table scan" because the clustered index is the table itself.  📌 When it happens: No WHERE clause or very broad filter (low selectivity). Join/filter columns aren’t indexed selectively. Query needs most or all columns (covering queries). 🧠 Performance Insight: Can be expensive for large tables. Usually appears when SQL Server can’t seek and needs to read all data. Example:    Table: CREATE TABLE dbo.Sales (     SaleID INT NOT NULL IDENTITY,     SaleDate DATE NOT NULL,     Quantity INT NOT NULL, PRIMARY KEY (SaleID) ) Query: SELECT * FROM dbo.Sales WHERE  SaleDate  BETWEEN '2025-02-04' AND '2025-02-10' 2. Index Scan (Non-Clustered) ✅ What it is: A Non-Clustered Index Scan scans all rows in a specific non-clustered index( not the full table) 📌 When it happens: The query filters on a ...

While executing Select query to pull data from a different server, SQL Server is showing following error:

Msg 7202, Level 11, State 2, Line 1 Could not find server 'LAPTOP-09O6NE3K\SQLEXPRESS03' in sys.servers. Verify that the correct server name was specified. If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers. Completion time: 2024-02-05T17:18:24.6869756+05:30 Solution: Step1:  Check if the server is available in the sys.servers table SELECT name from sys.servers Step2:  If no, add the new server to the sys.servers table EXEC sp_addlinkedserver @server = 'server name' Eg" EXEC sp_addlinkedserver @server = 'LAPTOP-09O6NE3K\SQLEXP RESS03' Step3:  Recheck if the new server name is added to the sys.servers table. If yes, try then rerunning the select query which throwed the error. Now it should pull data from the table in the new server successfully.