Thursday, December 23, 2010

SQL Scripts Manager a free tool from Red Gate



Red Gate's new "SQL Scripts Manager" is available for free download. 


This tool contains over 28 scripts written by expert DBAs, SQL Server MVPs, and Red Gate's SQL developers., to help you streamline monotonous administration and scripting tasks. 


You can easily customize this tool for using your own script.


You can view the description about scripts used, script source and author information.


Download SQL Scripts Manager now and start benefitting from the collective wisdom of these experts – and sharing your own scripts with the SQL Server community – today.


This will be really a very useful and handy tool for DBAs.










The following are the scripts available:

  1. SQL FileGroup SpaceUsed  
  2. Monitoring Plan Cache    
  3. CPU Utilization    
  4. IO Stalls    
  5. Top Resource Waits    
  6. Buffer Cache Hit Ratio    
  7. Object Read Write Ratio    
  8. Top Cpu Intensive Queries    
  9. Database Backup    
  10. Database Integrity Check    
  11. Deploy Maintenance Scripts    
  12. Index Maintenance    
  13. CallProc Template    
  14. InsertInto Template    
  15. Select From Table    
  16. Table Valued Function Template    
  17. Update Templates    
  18. Ping    
  19. Full And Log Backups In Past X Days    
  20. Last Good Database Backup    
  21. Read Error Logs The DBA Way    
  22. Blocking Transactions    
  23. Investigating Fragmented Indexes    
  24. Who Is Running What    
  25. Get Hit Ratio  
  26. Get Partitioned DBs  
  27. Get Tables With No Clustered Index
  28. Get Version And Uptime  

Tuesday, December 21, 2010

SQL Server 2005 Top 10 Features for Database Administration

Feature
Description
Database Mirroring
Extend log shipping capabilities with the database mirroring solution. You will be able to use database mirroring to enhance availability of your SQL Server systems by setting up automatic failover to a standby server.
Online Restore
With SQL Server 2005, database administrators are able to perform a restore operation while an instance of SQL Server is running. Online restore improves the availability of SQL Server because only the data being restored is unavailable; the rest of the database remains online and available.
Online Indexing Operations
The online index option allows concurrent modifications (updates, deletes, and inserts) to the underlying table or clustered index data and any associated indexes during index data definition language (DDL) execution. For example, while a clustered index is being rebuilt, you can continue to make updates to the underlying data and perform queries against the data.
Fast Recovery
A new faster recovery option improves availability of SQL Server databases. Administrators can reconnect to a recovering database after the transaction log has been rolled forward.
Standards-based Information Access
Any object, data source, or business intelligence component can be exposed using standards-based protocols such as SOAP and HTTP—eliminating the need for a middle-tier listener, such as IIS, to access a Web services interface that is exposed by SQL Server 2005.
SQL Server Management Studio
SQL Server 2005 includes SQL Server Management Studio, a new integrated suite of management tools with the functionality to develop, deploy, and troubleshoot SQL Server databases, as well as enhancements to previous functionality.
Dedicated Administrator Connection
SQL Server 2005 provides a dedicated administrator connection that administrators can use to access a running server even if the server is locked or otherwise unavailable. This capability enables administrators to troubleshoot problems on a server by executing diagnostic functions or Transact-SQL statements.
Snapshot Isolation
Snapshot Isolation (SI) level is provided at the database level. With SI, users can access the last committed row using a transitionally consistent view of the database. This capability provides greater scalability.
Data Partitioning
Data partitioning is enhanced with native table and index partitioning that enables efficient manageability of large tables and indexes.
Replication Enhancements
For distributed databases, SQL Server 2005 provides comprehensive schema change (DDL) replication, next-generation monitoring capabilities, built in replication from Oracle to SQL Server, merge replication over https, and significant merge replication scalability and performance improvements. Additionally, the peer-to-peer transactional replication feature improves support for data scale out using replication.

SQL Server 2005 Top 10 Features for Development

Feature
Description
Hosted CommonLanguage Runtime
With SQL Server 2005 developers can create database objects using familiar languages such as Microsoft Visual C# .NET and Microsoft Visual Basic .NET. Developers can also create two new objects—user-defined types and aggregates.
Native XML Support
Native XML data can be stored, queried, and indexed in a SQL Server database—allowing developers to build new classes of connected applications around Web services and across any platform or device.
ADO.NET version 2.0
From new support for SQL Types to Multiple Active Result Sets (MARS), ADO.NET in SQL Server 2005 evolves dataset access and manipulation to achieve greater scalability and flexibility.
Security Enhancements
The security model in SQL Server 2005 separate users from objects, provides fine-grain access, and enables greater control of data access. Additionally, all system tables are implemented as views, providing more control over database system objects.
Transact-SQL Enhancements
SQL Server 2005 provides new language capabilities for developing scalable database applications. These enhancements include error handling, recursive query capabilities, relational operator PIVOT, APPLY, ROW_NUMBER and other row ranking functions, and more.
Reliable Messaging for Asynchronous Applications
Service Broker is a robust messaging infrastructure that provides reliable transactional delivery of critical messages between servers—with the scalable high-performance that is expected with asynchronous queuing.
Visual Studio Integration
Tight integration with Microsoft Visual Studio and the .NET Framework streamlines development and debugging of data-driven applications. Developers can build database objects, such as stored procedures, using any .NET language and can seamlessly debug across .NET and Transact-SQL (TSQL) languages.
Web Services
With SQL Server 2005 developers can develop Web services in the database tier, making SQL Server a hypertext transfer protocol (HTTP) listener and providing a new type of data access capability for Web services-centric applications.
Embedded Reports
Use client-side reporting controls to embed real-time reports into an application at design time.
Full-Text Search Enhancements
SQL Server 2005 supports rich, full-text search applications. Cataloging capabilities provide greater flexibility over what is cataloged. Query performance and scalability have been improved dramatically, and new management tools provide greater insight into the full-text implementation.

Monday, December 13, 2010

Questions on SQL JOINS

A join will allow us to view data from related tables in a single result set.

INNER JOIN:
  • In an inner join, Only rows with values satisfying the join condition in the common column are displayed.
  • It is default join. So 'INNER' keyword can be ignored.

OUTER JOIN:
  • In an outer join, rows are returned even when there are no matches through the JOIN criteria on the second table.
  • Outer join is of three types: Left, Right, Full outer joins

LEFT OUTER JOIN:
  • A left outer join or a left join returns results from the table mentioned on the left of the JOIN keyword irrespective of whether it finds matches or not.
  • If the ON clause matches 0 records from table on the right, it will still return a row in the result—but with NULL in each column.

RIGHT OUTER JOIN:
  • A right outer join or a right join returns results from the table mentioned on the right of the JOIN keyword irrespective of whether it finds matches or not.
  • If the ON clause matches 0 records from table on the left, it will still return a row in the result—but with NULL in each column.

FULL OUTER JOIN:
  • A full outer join will combine results of both left and right outer join. Hence the records from both tables will be displayed with a NULL for missing matches from either of the tables.

CROSS JOIN:
  • A cross join also known as cartesian product between two tables joins each row from one table with each row of the other table.
  • A cross join does not include 'on' clause.
Two tables are created and values are inserted using following SQL statements.

CREATE TABLE A (ID numeric)

INSERT INTO A VALUES(1)
INSERT INTO A VALUES(2)
INSERT INTO A VALUES(3)

CREATE TABLE B (ID numeric)

INSERT INTO B VALUES(4)
INSERT INTO B VALUES(5)
INSERT INTO B VALUES(6)

Using the above tables, try to answer the following questions.

Questions:

1. What will be output of following query?


SELECT A.* from A inner join B on A.ID=B.ID

(A) 1, 2, 3, NULL, NULL, NULL
(B) 1, 2, 3
(C) NULL, NULL, NULL
(D) 0 Rows


2. What will be output of following query?

SELECT A.* from A left outer join B on A.ID=B.ID
(A) 1, 2, 3, NULL, NULL, NULL
(B) 1, 2, 3
(C) NULL, NULL, NULL
(D) 4, 5, 6


3. What will be output of following query?


SELECT A.* from A right outer join B on A.ID=B.ID

(A) 1, 2, 3, NULL, NULL, NULL
(B) 1, 2, 3
(C) NULL, NULL, NULL
(D) 4, 5, 6


4. What will be output of following query?


SELECT A.* from A full outer join B on A.ID=B.ID

(A) 1, 2, 3, NULL, NULL, NULL
(B) 1, 2, 3
(C) NULL, NULL, NULL
(D) 4, 5, 6


5. What will be output of following query?


SELECT A.* from A cross join B

(A) 1, 2, 3, NULL, NULL, NULL
(B) 1, 2, 3
(C) NULL, NULL, NULL
(D) 1, 2, 3, 1, 2, 3, 1, 2, 3

Show Answers:

Tuesday, December 7, 2010

Questions on Choosing an Authentication Mode

When you install SQL Server 2005, the database engine can be set to any of two types of Authentication modes, Windows Authentication mode and Mixed mode.

Windows Authentication Mode:

  • It is default authentication mode.
  • It provides high level of security.
  • It mandates that only users who are previously authenticated to windows OS can connect to SQL Server.

Mixed Authentication Mode:

  • Client applications submits user name and password to connect to SQL Server.
  • When using 'Mixed mode' you can use either 'Windows authentication' or 'SQL Server authentication' to connect to SQL Server.
  • Non-windows users (unix, macintosh) use this mode.


If Windows Authentication mode is selected during installation, the sa login is disabled. If you later change authentication mode to Mixed mode, the sa login remains disabled. To enable the sa login:
Execute the following statements to enable the sa password and assign a password.

ALTER LOGIN sa ENABLE;
GO
ALTER LOGIN sa WITH PASSWORD = '';
GO


Adhering to Password Policies:
To ensure SQL login security, SQL Server 2005 lets you to use AD's password policy and password complexity. You can do the following.

  • You can force password policies.
  • You can use password complexity.
  • You can force password expiration.
  • You can force users to change their password at next logon.

Passwords entered on the Authentication page must meet strong password policy requirements. Strong passwords are not readily guessed by any one, and are not easily hacked by using a computer program.

Follow these guidelines when you set passwords:

1. Strong passwords cannot use prohibited conditions or terms, including:

  • A blank or NULL condition
  • "Password"
  • "Admin"
  • "Administrator"
  • "sa"
  • "sysadmin"

2. A strong password cannot use the following terms associated with the installation computer:

  • The name of the user currently logged onto the computer.
  • The computer name.

3. A strong password must be at least six characters in length and satisfy at least three of the following four criteria:

  • It must contain uppercase letters.
  • It must contain lowercase letters.
  • It must contain numbers.
  • It must contain non-alphanumeric characters – e.g., #, %, or ^.



Questions:

1. You are tasked to implement a password policy for users connecting to your database. You must also provide access to non-windows clients. Which authentication modes you will use?
(a) Windows Authentication mode.
(b) Mixed Authentication mode.

2. Which of the following are true when talking about SQL Server 2005 password policies?
(a) You can force password policies.
(b) You can use password complexity.
(c) You can force password expiration.
(d) You can force users to change their password at next logon.

Show Answers:

Questions on Default, Named and Multiple instances

SQL Server 2005 supports to have multiple instances on a single server. Each instance within a computer runs independently of other instances. You can have only one default instance and others are named instances.

When can I use multiple instance?

  • When testing multiple versions of SQL Server on same computer.
  • When testing service packs and development databases and applications.
What is meant by a Default Instance?

During SQL Server installation, the setup acquires the hostname of the server. So you can have only one default instance on a computer. All clients can connect to the instance using the hostname of the computer.

What are Named Instances?
Named instances are the names that we provide during installation. You can have many number of named instances on a single computer.

For example, if your computer hostname is MCITP and you are providing a name "certification" during installation, then all clients will connect to this instance with MCITP\certification as server name.

Following points are to be considered when creating a named instance.
  • Instance names are not case sensitive.
  • Instance names are limited to 16 characters.
  • Instance names cannot contain the terms "Default," "MSSQLServer," or other reserved keywords.
  • The first character in the instance name must be a letter or an underscore (_).
  • Subsequent characters can be letters defined by the Unicode Standard 2.0, decimal numbers from Basic Latin or other national scripts, the dollar sign ($), or an underscore (_).
  • Embedded spaces or other special characters are not allowed in instance names; nor are the backslash (\), comma (,), colon (:), semi-colon (;), single quote ('), ampersand (&), or at sign (@).

By default, the first time you install SQL Server 2005 on a computer, Setup specifies the installation as the default instance; however, you can choose to install SQL Server as a named instance without installing the default instance first.


The following table shows the number of instances supported for each instance in the different editions of SQL Server 2005.

SQL Server 2005 edition
Database Engine instances
Analysis Services instances
Reporting Services instances
Enterprise Edition
Developer Edition
50
50
50
Standard Edition
Workgroup Edition
Express Edition
16
16
16

It is important point to consider that all components (SSAS/SSIS) of SQL Server that share the same instance name must have same version, edition, platform (16 bit/32 bit) and language.




Questions:


1. How many default instances you can have on a single SQL Server?

A. 1
B. 2
C. 3
D. 4

Show Answers:


Sunday, December 5, 2010

Simple Questions on SQL Server Editions




SQL Server 2005 installation requirements may differ depending on your application needs.
The different editions of SQL Server 2005 have the unique performance, price requirements and will suit for different scenarios. It is your responsibility to decide among editions of SQL Server 2005 before you install.
This image can help you understand how to make the best choice among the editions and components available in SQL Server 2005.

Questions:


1. Which of the following editions of SQL Server 2005 can support Indexed Views? Choose all that apply.
(A) Enterprise Edition
(B) Developer Edition
(C) Standard Edition
(D) Workgroup Edition
(E) Express Edition

2. You have given a Server with Windows 2003 operating system, 4 processors and 3 GB of RAM. What editions of SQL Server 2005 will you install on the server? Choose all that apply.
(A) Enterprise Edition
(B) Developer Edition
(C) Standard Edition
(D) Workgroup Edition
(E) Express Edition

3. Your customer requests you to develop a small web application to record walk-in interview details. Your will develop the application along with a small database and to be shipped to customer free of cost. Which edition of SQL Server 2005 will you choose?
(A) Enterprise Edition
(B) Developer Edition
(C) Standard Edition
(D) Workgroup Edition
(E) Express Edition

4. Which of the following editions of SQL Server 2005 NOT supported for use in a production environment?
(A) Enterprise Edition
(B) Developer Edition
(C) Standard Edition
(D) Workgroup Edition
(E) Express Edition

5. You have given a Server with Windows 2003 operating system with 8 processors. What editions of SQL Server 2005 will you install on the server that can utilize all the 8 processors?
(A) Enterprise Edition
(B) Developer Edition
(C) Standard Edition
(D) Workgroup Edition
(E) Express Edition

6. You suspect that a particular table can grow large and historical data may be archived. To do this you may implement table partitioning. Which of the following editions of SQL Server 2005 can support table partitioning?
(A) Enterprise Edition
(B) Developer Edition
(C) Standard Edition
(D) Workgroup Edition
(E) Express Edition

Show Answers:


Wednesday, December 1, 2010

Sequel QB Mag Volume 1 - E-Book Download
























I have created e-book version of all the articles published till 30-Nov-2010. You can download the e-book and use for your offline reading.

Download E-Book:

Topics Covered:



  1. Triggers 1
  2. Stored Procedures 3
  3. Recompiling SP 4
  4. SELECT Statement 6
  5. Transactions 7
  6. XML 8
  7. System Databases 11
  8. Collation settings 13
  9. SQL injection 14
  10. RAID systems 17
  11. Processor Affinity19
  12. Patch Management 21