<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Shahid Naeem</title>
	<atom:link href="http://www.shahidnaeem.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shahidnaeem.com</link>
	<description>IT Project Manager - Personal blog</description>
	<lastBuildDate>Mon, 20 Jul 2009 08:59:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Intro. Highly Availability</title>
		<link>http://www.shahidnaeem.com/intro-highly-availability/</link>
		<comments>http://www.shahidnaeem.com/intro-highly-availability/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 17:15:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[High Availability]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.shahidnaeem.com/?p=396</guid>
		<description><![CDATA[High availability of an application is a function of all components such as hardware, backup/recovery, operating system, vendor agreements, sufficient training, extensive quality assurance/testing, rigorous stands and procedures and some overall risk-mitigating strategies, such as spreading&#8230;
Backup, Training, Quality Assurance , Standard / Procedures, Server Instance isolation
1. Hardware 

Redundant power supplies ( and UPSs)
Redundant fan systems
Fault-tolerant [...]]]></description>
			<content:encoded><![CDATA[<p>High availability of an application is a function of all components such as hardware, backup/recovery, operating system, vendor agreements, sufficient training, extensive quality assurance/testing, rigorous stands and procedures and some overall risk-mitigating strategies, such as spreading&#8230;</p>
<p>Backup, Training, Quality Assurance , Standard / Procedures, Server Instance isolation</p>
<p><strong>1. Hardware </strong></p>
<ol>
<li>Redundant power supplies ( and UPSs)</li>
<li>Redundant fan systems</li>
<li>Fault-tolerant disk, such as RAID ( 1 through 10 ), preferably &#8220;hot swappable&#8221;</li>
<li>ECC memory</li>
<li>Redundant Ethernet connections</li>
</ol>
<p>2. Backup</p>
<p>3. Operating System</p>
<ol>
<li>Upgrades to your OS</li>
<li>Antivirus software</li>
<li>firewalls for external-facing systems</li>
</ol>
<p>Vendor Agreements</p>
<ol>
<li>software licenses</li>
<li>software support agreements</li>
<li>hardware service agreements</li>
</ol>
<p>Different Levels of HA:</p>
<ol>
<li>Microsoft Cluster Services ( non-SQL Server based )</li>
<li>SQL clustering</li>
<li>Data replication ( including peer-to-peer configurations )</li>
<li>Log shipping</li>
<li>Database Mirroring</li>
</ol>
<p>Microsoft Cluster Services ( MSCS )</p>
<ol>
<li>MSCS is the advance windows operating system configuration that defines and manages between two and eight servers as &#8220;nodes&#8221; in a cluster.</li>
<li>These nodes are aware of each other and can be setup to take over cluster-aware applications from any node that fails ( failed server ).</li>
<li>This sluster configuration also share and controls one or more disk subsystems as part of its high-availability capability.</li>
<li>MSCS is available only with MS Windows Enterprises Edition Advanced Server and Data Center OS.</li>
<li>MSCS can be set up in an active/passive or active/active mode.If active or passive server fails other can take over share disk and  cluster-aware applications in instaneously.</li>
</ol>
<p><strong>SQL Clustering</strong> ( Chapter 17 )</p>
<ol>
<li> Creating a SQL Server instance that is clustered is done by actually creting a virtual SQL server instance that is known to the application.</li>
<li>two physical SQL server instances that share one set of databases.</li>
<li>In an active/passive configuration, only one SQL server instance is active at a time</li>
<li>If active server fails, the passive server simply takes over instantaneously.</li>
<li>This is possible because MSCS also controls shared disk where the databases are.</li>
</ol>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.shahidnaeem.com/what%e2%80%99s-new-in-high-availability/" rel="bookmark">What’s New in High Availability</a></li><li><a href="http://www.shahidnaeem.com/sql-server-indexes/" rel="bookmark">SQL Server Indexes</a></li><li><a href="http://www.shahidnaeem.com/sql-server-security-principals/" rel="bookmark">SQL Server Security Principals</a></li><li><a href="http://www.shahidnaeem.com/executing-stored-procedures-automatically-at-sql-server/" rel="bookmark">Executing Stored Procedures Automatically at SQL Server</a></li><li><a href="http://www.shahidnaeem.com/sql-server-security/" rel="bookmark">SQL Server Security</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.shahidnaeem.com/intro-highly-availability/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Database does not have a valid owner</title>
		<link>http://www.shahidnaeem.com/database-does-not-have-a-valid-owner-2/</link>
		<comments>http://www.shahidnaeem.com/database-does-not-have-a-valid-owner-2/#comments</comments>
		<pubDate>Sat, 23 Aug 2008 08:55:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.shahidnaeem.com/?p=428</guid>
		<description><![CDATA[Database diagram support objects cannot be installed because this database does not have a valid owner. To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support objects
To fix the problem I first [...]]]></description>
			<content:encoded><![CDATA[<p>Database diagram support objects cannot be installed because this database does not have a valid owner. To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support objects</p>
<p>To fix the problem I first needed to attach the database to the management studio, this can be done in either the full product or the SQL Express Management Studio. Then by going to the properties for the database with the problem and selecting the files tab, change the owner to the [sa] account and select apply. Or you could use the following script.</p>
<pre class="snippet">
USE [&lt;DatabaseName&gt;]
GO
EXEC dbo.sp_changedbowner @loginame = N'sa', @map = false
GO
</pre>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.shahidnaeem.com/database-does-not-have-a-valid-owner/" rel="bookmark">Database does not have a valid owner</a></li><li><a href="http://www.shahidnaeem.com/sql-server-security-principals/" rel="bookmark">SQL Server Security Principals</a></li><li><a href="http://www.shahidnaeem.com/sql-server-security/" rel="bookmark">SQL Server Security</a></li><li><a href="http://www.shahidnaeem.com/introduction-to-joins/" rel="bookmark">Introduction to Joins</a></li><li><a href="http://www.shahidnaeem.com/sql-server-security-securables-and-permissions/" rel="bookmark">SQL Server Security : Securables and Permissions</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.shahidnaeem.com/database-does-not-have-a-valid-owner-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server Security : Securables and Permissions</title>
		<link>http://www.shahidnaeem.com/sql-server-security-securables-and-permissions/</link>
		<comments>http://www.shahidnaeem.com/sql-server-security-securables-and-permissions/#comments</comments>
		<pubDate>Sat, 16 Aug 2008 08:53:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Permissions]]></category>
		<category><![CDATA[Securables]]></category>

		<guid isPermaLink="false">http://www.shahidnaeem.com/?p=426</guid>
		<description><![CDATA[Securables - Securables are the SQL  Server resources that permissions can be granted to.



Server
Database
Schema


Logins
User
Table


EndPoints
Role
View


Databases
Application role
Function



Assembly
Procedure



Message Type
Queue



Route
Type



Service
Synonym



Remote Service Binding
Aggregate



Fulltext Catalog
XML schema collection



Certificate




Asymmetric Key




Symmetric Key




Contact




Schema Assemblies




Schemas




Permissions 
The permissions link  principals with securables. For example, a SQL LOGIN (the  principal) needs to CREATE (the permission)  databases (the securable). Together, these three elements represent a complete [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Securables </strong>-<strong> </strong>Securables are the SQL  Server resources that permissions can be granted to.</p>
<table border="0" width="100%">
<tbody>
<tr>
<td><strong>Server</strong></td>
<td><strong>Database</strong></td>
<td><strong>Schema</strong></td>
</tr>
<tr>
<td>Logins</td>
<td>User</td>
<td>Table</td>
</tr>
<tr>
<td>EndPoints</td>
<td>Role</td>
<td>View</td>
</tr>
<tr>
<td>Databases</td>
<td>Application role</td>
<td>Function</td>
</tr>
<tr>
<td></td>
<td>Assembly</td>
<td>Procedure</td>
</tr>
<tr>
<td></td>
<td>Message Type</td>
<td>Queue</td>
</tr>
<tr>
<td></td>
<td>Route</td>
<td>Type</td>
</tr>
<tr>
<td></td>
<td>Service</td>
<td>Synonym</td>
</tr>
<tr>
<td></td>
<td>Remote Service Binding</td>
<td>Aggregate</td>
</tr>
<tr>
<td></td>
<td>Fulltext Catalog</td>
<td>XML schema collection</td>
</tr>
<tr>
<td></td>
<td>Certificate</td>
<td></td>
</tr>
<tr>
<td></td>
<td>Asymmetric Key</td>
<td></td>
</tr>
<tr>
<td></td>
<td>Symmetric Key</td>
<td></td>
</tr>
<tr>
<td></td>
<td>Contact</td>
<td></td>
</tr>
<tr>
<td></td>
<td>Schema Assemblies</td>
<td></td>
</tr>
<tr>
<td></td>
<td>Schemas</td>
<td></td>
</tr>
</tbody>
</table>
<p><strong>Permissions </strong></p>
<p>The permissions link  principals with securables. For example, a SQL LOGIN (the  principal) needs to CREATE (the permission)  databases (the securable). Together, these three elements represent a complete  security assignment.</p>
<p><strong>Managing Permissions</strong></p>
<ol>
<li>A GRANT of a permission removes any REVOKE or DENY on a securable.  For example, if a table has SELECT permission denied on it and then the SELECT  permission is granted, the DENY permission will then be removed on that table.</li>
<li>DENY and REVOKE remove any GRANT permission on a securable. REVOKE  removes any GRANT or DENY permission on a securable.</li>
<li>Permissions denied at a higher scope in the security model  override grants on that permission at a lower scope. Keep in mind that the  security model has the server scope at the highest level, followed by database  and schema. So, if INSERT permission is denied on tables at the database level,  and INSERT on a specific table in that database is granted at the schema level,  the result is that INSERT is denied on all tables. In this example, a  database-level DENY overrides any GRANT at the lower schema level.</li>
<li>Permissions granted at a higher scope in the security model are  overridden by a DENY permission at a lower level. For example, if INSERT  permission is granted on all tables at the database scope, and INSERT is denied  on a specific table in the database (schema scope), INSERT is then denied on  that specific table.</li>
</ol>
<p><strong><em>Statement </em></strong><strong>permissions</strong> have nothing to do  with the actual data; they allow users to create the structure that holds the  data.</p>
<ol>
<li>Create  Database</li>
<li>Create  Table</li>
<li>Create  View</li>
<li>Create  Procedure</li>
<li>Create  Index</li>
<li>Create  Rule</li>
<li>Create  Default</li>
</ol>
<p>The second type of permissions is <strong><em>object </em>permissions</strong>, which  control how users work with the actual data.</p>
<table border="0" width="100%">
<tbody>
<tr>
<td width="18%"><strong>Object Permission</strong></td>
<td width="82%"><strong>Description</strong></td>
</tr>
<tr>
<td valign="top"><strong>Control</strong></td>
<td>This permission gives  the principal ownership-like capabilities on the object and all objects under  it in the hierarchy. For example, if you grant a user Control permission on the  database, then the user has Control permission on all the objects in the  database, such as tables and views.</td>
</tr>
<tr>
<td valign="top"><strong>Alter</strong></td>
<td>This permission  allows users to create, alter, or drop the securable and any object under it in  the hierarchy. The only property the user can’t change is ownership.</td>
</tr>
<tr>
<td valign="top"><strong>Take Ownership</strong></td>
<td>This allows the user  to take ownership of an object.</td>
</tr>
<tr>
<td valign="top"><strong>Impersonate</strong></td>
<td>This permission  allows one login or user to impersonate another.</td>
</tr>
<tr>
<td valign="top"><strong>Create</strong></td>
<td>As the name implies,  this permission lets a user create objects.</td>
</tr>
<tr>
<td valign="top"><strong>View Definition</strong></td>
<td>This permission  allows users to see the Transact-SQL syntax that was used to create the object  being secured.</td>
</tr>
<tr>
<td valign="top"><strong>Select</strong></td>
<td>When granted, this  permission allows users to read data from the table or view. When granted at  the column level, it lets users read from a single column.</td>
</tr>
<tr>
<td valign="top"><strong>Insert </strong></td>
<td>This permission  allows users to insert new rows into a table.</td>
</tr>
<tr>
<td valign="top"><strong>Update</strong></td>
<td>This permission lets  users modify existing data in a table but not add new rows to or delete  existing rows from a table. When this permission is granted on a column, users  can modify data in that single column.</td>
</tr>
<tr>
<td valign="top"><strong>Delete</strong></td>
<td>This permission  allows users to remove rows from a table.</td>
</tr>
<tr>
<td valign="top"><strong>References</strong></td>
<td>Tables can be linked  together on a common column with a foreign-key relationship, which is designed  to protect data across tables. When two tables are linked with a foreign key,  this permission allows the user to select data from the primary table without  having Select permission on the foreign table.</td>
</tr>
<tr>
<td valign="top"><strong>Execute</strong></td>
<td>This permission  allows users to execute the stored procedure where the permission is applied.</td>
</tr>
<tr>
<td valign="top"></td>
<td><strong>All the permissions in SQL Server can  exist in one of three states:</strong></td>
</tr>
<tr>
<td valign="top"><strong>Grant</strong></td>
<td>Granting allows users  to use a specific permission. For instance, if you grant SmithB Select  permission on a table, then SmithB can read the data within. You know a  permission has been granted when the Allow check box is selected next to the  permission in the permissions list</td>
</tr>
<tr>
<td valign="top"><strong>Revoke</strong></td>
<td>A revoked permission  isn’t specifically granted, but a user can inherit the permission if it has been  granted to another role of which they are a member. That is, if you revoke the Select  permission from SmithB, then SmithB can’t use it. If, however, SmithB is a  member of a role that has been granted Select permission, SmithB can read the  data just as if SmithB had the Select permission. A permission is revoked when  neither Allow nor Deny boxes are selected next to a permission.</td>
</tr>
<tr>
<td valign="top"><strong>Deny</strong></td>
<td>If you deny a  permission, the user doesn’t get the permission—no matter what. If you deny  SmithB Select permission on a table, even if SmithB is a member of a role with  Select permission, then SmithB can’t read the data. You know a permission has  been denied when the Deny check box is selected next to the permission in the  permissions list.</td>
</tr>
</tbody>
</table>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.shahidnaeem.com/sql-server-security/" rel="bookmark">SQL Server Security</a></li><li><a href="http://www.shahidnaeem.com/sql-server-security-principals/" rel="bookmark">SQL Server Security Principals</a></li><li><a href="http://www.shahidnaeem.com/datetime-conversions-using-sql-server/" rel="bookmark">Date/Time Conversions Using SQL Server</a></li><li><a href="http://www.shahidnaeem.com/introduction-to-joins/" rel="bookmark">Introduction to Joins</a></li><li><a href="http://www.shahidnaeem.com/sql-server-restore-information/" rel="bookmark">Backup & Restore Information</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.shahidnaeem.com/sql-server-security-securables-and-permissions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server Security Principals</title>
		<link>http://www.shahidnaeem.com/sql-server-security-principals/</link>
		<comments>http://www.shahidnaeem.com/sql-server-security-principals/#comments</comments>
		<pubDate>Fri, 08 Aug 2008 08:51:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Pricipals]]></category>

		<guid isPermaLink="false">http://www.shahidnaeem.com/?p=424</guid>
		<description><![CDATA[Principals: 
Principals are the  entities that request security to SQL Server resources.



Scope
Principals


SQL Server Level
SQL Server Login


Windows Level
Local user, Local group, Domain user, Domain group


Database Level
Database User, Database Role, Application Role



Default Logins

Every principal that is granted security to SQL Server must have an associated login.
The    login provides access to SQL Server and [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Principals: </strong></p>
<p>Principals are the  entities that request security to SQL Server resources.</p>
<table border="0" width="100%">
<tbody>
<tr class="tabletop">
<td><strong>Scope</strong></td>
<td><strong>Principals</strong></td>
</tr>
<tr>
<td>SQL Server Level</td>
<td>SQL Server Login</td>
</tr>
<tr>
<td>Windows Level</td>
<td>Local user, Local group, Domain user, Domain group</td>
</tr>
<tr>
<td>Database Level</td>
<td>Database User, Database Role, Application Role</td>
</tr>
</tbody>
</table>
<p><strong>Default Logins</strong></p>
<ol>
<li>Every principal that is granted security to SQL Server must have an associated login.</li>
<li>The    login provides access to SQL Server and can be associated with principals that are scoped at the Windows and server levels</li>
<li>These logins can be associated with Windows accounts, Windows groups, or SQL Server logins</li>
<li>Logins are stored in the master database and can be granted permission to resources that    are scoped at the server level.</li>
<li>Logins provide the initial permission needed to access a SQL      Server instance and allow you to grant access to the related databases.</li>
<li>Permissions to      specific database resources must be granted via a database user.</li>
<li>The important thing to      remember is that logins and users are directly related to each other but are different entities.      It is possible to create a new login without creating an associated database user, but a      new database user must have an associated login.</li>
</ol>
<p><strong>1. SA account</strong></p>
<ol>
<li>The  SA account is a SQL LOGIN that is assigned to the <span style="text-decoration: underline;">SysAdmin fixed-server role</span>.</li>
<li>The  SA account cannot be removed, and it can always be used to gain access to SQL  Server.</li>
<li>The  SA account should always have a strong password to prevent malicious attacks,  and it should be used only by database administrators.</li>
</ol>
<p><strong>2. BUILTIN\Administrators  login </strong></p>
<ol>
<li>The  login is made a member of the SysAdmin fixed-server role</li>
<li>It  is a windows group that corresponds to the local administrators group for the  machine that SQL Server is running on.</li>
</ol>
<p><strong>3. NT AUTHORITY\SYSTEM login</strong></p>
<ol>
<li>This account is related to the local system account that SQL  Server services can run under.</li>
<li>It is also added as a member of the sysadmin fixed-server role.</li>
<li>This account can also be removed if the SQL Server services are  not running with the local system account. This should be done with caution,  however, because it can affect applications such as Reporting Services.</li>
</ol>
<p>To better understand logins, you can look at the sys.server_principals catalog view. This view contains a row for every server-level principal, including each server login. The following example selects from this view and displays the results:</p>
<pre class="snippet">select left(name,25) name, type, type_desc
from sys.server_principals AS log
WHERE (log.type in (‘U’, ‘G’, ‘S’, ‘R’))
order by 3,1</pre>
<p><strong>Default Users</strong></p>
<ol>
<li>DBO- default owner ( when login by administrator)</li>
<li>Guest – ( drop it recommended )</li>
<li>Information_Schema</li>
<li>Sys -</li>
</ol>
<p><strong>dbo  User</strong></p>
<ol>
<li>The  dbo user is the database owner and cannot be deleted from the database.</li>
<li>Members  of the Sysadmin server role are mapped to the dbo user in each database, which  allows them to administer all databases.</li>
<li>Objects  owned by dbo that are part of the dbo schema can be referenced by the object  name alone. When an object is referenced without a schema name, SQL Server  first looks for the object in the default schema for the user that is  connected. If the object is not in the user’s default schema, the object is  retrieved from the dbo schema. Users can have a default schema that is set to  dbo.</li>
</ol>
<p><strong> guest User</strong></p>
<ol>
<li>The  guest user is created by default in each database when the database is created.  This account allows users that do not have a user account in the database to  access the database.</li>
<li>By  defa-ult, the guest user does not have permission to connect to the database.  To allow logins without a specific user account to connect to the database, you  need to grant</li>
<li>GRANT CONNECT TO GUEST<strong> </strong></li>
<li><strong>The guest  account is a special account and does not have an associated login. You can  change the access for the guest account by using T-SQL commands instead.</strong></li>
<li><strong>EXEC  sp_addrolemember N’db_datareader’, N’guest’</strong></li>
</ol>
<p><strong> INFORMATION_SCHEMA User</strong></p>
<p>The  INFORMATION_SCHEMA user owns all the information schema views that are  installed in each database. it cannot be dropped from the database.</p>
<p><strong> sys  User</strong></p>
<p>The  sys account gives users access to system objects such as system tables, system  views, extended stored procedures, and other objects that are part of the  system catalog. The sys user owns these objects. Like the INFORMATION_SCHEMA  user, it cannot be dropped from the database.<br />
<strong>List  All Users</strong></p>
<pre class="snippet">  SELECT  left(u.name,25) AS [Name], type, left(type_desc,15) as type_desc
  FROM  sys.database_principals AS u
  WHERE  (u.type in (‘U’, ‘S’, ‘G’)) ORDER BY 1</pre>
<p><strong>View all object by user</strong></p>
<pre class="snippet">  SELECT name, object_id,  schema_id, type_desc
  FROM sys.all_objects
  WHERE  OBJECTPROPERTYEX(object_id, N'OwnerId') = USER_ID(N'sys')
  ORDER BY 1</pre>
<p><strong>User/Schema  Separation</strong></p>
<p>It is a collection of database objects  that one user owns and that forms a single namespace. A single namespace is one  in which each object name is unique and there are no duplicates.</p>
<p><strong>ROLES</strong></p>
<p>Permissions are applied to a role, and  then members are added to the role. Any member of the role has all the  permissions that the role has.</p>
<p>SQL Server has the  following three types of roles:<br />
<strong>1.Fixed-server  and fixed-database roles</strong><br />
These roles are installed  by default and have a predefined set of permissions.<br />
<strong>2.User-defined  roles</strong></p>
<p>These roles are created in  each database, with a custom set of permissions for each set of users assigned  to it.</p>
<p><strong>3.Application  roles</strong></p>
<p>These roles are a special  roles that can be used to manage database access for an application.</p>
<p><strong>Fixed-Server  Roles ( Server levelsecurables )</strong></p>
<table border="0" width="100%">
<tbody>
<tr>
<td><strong>Role</strong></td>
<td><strong>Permission</strong></td>
</tr>
<tr>
<td>Bulkadmin</td>
<td>Allowed to run the BULK INSERT statement.</td>
</tr>
<tr>
<td>Dbcreator</td>
<td>Allowed to CREATE, ALTER, DROP, and RESTORE any database.</td>
</tr>
<tr>
<td>Diskadmin</td>
<td>Allowed to manage disk files that are used by SQL Server.</td>
</tr>
<tr>
<td>Processadmin</td>
<td>Allowed to terminate SQL Server processes.</td>
</tr>
<tr>
<td>Securityadmin</td>
<td>Allowed to GRANT, DENY, and REVOKE permissions for logins at the server and database levels. Members of this role can  reset passwords for SQL Server logins</td>
</tr>
<tr>
<td>Serveradmin</td>
<td>Allowed to change serverwide configuration properties and shut down the server,  if needed.</td>
</tr>
<tr>
<td>Setupadmin</td>
<td>Allowed to add and remove linked servers and execute some system stored  procedures.</td>
</tr>
<tr>
<td>Sysadmin</td>
<td>Allowed to perform  any activity in the server.</td>
</tr>
</tbody>
</table>
<p><strong>Fixed-Database  Roles</strong></p>
<table border="0" width="100%">
<tbody>
<tr>
<td><strong>Role</strong></td>
<td><strong>Permission</strong></td>
</tr>
<tr>
<td>db_accessadmin</td>
<td>Allowed to add or  remove database access for logins.</td>
</tr>
<tr>
<td>db_backupoperator</td>
<td>Allowed to back up the database</td>
</tr>
<tr>
<td>db_datareader</td>
<td>Allowed to read all user table  data.</td>
</tr>
<tr>
<td>db_datawriter</td>
<td>Allowed to change the data in all  user tables.</td>
</tr>
<tr>
<td valign="top">db_ddladmin</td>
<td valign="top">Allowed to run any Data Definition Language (DDL) command against the database. This includes commands to create, alter, and drop database objects.</td>
<td></td>
</tr>
<tr>
<td valign="top">db_denydatareader</td>
<td>Denied the right to read all user table data.</td>
</tr>
<tr>
<td valign="top">db_denydatawriter</td>
<td>Denied the right to change the data in  any of the user tables.</td>
</tr>
<tr>
<td valign="top">db_owner</td>
<td>Allowed  to perform any action on the database. Members of the sysadmin fixed–server role are mapped to this database role</td>
</tr>
<tr>
<td valign="top">db_securityadmin</td>
<td>Allowed to manage permissions for  database users, including membership  in roles.</td>
</tr>
</tbody>
</table>
<p><strong>The  public Role </strong></p>
<ol>
<li>The  public role is a special database role that is like a fixed-database role  except that its permissions are not fixed. The permissions for this role can be  altered.</li>
<li>Every  user in a database is automatically made a member of the public role and in  turn receives any permissions that have been granted to the public role.  Database users cannot be removed from the public role.</li>
<li>The  public role is similar in function to the guest user that is installed by  default in each database. The difference is that the permissions granted to the  guest user are used by any login that does not have a user account in the  database. In this case, the login is allowed to enter the database via the  guest account. In the case of the public role, the login has been added as a  user of the database and in turn picks up any permissions that have been  granted to the public role.</li>
</ol>
<p><strong>To view the permissions associated  with the public role</strong></p>
<pre class="snippet">SELECT top 5 g.name,  object_name(major_id) as ‘Object’, permission_name
from  sys.database_permissions p
join  sys.database_principals g
on p.grantee_principal_id  = g.principal_id
and g.name = ‘public’
order by 1,2</pre>
<p>This SELECT utilizes two catalog views  that contain security information. The SELECT returns only the first five  permissions for the public role, but the TOP clause can be removed to return  all the permissions.</p>
<p><strong>Application Role</strong></p>
<p>To obtain the  permissions associated with the role, the connection must set the role and  supply the password.</p>
<p>This is done  using the stored procedure sp_setapprole.  You set the role to the sales application role (with  the password PassW0rd) as follows:</p>
<pre class="snippet">   EXEC sp_setapprole ‘sales’,  ‘PassW0rd’</pre>
<p>You can also  encrypt the password:</p>
<pre class="snippet">  EXEC sp_setapprole ‘sales’,  {ENCRYPT N ‘ PassW0rd’}, ‘odbc’</pre>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.shahidnaeem.com/sql-server-security/" rel="bookmark">SQL Server Security</a></li><li><a href="http://www.shahidnaeem.com/sql-server-security-securables-and-permissions/" rel="bookmark">SQL Server Security : Securables and Permissions</a></li><li><a href="http://www.shahidnaeem.com/database-does-not-have-a-valid-owner/" rel="bookmark">Database does not have a valid owner</a></li><li><a href="http://www.shahidnaeem.com/sql-server-user-defined-functions/" rel="bookmark">SQL Server User Defined Functions</a></li><li><a href="http://www.shahidnaeem.com/sql-server-stored-procedure/" rel="bookmark">SQL Server Stored Procedure</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.shahidnaeem.com/sql-server-security-principals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server Security</title>
		<link>http://www.shahidnaeem.com/sql-server-security/</link>
		<comments>http://www.shahidnaeem.com/sql-server-security/#comments</comments>
		<pubDate>Sat, 02 Aug 2008 08:50:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.shahidnaeem.com/?p=422</guid>
		<description><![CDATA[Principals:  Principals are the  entities that request security to SQL Server resources.
Securables - Securables are the SQL  Server resources that permissions can be granted to.
Permissions - The permissions link  principals with securables. For example, a SQL LOGIN (the  principal) needs to CREATE (the permission)  databases (the securable). Together, these three [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Principals: </strong> Principals are the  entities that request security to SQL Server resources.</p>
<p><strong>Securables </strong>-<strong> </strong>Securables are the SQL  Server resources that permissions can be granted to.</p>
<p><strong>Permissions </strong>-<strong> </strong>The permissions link  principals with securables. For example, a SQL LOGIN (the  principal) needs to CREATE (the permission)  databases (the securable). Together, these three elements represent a complete  security assignment.</p>
<p><strong>SA account</strong></p>
<ol>
<li>The  SA account is a SQL LOGIN that is assigned to the <span style="text-decoration: underline;">SysAdmin fixed-server role</span>.</li>
<li>The  SA account cannot be removed, and it can always be used to gain access to SQL  Server.</li>
<li>The  SA account should always have a strong password to prevent malicious attacks,  and it should be used only by database administrators.</li>
</ol>
<p><strong>BUILTIN\Administrators  login </strong></p>
<ol>
<li>The  login is made a member of the SysAdmin fixed-server role</li>
<li>It  is a windows group that corresponds to the local administrators group for the  machine that SQL Server is running on.</li>
</ol>
<p><strong>NT AUTHORITY\SYSTEM login</strong></p>
<ol>
<li>This account is related to the local system account that SQL  Server services can run under.</li>
<li>It is also added as a member of the sysadmin fixed-server role.</li>
<li>This account can also be removed if the SQL Server services are  not running with the local system account. This should be done with caution,  however, because it can affect applications such as Reporting Services.</li>
</ol>
<p><strong>dbo  User</strong></p>
<ol>
<li>The  dbo user is the database owner and cannot be deleted from the database.</li>
<li>Members  of the Sysadmin server role are mapped to the dbo user in each database, which  allows them to administer all databases.</li>
<li>Objects  owned by dbo that are part of the dbo schema can be referenced by the object  name alone. When an object is referenced without a schema name, SQL Server  first looks for the object in the default schema for the user that is  connected. If the object is not in the user’s default schema, the object is  retrieved from the dbo schema. Users can have a default schema that is set to  dbo.</li>
</ol>
<p><strong>guest User</strong></p>
<ol>
<li>The  guest user is created by default in each database when the database is created.  This account allows users that do not have a user account in the database to  access the database.</li>
<li>By  defa-ult, the guest user does not have permission to connect to the database.  To allow logins without a specific user account to connect to the database, you  need to grant</li>
<li>GRANT CONNECT TO GUEST<strong> </strong></li>
<li><strong>The guest  account is a special account and does not have an associated login. You can  change the access for the guest account by using T-SQL commands instead.</strong></li>
<li><strong>EXEC  sp_addrolemember N’db_datareader’, N’guest’</strong></li>
</ol>
<p><strong>The  INFORMATION_SCHEMA User</strong></p>
<p>The  INFORMATION_SCHEMA user owns all the information schema views that are  installed in each database. it cannot be dropped from the database.</p>
<p><strong>The sys  User</strong></p>
<p>The  sys account gives users access to system objects such as system tables, system  views, extended stored procedures, and other objects that are part of the  system catalog. The sys user owns these objects. Like the INFORMATION_SCHEMA  user, it cannot be dropped from the database.</p>
<p><strong>List  All Users</strong></p>
<p>SELECT  left(u.name,25) AS [Name], type, left(type_desc,15) as type_desc</p>
<p>FROM  sys.database_principals AS u</p>
<p>WHERE  (u.type in (‘U’, ‘S’, ‘G’)) ORDER BY 1</p>
<p><strong>View all object by user</strong></p>
<p>SELECT name, object_id,  schema_id, type_desc</p>
<p>FROM sys.all_objects</p>
<p>WHERE  OBJECTPROPERTYEX(object_id, N&#8217;OwnerId&#8217;) = USER_ID(N&#8217;sys&#8217;)</p>
<p>ORDER BY 1</p>
<p><strong>User/Schema  Separation</strong></p>
<p>It is a collection of database objects  that one user owns and that forms a single namespace. A single namespace is one  in which each object name is unique and there are no duplicates.</p>
<p><strong>ROLES</strong></p>
<p>Permissions are applied to a role, and  then members are added to the role. Any member of the role has all the  permissions that the role has.</p>
<p>SQL Server has the  following three types of roles:</p>
<p><strong>1.Fixed-server  and fixed-database roles</strong></p>
<p><strong> </strong>These roles are installed  by default and have a predefined set of permissions.</p>
<p><strong>2.User-defined  roles</strong></p>
<p><strong> </strong>These roles are created in  each database, with a custom set of permissions for each set of users assigned  to it.</p>
<p><strong>3.Application  roles</strong></p>
<p><strong> </strong>These roles are a special  roles that can be used to manage database access for an application.</p>
<p><strong>Fixed-Server  Roles ( Server levelsecurables )</strong></p>
<p><strong><span style="text-decoration: underline;">ROLE               PERMISSION</span></strong></p>
<p><strong>Bulkadmin </strong> Allowed to run the BULK INSERT statement.</p>
<p><strong>Dbcreator</strong> Allowed to CREATE, ALTER, DROP, and RESTORE any database.</p>
<p><strong>Diskadmin</strong> Allowed to manage disk files that are used by SQL Server.</p>
<p><strong>Processadmin</strong> Allowed to terminate SQL Server processes.</p>
<p><strong>Securityadmin</strong> Allowed to GRANT, DENY, and REVOKE permissions for logins at the server and                                   database levels. Members of this role can  reset passwords for SQL Server logins</p>
<p><strong>Serveradmin</strong> Allowed to change serverwide configuration properties and shut down the server,  if                                 needed.</p>
<p><strong>Setupadmin</strong> Allowed to add and remove linked servers and execute some system stored  procedures.</p>
<p><strong>Sysadmin</strong> Allowed to perform  any activity in the server.</p>
<p><strong>Fixed-Database  Roles</strong></p>
<p><strong><span style="text-decoration: underline;">ROLE                           PERMISSION</span></strong></p>
<p><strong>db_accessadmin </strong>Allowed to add or  remove database access for logins.</p>
<p><strong>db_backupoperator </strong>Allowed to back up the database.</p>
<p><strong>db_datareader</strong> Allowed to read all user table  data.</p>
<p><strong>db_datawriter </strong> Allowed to change the data in all  user tables.</p>
<p><strong>db_ddladmin </strong> Allowed to run any Data  Definition Language (DDL) command against the                                               database. This  includes commands to create, alter, and drop  database objects.</p>
<p><strong>db_denydatareader </strong>Denied the right to read all user table data.</p>
<p><strong>db_denydatawriter </strong>Denied the right to change the data in  any of the user tables.</p>
<p><strong>db_owner </strong> Allowed  to perform any action on the database. Members of the sysadmin fixed–                                               server role are mapped to this database role.</p>
<p><strong>db_securityadmin</strong> Allowed to manage permissions for  database users, including</p>
<p>membership  in roles.</p>
<p><strong>The  public Role </strong></p>
<ol>
<li>The  public role is a special database role that is like a fixed-database role  except that its permissions are not fixed. The permissions for this role can be  altered.</li>
<li>Every  user in a database is automatically made a member of the public role and in  turn receives any permissions that have been granted to the public role.  Database users cannot be removed from the public role.</li>
<li>The  public role is similar in function to the guest user that is installed by  default in each database. The difference is that the permissions granted to the  guest user are used by any login that does not have a user account in the  database. In this case, the login is allowed to enter the database via the  guest account. In the case of the public role, the login has been added as a  user of the database and in turn picks up any permissions that have been  granted to the public role.</li>
</ol>
<p>To view the permissions associated  with the public role,</p>
<p>SELECT top 5 g.name,  object_name(major_id) as ‘Object’, permission_name</p>
<p>from  sys.database_permissions p</p>
<p>join  sys.database_principals g</p>
<p>on p.grantee_principal_id  = g.principal_id</p>
<p>and g.name = ‘public’</p>
<p>order by 1,2</p>
<p>This SELECT utilizes two catalog views  that contain security information. The SELECT returns only the first five  permissions for the public role, but the TOP clause can be removed to return  all the permissions.</p>
<p><strong>Application Role</strong></p>
<p>To obtain the  permissions associated with the role, the connection must set the role and  supply the password.</p>
<p>This is done  using the stored procedure sp_setapprole.  You set the role to the sales application role (with  the password PassW0rd) as follows:</p>
<p>EXEC sp_setapprole ‘sales’,  ‘PassW0rd’</p>
<p>You can also  encrypt the password:</p>
<p>EXEC sp_setapprole ‘sales’,  {ENCRYPT N ‘ PassW0rd’}, ‘odbc’</p>
<p><strong>Managing Permissions</strong></p>
<ol>
<li>A GRANT of a permission removes any REVOKE or DENY on a securable.  For example, if a table has SELECT permission denied on it and then the SELECT  permission is granted, the DENY permission will then be removed on that table.</li>
<li>DENY and REVOKE remove any GRANT permission on a securable. REVOKE  removes any GRANT or DENY permission on a securable.</li>
<li>Permissions denied at a higher scope in the security model  override grants on that permission at a lower scope. Keep in mind that the  security model has the server scope at the highest level, followed by database  and schema. So, if INSERT permission is denied on tables at the database level,  and INSERT on a specific table in that database is granted at the schema level,  the result is that INSERT is denied on all tables. In this example, a  database-level DENY overrides any GRANT at the lower schema level.</li>
<li>Permissions granted at a higher scope in the security model are  overridden by a DENY permission at a lower level. For example, if INSERT  permission is granted on all tables at the database scope, and INSERT is denied  on a specific table in the database (schema scope), INSERT is then denied on  that specific table.</li>
</ol>
<p><strong><em>Statement </em></strong><strong>permissions</strong> have nothing to do  with the actual data; they allow users to create the structure that holds the  data.</p>
<ol>
<li>Create  Database</li>
<li>Create  Table</li>
<li>Create  View</li>
<li>Create  Procedure</li>
<li>Create  Index</li>
<li>Create  Rule</li>
<li>Create  Default</li>
</ol>
<p>The second type of permissions is <strong><em>object </em>permissions</strong>, which  control how users work with the actual data.</p>
<p><strong>Control </strong>This permission gives  the principal ownership-like capabilities on the object and all objects under  it in the hierarchy. For example, if you grant a user Control permission on the  database, then the user has Control permission on all the objects in the  database, such as tables and views.</p>
<p><strong>Alter </strong>This permission  allows users to create, alter, or drop the securable and any object under it in  the hierarchy. The only property the user can’t change is ownership.</p>
<p><strong>Take Ownership </strong>This allows the user  to take ownership of an object.</p>
<p><strong>Impersonate </strong>This permission  allows one login or user to impersonate another.</p>
<p><strong>Create </strong>As the name implies,  this permission lets a user create objects.</p>
<p><strong>View Definition </strong>This permission  allows users to see the Transact-SQL syntax that was used to create the object  being secured.</p>
<p><strong>Select </strong>When granted, this  permission allows users to read data from the table or view. When granted at  the column level, it lets users read from a single column.</p>
<p><strong>Insert </strong>This permission  allows users to insert new rows into a table.</p>
<p><strong>Update </strong>This permission lets  users modify existing data in a table but not add new rows to or delete  existing rows from a table. When this permission is granted on a column, users  can modify data in that single column.</p>
<p><strong>Delete </strong>This permission  allows users to remove rows from a table.</p>
<p><strong>References </strong>Tables can be linked  together on a common column with a foreign-key relationship, which is designed  to protect data across tables. When two tables are linked with a foreign key,  this permission allows the user to select data from the primary table without  having Select permission on the foreign table.</p>
<p><strong>Execute </strong>This permission  allows users to execute the stored procedure where the permission is applied.</p>
<p>All the permissions in SQL Server can  exist in one of three states:</p>
<p><strong>Grant </strong>Granting allows users  to use a specific permission. For instance, if you grant SmithB Select  permission on a table, then SmithB can read the data within. You know a  permission has been granted when the Allow check box is selected next to the  permission in the permissions list.</p>
<p><strong>Revoke </strong>A revoked permission  isn’t specifically granted, but a user can inherit the permission if it has been  granted to another role of which they are a member. That is, if you revoke the Select  permission from SmithB, then SmithB can’t use it. If, however, SmithB is a  member of a role that has been granted Select permission, SmithB can read the  data just as if SmithB had the Select permission. A permission is revoked when  neither Allow nor Deny boxes are selected next to a permission.</p>
<p><strong>Deny </strong>If you deny a  permission, the user doesn’t get the permission—no matter what. If you deny  SmithB Select permission on a table, even if SmithB is a member of a role with  Select permission, then SmithB can’t read the data. You know a permission has  been denied when the Deny check box is selected next to the permission in the  permissions list.</p>
<p><strong><span style="text-decoration: underline;">Tips:</span></strong></p>
<ol>
<li>Every  principal that is granted security to SQL Server must have an associated login.</li>
<li>Logins  are stored in Master database.</li>
<li>It  is possible to create a new login without creating an associated database user,  but a new database user must have an associated login.</li>
<li>A login is used for user  authentication ( connect to SQL Server)</li>
<li>A database user account is used for  database access and permissions validation (database)</li>
<li>sa,  builtin\administrators, and NT authority\system) are logins that are installed  by default at installation time.</li>
<li>Dbo,guest,Information_schema  and sys are database users that have been created by default at installation  time.</li>
</ol>
<p><strong><span style="text-decoration: underline;">PRACTICAL</span></strong></p>
<p><span style="text-decoration: underline;">Server Level Security</span></p>
<p><strong>LOGIN</strong></p>
<ol>
<li>Registered Servers ( alt + ctrl + G)</li>
<li>Right click on Database Engine and Create group.</li>
<li>Add registered server into created groups.</li>
<li>Right click on Register server and connect to  object explorer</li>
<li><em>Create window user  &amp; associated window group.(computer  Management)</em></li>
<li>Create window login &#8211; wLogin ( Management Studio  )</li>
<li>General Tab</li>
<li>Window  login ( active directory )</li>
<li>Default  database</li>
<li>Enforce  password policy  ( only in SQL login )</li>
<li>Server Roles</li>
<li>Select  Server role default is Public (<span style="text-decoration: underline;"> unelectable</span>)</li>
<li>User Mapping</li>
<li>Select  databases</li>
<li>Select  Database roles</li>
<li>Select  Server Level Securable</li>
<li>Grant  Permissions</li>
<li>Status</li>
<li>Grant  permission to database Engine</li>
<li>Enable  / Disable Login</li>
</ol>
<p><strong>SERVER ROLES</strong></p>
<ol>
<li>Add members to any server roles</li>
</ol>
<p><strong>CREDENTIALS</strong></p>
<ol>
<li>You can map window credential to SQL  authentication user to access any kind of resource  (file system )outside SQL Server.</li>
</ol>
<p><strong><span style="text-decoration: underline;">Database level  Security</span></strong></p>
<p>SCHEMA</p>
<ol>
<li>Right click on Schema and select New and enter  Name</li>
<li>Select Schema owner ( users, database roles,  application roles )</li>
<li>To apply Permission to object in schema add  objects into it</li>
<li>Create table with associated schema</li>
</ol>
<p><strong>USERS</strong></p>
<ol>
<li>Create User named  sLogin associated with login</li>
<li>Default schema ( can’t assign default schema in  window authenticated user )</li>
<li>Owned schema by this user ( schema has only one  owner )<span style="text-decoration: underline;">cant unselect</span></li>
<li>Database roles by this user</li>
<li>Securable</li>
<li>Add object associated with schema and grant  permissions</li>
<li>Extend properties ( for documention)</li>
</ol>
<div>
<p>CBT Security Video 14:30 à 36</p></div>
<p>Creating a Windows Login</p>
<p>Task 1.17 Creating a Standard Login</p>
<p>Task 1.18 Assigning Logins to Fixed Server Roles</p>
<p>Task 1.19 creating a Database User Mapping</p>
<p>Task 1.20 Assigning User Mappings to Fixed Database Roles</p>
<p>Task 1.21 Creating a Custom Database Role</p>
<p>Task 1.22 Creating an application Role</p>
<p>Task 1.23 Assigning Permissions</p>
<p>Users, Roles and groups</p>
<p>Managing schemas</p>
<p>DDL Triggers</p>
<p>Default Users</p>
<ol>
<li>DBO- default owner ( when login by administrator)</li>
<li>Guest – ( drop it recommended )</li>
<li>Information_Schema</li>
<li>Sys -</li>
</ol>
<p><strong>User mapping</strong></p>
<p>Every single user has public role.  We can’t un-select it.</p>
<p>Grant privilege to role à  grant that role to individual user</p>
<p>//orfan user</p>
<p>Exec sp_addrolemember ‘db_datawriter’ , ‘johnson\joe’</p>
<p>Exec sp_changeuser</p>
<p>Users, Server Roles,</p>
<p>User Mapping-database role-default schema</p>
<p>, Securables, Status</p>
<p><strong>Practice:</strong></p>
<p>Create Schemaà</p>
<p>create Database role –  (a ) select default schema created, (b)Members  to this roles</p>
<p>Application role – default created schema , add  securables</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>DDL Triggers</p>
<p>Monitor most DDL activity</p>
<ol>
<li>Prevent  unauthorized usage</li>
<li>Audit  DDL</li>
</ol>
<p>2 Scope</p>
<ol>
<li>Server</li>
<li>Database</li>
</ol>
<pre class="snippet">Create trigger my_ddl_trig
  on database
  for ddl_database_level_events as
  ----    8-16
  if datepart(hour,getDate())&lt;8 or
  datepart(hour,getDate())&gt;17
  print ‘cannot perform ddl outside of normal business  hours’
rollback</pre>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.shahidnaeem.com/sql-server-security-principals/" rel="bookmark">SQL Server Security Principals</a></li><li><a href="http://www.shahidnaeem.com/sql-server-security-securables-and-permissions/" rel="bookmark">SQL Server Security : Securables and Permissions</a></li><li><a href="http://www.shahidnaeem.com/database-does-not-have-a-valid-owner/" rel="bookmark">Database does not have a valid owner</a></li><li><a href="http://www.shahidnaeem.com/sql-server-user-defined-functions/" rel="bookmark">SQL Server User Defined Functions</a></li><li><a href="http://www.shahidnaeem.com/sql-server-stored-procedure/" rel="bookmark">SQL Server Stored Procedure</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.shahidnaeem.com/sql-server-security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server Indexes</title>
		<link>http://www.shahidnaeem.com/sql-server-indexes/</link>
		<comments>http://www.shahidnaeem.com/sql-server-indexes/#comments</comments>
		<pubDate>Fri, 25 Jul 2008 08:47:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Indexes]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.shahidnaeem.com/?p=420</guid>
		<description><![CDATA[IMPLEMENTING  INDEXES
INTRODUCTION TO INDEXES
Indexes

Indexes improve query performance by reducing  I/O operations ( select, update, delete )
Indexes are built on one or more columns in a  table or  view ( keys)
Indexes are automatically created for primary  key and unique constraints

Index Types

Clustered index ( like phone book ) –binary tree
Leaf nodes contains actual [...]]]></description>
			<content:encoded><![CDATA[<p><strong><span style="text-decoration: underline;">IMPLEMENTING  INDEXES</span></strong><br />
INTRODUCTION TO INDEXES<br />
Indexes</p>
<ol>
<li>Indexes improve query performance by reducing  I/O operations ( select, update, delete )</li>
<li>Indexes are built on one or more columns in a  table or  view ( keys)</li>
<li>Indexes are automatically created for primary  key and unique constraints</li>
</ol>
<p>Index Types</p>
<ol>
<li>Clustered index ( like phone book ) –binary tree</li>
<li>Leaf nodes contains actual data pages</li>
<li>Root, intermediate, look</li>
<li>Data sorted and stored based on index key</li>
<li>Non clustaered index binary tree</li>
<li>Intermediate nodes contain pointers to actual  data pages</li>
<li>Data not sorted based on key</li>
<li>Unique, included, full text, xml</li>
</ol>
<p><strong><span style="text-decoration: underline;">Index Guidelines-  query optimizer</span></strong><br />
Non-Clustered</p>
<ol>
<li>Queries that do not return large data sets</li>
<li>Queries that return exact matching ( where )</li>
<li>Covered querry</li>
<li>Columns with high degree of uniqueness (1-1  relationship)</li>
<li>Group by columns</li>
<li></li>
</ol>
<p>Clustered</p>
<ol>
<li>Queries that return large data sets</li>
<li>Qeures that return ranges</li>
<li>Columns with a high degree of uniqueness</li>
<li>Foreign key columns</li>
<li>Group by and order by</li>
</ol>
<p>Database</p>
<ol>
<li>Avoid on indexing  heavily updated tasks</li>
<li>Use many indexes on tables with little to no  data modifications</li>
<li>Avoid indexing small tables</li>
</ol>
<p>Practical WORKING WITH INDEXES</p>
<ol>
<li>Primary key creates clustered index</li>
<li>Tables à  Indexes à  right click and New index</li>
<li>Fill factor work with leaf level node while pad  index works with intermediate level node</li>
<li>Covered index&#8211;   cover all columns in index=add non-key column into index</li>
</ol>
<p>MAINTAINING &amp; OPTIMIZING INDEXES<br />
1)<br />
Index Property à  fragmentation à  if total fragmentation &lt;30% re organize( ), if &gt;30% rebuild ( drop and  created )<br />
2)Database Engine tuning advisor run and see recommendation<br />
3) SQL Profiler<br />
Display estimated query plan, select and execute</p>
<div>
Display actual query plan,  select and execute</div>
<p>CLUSTERED INDEX , Non Cluster Idnex, unique Index ( just  check box)<br />
Tables –TableAà  Indexà  Right click and New<br />
Optons: left all default except<br />
<strong>Set fill</strong> factor  specify how full sql server should make leave level of each index page when  creating the index <strong>Pad Index</strong> specify  space to leave open on each page in intermediate levels of the index Allow  Online Indexing<br />
&#8212;Creating covered indexes<br />
Include include columns ( non covered key or non-key files)<br />
Maintaining Index – rebuild or re organize</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.shahidnaeem.com/sql-server-views/" rel="bookmark">SQL Server Views</a></li><li><a href="http://www.shahidnaeem.com/what%e2%80%99s-new-in-high-availability/" rel="bookmark">What’s New in High Availability</a></li><li><a href="http://www.shahidnaeem.com/sql-server-security-securables-and-permissions/" rel="bookmark">SQL Server Security : Securables and Permissions</a></li><li><a href="http://www.shahidnaeem.com/sql-server-security/" rel="bookmark">SQL Server Security</a></li><li><a href="http://www.shahidnaeem.com/bulk-logged-recovery-model/" rel="bookmark">Bulk-Logged  Recovery Model</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.shahidnaeem.com/sql-server-indexes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to Joins</title>
		<link>http://www.shahidnaeem.com/introduction-to-joins/</link>
		<comments>http://www.shahidnaeem.com/introduction-to-joins/#comments</comments>
		<pubDate>Mon, 14 Jul 2008 08:44:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Database Design]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Cross Join]]></category>
		<category><![CDATA[Inner Join]]></category>
		<category><![CDATA[Joins]]></category>
		<category><![CDATA[Left Outer Join]]></category>
		<category><![CDATA[Outer Join]]></category>
		<category><![CDATA[Self Join]]></category>

		<guid isPermaLink="false">http://www.shahidnaeem.com/?p=418</guid>
		<description><![CDATA[Joins
The types of joins that SQL Server supports are listed in Table 4-3.



Type of join
Description


Inner joins 
Retrieves only data that exists in both tables based on the JOIN. INNER JOIN is frequently shorteded to just JOIN.


Outer Joins 
Inner Joins allow us to pull data that exists in both tables, but sometime we want to pull [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Joins</strong></p>
<p>The types of joins that SQL Server supports are listed in Table 4-3.</p>
<table border="0">
<tbody>
<tr>
<td><strong>Type of join</strong></td>
<td><strong>Description</strong></td>
</tr>
<tr>
<td><strong>Inner joins </strong></td>
<td>Retrieves only data that exists in both tables based on the JOIN. INNER JOIN is frequently shorteded to just JOIN.</td>
</tr>
<tr valign="top">
<td><strong>Outer Joins </strong></td>
<td>Inner Joins allow us to pull data that exists in both tables, but sometime we want to pull all the data from one of the tables, in addition to what matches in both tables. These a-re referred as to as Outer Joins</td>
</tr>
<tr>
<td valign="top"><strong>Left outer joins </strong></td>
<td>Retrieves all data in left table, and only data that exists in the right table based on the JOIN.</td>
</tr>
<tr>
<td valign="top"><strong>Right outer join </strong></td>
<td>Retrieves all data in right table, and only data that exists in the left table based on the JOIN.</td>
</tr>
<tr>
<td valign="top"><strong>Full join (full outer join)</strong></td>
<td>Retrieves all data in both tables.</td>
</tr>
<tr>
<td valign="top"><strong>Cross joins </strong></td>
<td>Creates a Cartesian product of the tables. Used to create sample databases with large volumes of data without too much effort.</td>
</tr>
<tr>
<td valign="top"><strong>Self-join</strong></td>
<td>Joining a table to itself. This is sometimes required when retrieving data from a table that references the table (such as ManagerID of an   Employee also being in the Employee table as EmployeeID).</td>
</tr>
</tbody>
</table>
<p><strong>INNER JOINS</strong></p>
<pre class="snippet">SELECT Production.Product.Name,
	Production.Product.ProductNumber,
	Production.ProductModel.Name as 'Model Name'
FROM
Production.ProductModel Inner join Production.Product
ON
Production.ProductModel.ProductModelID=Production.Product.ProductModelID</pre>
<p><strong>OUTER JOINS</strong></p>
<p>Once more than two tables are involved in the query, things get a  bit more complicated. When a table is joined to the RIGHT table, a LEFT  OUTER JOIN must be used. That is because the NULL rows from the RIGHT  table will not match any rows on the new table.  An INNER JOIN causes the non-matching rows to be eliminated from the  results. If the Sales.SalesOrderDetail table is joined to the  Sales.SalesOrderHeader table and an INNER JOIN is used, none of the  customers without orders will show up. NULL cannot be joined to any  value, not even NULL.</p>
<p>To illustrate this point, when I add the Sales.SalesOrderDetail table  to one of the previous queries that checked for customers without  orders, I get back no rows at all.</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="snippet">SELECT c.CustomerID, s.SalesOrderID, d.SalesOrderDetailID
FROM Sales.Customer c
LEFT OUTER JOIN Sales.SalesOrderHeader s ON c.CustomerID = s.CustomerID
INNER JOIN Sales.SalesOrderDetail d ON s.SalesOrderID = d.SalesOrderID
WHERE s.SalesOrderID IS NULL</pre>
<p>To get correct results, change the INNER JOIN to a LEFT JOIN.</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="snippet">SELECT c.CustomerID, s.SalesOrderID, d.SalesOrderDetailID
FROM Sales.Customer c
LEFT OUTER JOIN Sales.SalesOrderHeader s ON c.CustomerID = s.CustomerID
LEFT OUTER JOIN Sales.SalesOrderDetail d ON s.SalesOrderID = d.SalesOrderID
WHERE s.SalesOrderID IS NULL</pre>
<p>What about additional tables joined to Sales.Customer, the table on the left?   Must outer joins be used? If it is possible that there are some rows without matches,   it must be an outer join to guarantee that no results are lost.  The Sales.Customer table   has a foreign key pointing to the Sales.SalesTerritory table.  Every customer’s territory   ID must match a valid value in Sales.SalesTerritory.  This query returns 66 rows as expected   because it is impossible to eliminate any customers by joining to Sales.SalesTerritory:</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="snippet">SELECT c.CustomerID, s.SalesOrderID, t.Name
FROM Sales.Customer c
LEFT OUTER JOIN Sales.SalesOrderHeader s ON c.CustomerID = s.CustomerID
INNER JOIN Sales.SalesTerritory t ON c.TerritoryID = t.TerritoryID
WHERE SalesOrderID IS NULL</pre>
<p>Sales.SalesTerritory is the primary key table; every customer must match a valid territory.    If you wanted to write a query that listed all territories, even those that had no customers,   an outer join will be used. This time, Sales.Customers is on the right side of the join.</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="snippet">SELECT t.Name, CustomerID  FROM Sales.SalesTerritory t
LEFT OUTER JOIN Sales.Customer c ON t.TerritoryID = c.TerritoryID</pre>
<p><strong>Cross Join</strong></p>
<p>Many SQL books and tutorials recommend that you “avoid cross joins” or “beware of Cartesian products” when writing your SELECT statements, which occur when you don&#8217;t express joins between your tables.</p>
<pre class="snippet">SELECT S.Store, P.Product
FROM Stores S
CROSS JOIN Products P</pre>
<p><strong>Self Join</strong></p>
<p>A table can be joined to itself in a self-join. For example, you can use a self-join to find the products that are supplied by more than one vendor.</p>
<pre class="snippet">USE AdventureWorks;
GO
SELECT DISTINCT pv1.ProductID, pv1.VendorID
FROM Purchasing.ProductVendor pv1
INNER JOIN Purchasing.ProductVendor pv2 ON pv1.ProductID = pv2.ProductID
    AND pv1.VendorID &lt;&gt; pv2.VendorID
ORDER BY pv1.ProductID</pre>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.shahidnaeem.com/sql-server-restore-information/" rel="bookmark">Backup & Restore Information</a></li><li><a href="http://www.shahidnaeem.com/sql-server-user-defined-functions/" rel="bookmark">SQL Server User Defined Functions</a></li><li><a href="http://www.shahidnaeem.com/datetime-conversions-using-sql-server/" rel="bookmark">Date/Time Conversions Using SQL Server</a></li><li><a href="http://www.shahidnaeem.com/sql-server-views/" rel="bookmark">SQL Server Views</a></li><li><a href="http://www.shahidnaeem.com/sql-server-security-securables-and-permissions/" rel="bookmark">SQL Server Security : Securables and Permissions</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.shahidnaeem.com/introduction-to-joins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Date/Time Conversions Using SQL Server</title>
		<link>http://www.shahidnaeem.com/datetime-conversions-using-sql-server/</link>
		<comments>http://www.shahidnaeem.com/datetime-conversions-using-sql-server/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 08:42:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://www.shahidnaeem.com/?p=416</guid>
		<description><![CDATA[SQL Server provides a number of options you can use to format a date/time string. One of the first considerations is the actual date/time needed. The most common is the current date/time using getdate(). This provides the current date and time according to the server providing the date and time. If a universal date/time is [...]]]></description>
			<content:encoded><![CDATA[<p>SQL Server provides a number of options you can use to format a date/time string. One of the first considerations is the actual date/time needed. The most common is the current date/time using <b>getdate()</b>. This provides the current date and time according to the server providing the date and time. If a universal date/time is needed, then <b>getutcdate()</b> should be used. To change the format of the date, you convert the requested date to a string and specify the format number corresponding to the format needed. Below is a list of formats and an example of the output:</p>
<p>Date/Time Conversions Using SQL Server</p>
<pre class="snippet">
select convert(varchar,Content.created,111) as created from Content
</pre>
<p><center></p>
<table cellspacing="0" cellpadding="3" border="1">
<tbody>
<tr align="left" valign="top">
<td colspan="3"><strong>DATE FORMATS</strong></td>
</tr>
<tr align="left" valign="top">
<td><strong>Format #</strong></td>
<td><strong>Query</strong> (current date: 12/30/2006)</td>
<td><strong>Sample</strong></td>
</tr>
<tr align="left" valign="top">
<td align="middle">1</td>
<td>select convert(varchar, getdate(), 1)</td>
<td>12/30/06</td>
</tr>
<tr align="left" valign="top">
<td align="middle">2</td>
<td>select convert(varchar, getdate(), 2)</td>
<td>06.12.30</td>
</tr>
<tr align="left" valign="top">
<td align="middle">3</td>
<td>select convert(varchar, getdate(), 3)</td>
<td>30/12/06</td>
</tr>
<tr align="left" valign="top">
<td align="middle">4</td>
<td>select convert(varchar, getdate(), 4)</td>
<td>30.12.06</td>
</tr>
<tr align="left" valign="top">
<td align="middle">5</td>
<td>select convert(varchar, getdate(), 5)</td>
<td>30-12-06</td>
</tr>
<tr align="left" valign="top">
<td align="middle">6</td>
<td>select convert(varchar, getdate(), 6)</td>
<td>30 Dec 06</td>
</tr>
<tr align="left" valign="top">
<td align="middle">7</td>
<td>select convert(varchar, getdate(), 7)</td>
<td>Dec 30, 06</td>
</tr>
<tr align="left" valign="top">
<td align="middle">10</td>
<td>select convert(varchar, getdate(), 10)</td>
<td>12-30-06</td>
</tr>
<tr align="left" valign="top">
<td align="middle">11</td>
<td>select convert(varchar, getdate(), 11)</td>
<td>06/12/30</td>
</tr>
<tr align="left" valign="top">
<td align="middle">101</td>
<td>select convert(varchar, getdate(), 101)</td>
<td>12/30/2006</td>
</tr>
<tr align="left" valign="top">
<td align="middle">102</td>
<td>select convert(varchar, getdate(), 102)</td>
<td>2006.12.30</td>
</tr>
<tr align="left" valign="top">
<td align="middle">103</td>
<td>select convert(varchar, getdate(), 103)</td>
<td>30/12/2006</td>
</tr>
<tr align="left" valign="top">
<td align="middle">104</td>
<td>select convert(varchar, getdate(), 104)</td>
<td>30.12.2006</td>
</tr>
<tr align="left" valign="top">
<td align="middle">105</td>
<td>select convert(varchar, getdate(), 105)</td>
<td>30-12-2006</td>
</tr>
<tr align="left" valign="top">
<td align="middle">106</td>
<td>select convert(varchar, getdate(), 106)</td>
<td>30 Dec 2006</td>
</tr>
<tr align="left" valign="top">
<td align="middle">107</td>
<td>select convert(varchar, getdate(), 107)</td>
<td>Dec 30, 2006</td>
</tr>
<tr align="left" valign="top">
<td align="middle">110</td>
<td>select convert(varchar, getdate(), 110)</td>
<td>12-30-2006</td>
</tr>
<tr align="left" valign="top">
<td align="middle">111</td>
<td>select convert(varchar, getdate(), 111)</td>
<td>2006/12/30</td>
</tr>
<tr align="left" valign="top">
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr align="left" valign="top">
<td colspan="3"><strong>TIME FORMATS</strong></td>
</tr>
<tr align="left" valign="top">
<td align="middle">8 or 108</td>
<td>select convert(varchar, getdate(), <img src='http://www.shahidnaeem.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> </td>
<td>00:38:54</td>
</tr>
<tr align="left" valign="top">
<td align="middle">9 or 109</td>
<td>select convert(varchar, getdate(), 9)</td>
<td>Dec 30 2006 12:38:54:840AM</td>
</tr>
<tr align="left" valign="top">
<td align="middle">14 or 114</td>
<td>select convert(varchar, getdate(), 14)</td>
<td>00:38:54:840</td>
</tr>
</tbody>
</table>
<p></center></p>
<p>You can also format the date or time without dividing characters, as well as concatenate the date and time string:</p>
<p><center></p>
<table cellspacing="0" cellpadding="3" border="1">
<tbody>
<tr align="left" valign="top">
<td><strong>Sample statement</strong></td>
<td><strong>Output</strong></td>
</tr>
<tr align="left" valign="top">
<td>select replace(convert(varchar, getdate(),101),&#8217;/',&#8221;)</td>
<td>12302006</td>
</tr>
<tr align="left" valign="top">
<td>select replace(convert(varchar, getdate(),101),&#8217;/',&#8221;) + replace(convert(varchar, getdate(),108),&#8217;:',&#8221;)</td>
<td>12302006004426</td>
</tr>
</tbody>
</table>
<p></center></p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.shahidnaeem.com/sql-server-restore-information/" rel="bookmark">Backup & Restore Information</a></li><li><a href="http://www.shahidnaeem.com/introduction-to-joins/" rel="bookmark">Introduction to Joins</a></li><li><a href="http://www.shahidnaeem.com/sql-server-database-backup-options/" rel="bookmark">SQL Server Database Backup Options</a></li><li><a href="http://www.shahidnaeem.com/sql-server-restore-database-options/" rel="bookmark">SQL Server Restore Database Options</a></li><li><a href="http://www.shahidnaeem.com/sql-server-user-defined-functions/" rel="bookmark">SQL Server User Defined Functions</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.shahidnaeem.com/datetime-conversions-using-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server T-SQL</title>
		<link>http://www.shahidnaeem.com/sql-server-t-sql/</link>
		<comments>http://www.shahidnaeem.com/sql-server-t-sql/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 08:40:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://www.shahidnaeem.com/?p=414</guid>
		<description><![CDATA[T-SQL
INTRODUCTION TO T-SQL
DML

Select, Insert , Update, Delete

DDL

Create, alter&#160;  &#38; drop

Common T-SQL

Variables ( temp data storage
Functions (built-in operations
Control of flow ( decision making constructs )
Syntax
Coding conventions

USING DML STATEMENTS

Where
Like , &#60;
Order by
&#160;

WORKING WITH T-SQL
INTRODUCTION TO DDL
Related Posts:SQL Server Stored ProcedureSQL Server User Defined FunctionsSQL Server IndexesSQL Server Security : Securables and PermissionsSQL Server Security]]></description>
			<content:encoded><![CDATA[<p>T-SQL</p>
<p>INTRODUCTION TO T-SQL</p>
<p><strong>DML</strong></p>
<ol>
<li>Select, Insert , Update, Delete</li>
</ol>
<p><strong>DDL</strong></p>
<ol>
<li>Create, alter&nbsp;  &amp; drop</li>
</ol>
<p>Common T-SQL</p>
<ol>
<li>Variables ( temp data storage</li>
<li>Functions (built-in operations</li>
<li>Control of flow ( decision making constructs )</li>
<li>Syntax</li>
<li>Coding conventions</li>
</ol>
<p>USING DML STATEMENTS</p>
<ol>
<li>Where</li>
<li>Like , &lt;</li>
<li>Order by</li>
<li>&nbsp;</li>
</ol>
<p>WORKING WITH T-SQL</p>
<p>INTRODUCTION TO DDL</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.shahidnaeem.com/sql-server-stored-procedure/" rel="bookmark">SQL Server Stored Procedure</a></li><li><a href="http://www.shahidnaeem.com/sql-server-user-defined-functions/" rel="bookmark">SQL Server User Defined Functions</a></li><li><a href="http://www.shahidnaeem.com/sql-server-indexes/" rel="bookmark">SQL Server Indexes</a></li><li><a href="http://www.shahidnaeem.com/sql-server-security-securables-and-permissions/" rel="bookmark">SQL Server Security : Securables and Permissions</a></li><li><a href="http://www.shahidnaeem.com/sql-server-security/" rel="bookmark">SQL Server Security</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.shahidnaeem.com/sql-server-t-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server Views</title>
		<link>http://www.shahidnaeem.com/sql-server-views/</link>
		<comments>http://www.shahidnaeem.com/sql-server-views/#comments</comments>
		<pubDate>Sat, 28 Jun 2008 08:38:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Views]]></category>

		<guid isPermaLink="false">http://www.shahidnaeem.com/?p=412</guid>
		<description><![CDATA[INTORDUCTION TO VIEWS
View

Views are virtual tables defined by a query and  generated when called.

Types of Views

Standard Views
Combine &#38; filtering data from one or more  tables
Simplifies data manipulations &#38; results
Indeed Views
view within a clustered index
indeed views are computed &#38; physically  stored  in the database
Partitioned Views
Combines horizontally partitioned data from  member tables across [...]]]></description>
			<content:encoded><![CDATA[<p>INTORDUCTION TO VIEWS</p>
<p><strong>View</strong></p>
<ol>
<li>Views are virtual tables defined by a query and  generated when called.</li>
</ol>
<p>Types of Views</p>
<ol>
<li>Standard Views</li>
<li>Combine &amp; filtering data from one or more  tables</li>
<li>Simplifies data manipulations &amp; results</li>
<li>Indeed Views</li>
<li>view within a clustered index</li>
<li>indeed views are computed &amp; physically  stored  in the database</li>
<li>Partitioned Views</li>
<li>Combines horizontally partitioned data from  member tables across one or more servers.</li>
<li>Local portioned views combine data from tables  On the same server</li>
<li>Distributed partitioned views combine data from  tables across servers.</li>
</ol>
<p>View Usage</p>
<p>Standard views</p>
<ol>
<li>Simplify results by focusing on specific data</li>
<li>Simplify security by controlling access through  views rather than tables</li>
<li>Provide backward compatibility during schema  changes</li>
</ol>
<p>Indexed Views</p>
<ol>
<li>Great for complex queries which return large  results and require heavy processing</li>
<li>Other queries can benefit from the index on a  view</li>
<li>Updates are reflected in the stored data.</li>
</ol>
<p>Partitioned Views</p>
<ol>
<li>Scale our processing by portioning tables into  multiple member tables.</li>
</ol>
<p>CREATING &amp; MODIFYING VIEWS</p>
<p>WORKING WITH VIEWS</p>
<p>PRACTICE</p>
<p>1)</p>
<p>Create view named  as  SQL Query ( standard view )</p>
<p>2)</p>
<p>Create view Named with SchemaBinding as SQLQuery ( INDEX  VIEW )</p>
<p>Go</p>
<p>Create Unique clustered Index IX_AllTime</p>
<p>On Sales.vixAllTime(name)</p>
<p>3) Distributed Partitioned View</p>
<p>1. Create New Table1 on Server 1 ,  check constraint on portioning column</p>
<p>2.   insert data from original table to Table1</p>
<p>3.  Create New Table1 on  Server2, check  constraint on portioning colum</p>
<p>4.  import data from Table1 from its original table1</p>
<p>5.  Create Link Server  on both server ( be  made using login’s current security context )</p>
<p>6.  Create view Sales on Server 1 as select query  from Server 1 Union All select query from Server2</p>
<p>7.  Create same view on server 2</p>
<div>
<p>Modifying Data Via View</p></div>
<p><strong>&#8212;creating a  Standard Views</strong></p>
<p>Create View vABC</p>
<p>As</p>
<p>Select Statement</p>
<p>//access</p>
<p>Select * from  vABC</p>
<p><strong>&#8212;Creating  Indexed Views</strong></p>
<ol>
<li><strong>It binds  this view with the table, so you cant change based table</strong></li>
<li><strong>Count_big(*)  required</strong></li>
<li><strong>Create  unique clustered index</strong></li>
<li><strong>If using  group by then make index on this field</strong></li>
</ol>
<p>Create view vABC</p>
<p>With  schemabinding</p>
<p>As</p>
<p>Select  name, sum(qty),</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.shahidnaeem.com/sql-server-user-defined-functions/" rel="bookmark">SQL Server User Defined Functions</a></li><li><a href="http://www.shahidnaeem.com/sql-server-indexes/" rel="bookmark">SQL Server Indexes</a></li><li><a href="http://www.shahidnaeem.com/sql-server-security-securables-and-permissions/" rel="bookmark">SQL Server Security : Securables and Permissions</a></li><li><a href="http://www.shahidnaeem.com/sql-server-security/" rel="bookmark">SQL Server Security</a></li><li><a href="http://www.shahidnaeem.com/sql-server-security-principals/" rel="bookmark">SQL Server Security Principals</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.shahidnaeem.com/sql-server-views/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
