SQL SERVER

SQL Server is a Database Management System (DBMS) created by Microsoft. In early days, File Management System is used for storing data permanently on secondary storage device and retrieves it back whenever necessary. But because of some drawbacks in file management system, a new data management system was developed, called as DBMS.

File Management System
In File Management System, data is organized in the form of Fields, Records and Files. A field is meaningful collection of characters, a record is collection of related fields and a file is collection of similar type of records. As an example you can observe the following table that contains student details.

Fields

Sno
1 2 3 4 5

Sname
SAI KRISHNA RAHUL SARMA PARDHU

Course
C CPP ORACLE DOT NET JAVA

Drawbacks Of File Management System
Records File The drawbacks of file management system that leads to the development of DBMS are as follows. 1. Data Redundancy and Inconsistency : In file management system data is duplicated, which is called as redundancy. Because of this duplication memory is wasted and it is inconsistent for the user if he/she has to make changes to the duplicated data. This is because changing the data at one place will not reflect in all places where it is duplicated and user has to make the change at every place where it is duplicated. 2. Atomicity Problem : “Either all the changes in a transaction must occur nor neither occur”. This rule is called atomicity rule and this rule is violated by the file management system, which is called as atomicity problem. For example, if the transaction is to transefer1000/from Account A to Account B, the two steps in the transaction will be as follows. a. Deduct 1000/- from Account A

1

b. Add 1000/- to Account B If there is a system failure or power failure after deducting amount from Account A and before adding this amount to Account B, then amount is deducted from account A but is not added to account B, which violates atomicity rule. According to atomicity rule, If second step is cancelled then first step must also be cancelled other wise second step must also be performed. 3. Concurrent Access Anomolies : The problems that occur when more than one user try to access the same data in the same file are called as concurrent access anomalies. For example within a bank there is a joint Account A, whose balance amount is 5000/-. Two customers of the joint account are withdrawing amount from the Account A, at the same time from two different branches of the bank. One is withdrawing 500/- and another is withdrawing 1000/-. As both are withdrawing at the same time, balance amount is read as 5000 by both the computers. First computer will deduct 500/- and makes the remaining balance as 4500/-. Second computer will deduct 1000/- and will make the remaining balance as 4000/-. During the process of update only one can update data at a time. Hence finally balance will be shown either as 4500 or 4000 instead of the actual amount 3500/-. 4. Security Problem : within file management system, if user got the write permission, he can insert new data, update existing data and he can also delete data from the file and it is not possible to restrict the user from updating or deleting data while allowing to insert new data.

Database Management System (DBMS)
DBMS is based on databases. A database is defined as collection of inter-related data. DBMS is defined as collection of databases and a set of programs to work with databases. SQL Server is called as DBMS as it contains databases and a set of programs to work with databases. DBMS overcomes all the drawbacks of file management system. After inventing DBMS, several models are proposed stating various ways of representing data within the database and their advantages, called as data models. These data models are classified into three categories based on their purpose as follows. 1. Physical Data Models 2. Conceptual Data Models 3. Logical Data Models

Physical Data Models : The data models that concentrate on how the data is physically stored
within the database are called as physical data models.

2

Conceptual Data Models : The data models that concentrate on how the data and relationship
between data can be represented diagrammatically are called as conceptual data models. One of the most popular conceptual model is Entity-Relationship Model(E-R Model). E-R model uses the terminology Entity, Attribute and Relationship. An entity is a real world object stored within the database. If you store student information in the database, then student is called an entity, if you store employee information within the database, then employee is called an entity and so on. An attribute is a characteristic feature of the entity. For student entity sid, sname, course, address all these are called as attributes. A relationship is an association between entities. Relationship between entities are classified into one to one(1:1), one to many(1:M) and many to many(M:N). Within E-R diagrams an entity is represented with a rectangle, an attribute with oval shape and relationship with diamond shape. The E-R diagram for the entities Student and Course is as follows. The relationship type between course and student is one to many. This is because one student can join only one course and a course can be chosen by any number of students.
Snam e
Co urs e

Cname

SID

CID

Du rat i n o

Student

M

Join s

1

Course

Logical Data Models : The data models that concentrate on what data is stored in the database
and what type of relationship exist between data are called as logical data models. The following lists of logical data models are available. 1. Hierarchical Data Model 2. Network Data Model 3. Relational Data Model 4. Object Data Model 5. Object Relational Data Model

Hierarchical Data Model : in this data model data is organized hierarchically like in tree data
structure. Within hierarchical database model it is not possible to represent many to many relationships. This drawback leads to the development of network data model. Student information can be represented in hierarchical data model as follows. 3

College

CID 1001

CID 1002

CID 1003

Courses

SID 10001

SID 10002

SID 10010

SID 10011

Students

Network Data Model : in this data model also data is represented same as in case of
hierarchical data model except that it can represent many to many relationship. Student information is represented in network data model as follows.
College

CID 1001

CID 1002

CID 1003

Courses

SID 10001

SID 10002

SID 10010

SID 10011

Students With Many To Many RelationShip With Course

In both hierarchical and network data models, organization of data is very difficult as it is organized like a tree data structure. Especially deleting a record will be very complex process as all records that are based on deleted record must be rearranged. These drawbacks lead to the development of relational data model.

Relational Data Model : Relational data model was proposed by E.F.Codd in 1970. He
proposed the model theoretically and first practical implementation of relational model was System-R and is developed by IBM Corporation. In relational data model data is organized in the form of attributes, tuples and relations. Attribute, tuple and relation can be compared to a field,

4

. 5 .F. Object Relational Data Model : this model combines the features of object data model with the features of relational data model.DB2.. Attributes or Columns Sno 1 2 3 4 5 Sname SAI KRISHNA RAHUL SARMA PARDHU Course C CPP ORACLE DOT NET JAVA As organization of data in relational data model is similar to file management system. MS Access etc. Codd and now a days these terms are replaced with column. Examples are Object Store. This model also becomes popular as it has advantages of OOP.record and file in file management system. Cactus etc. Examples are SQL Server.0 onwards. This model provides OOP features within the database. Example is Oracle 8. Oracle. Hence this model has both the advantages of relational data model as well as object data model. it is very easy to maintain when compared to hierarchical and network data models. Object Data Model : This data model is based on object oriented concepts of programming. Now a days most Tuples or Rows Relation or Table of the DBMS are RDBMS. These are technical terms given by E. row and table respectively.

Codd and now a days these terms are replaced with column. row and table respectively. Oracle developed by Oracle Corporation and DB2 developed by IBM Corporation are some examples of RDBMS.F. Not Null : if we insert a row into a table without providing value for a column. In relational data model data is organized in the form of attributes. then you can specify Not Null constraint on that column.F. tuple and relation can be compared to a field. For example.Relational Data Model Relational data model is proposed by E. If you want to restrict the user from inserting a NULL value in to a column. tuples and relations. Sno 1 2 NULL 4 5 Sname SAI KRISHNA RAHUL SARMA PARDHU Course C CPP ORACLE DOT NET JAVA Attributes or Columns Relational data model provides various Table Tuples data integrity within the Relation or constraints to maintain or Rows database. then the value in that column is called NULL value. sno must be unique i. record and file in file management system. 2. Unique : when you don’t want to allow duplicate values in to a column. Integrity constraints supported by Relational data model are as follows. These are technical terms given by E. if you take student table. SQL Server developed by Microsoft Corporation. then you can specify unique constraint on that column. In the above student table third row is inserted without giving a value for sno column. Hence this row contains NULL for sno column. The attribute. 6 . Later several DBMS are developed based on relational model and are called as relational database management system (RDBMS).e. First practical implementation of relational model is System-R developed by IBM Corporation. 1.Codd in 1970. These constraints are called as integrity constraints.

To implement this condition on sno column. For example. the candidate key used by the user to identify the tuples uniquely is called as primary key. For example. Here hall ticket no is primary key. When you specify foreign key constraint on a column. you have to specify unique constraint on sno column. Deptno is called as primary key. 7 . But as we use Deptno to uniquely identify the rows of department table. if we take the Department table that contains Deptno. Primary Key : when you specify primary key constraint on a column. ii) Secondary Key : An attribute that is used to uniquely identify the rows of the table when primary key fails is called as secondary key. 4. Among all available candidate keys. As a foreign key refers to a primary key.sno given for one student must not be given to another student. you must specify a primary key column as reference to it. A table must contain an attribute as primary key attribute to identify each row of the table uniquely. then we can use student name and his father name combination to retrieve marks. A table can contain more than one candidate key.. it is also called as referential integrity constraint. If user lost his hall ticket no. then null values as well as duplicate values are not allowed into that column. i) Candidate Key : An attribute of the table that will uniquely identify every tuple of the table is called as candidate key. A foreign key constraint will restrict the user from inserting a value that doesn’t exist in the referenced primary key column. when we have to retrieve marks of a student. both Deptno and Dname Columns are candidate keys. Foreign Key : this constraint is used to create relationship between two tables. Hence combination of these two columns is called as secondary key. Dname and Location Columns. 3. we will provide student’s hall ticket no.

Total normalization process includes 8 normal forms. Programmer Jr. Domain/Key Normal Form(DKNF) 8. 1. PID P101 P101 P101 P102 P102 P102 P102 Proj. Second Normal Form (2NF) 3. a primary key must be defined for the table and all non-key attributes must be dependent on key attributes. As an example observe the following relation that contains information regarding various projects and employees working in those projects. Programmer DBA Jr. Fifth Normal Form (5NF) 7. Name College Maintenance College Maintenance College Maintenance Hospital Maintenance Hospital Maintenance Hospital Maintenance Hospital Maintenance EmpID 1001 1007 1003 1001 1005 1003 1009 Ename A K M A S M R Sr. Fourth Normal Form (4NF) 6. The attributes that are part of primary key are called as key attributes and all remaining attributes are called as non-key attributes. Sixth Normal Form(6NF) First Normal Form (1NF) : A relation is said to be in first normal form if and only if a primary key is defined for the relation and all non-key attributes are dependent on key attributes. Hence we can define primary key on the combination of PID and EMPID Columns. First Normal Form (1NF) 2. it is not possible to define primary key on a single column as every column can contain duplicate values.Normalization The process of minimizing data redundancy through a series of steps called normal forms is called as normalization. Boyce-Codd Normal Form (BCNF) 5. Now by giving the values of 8 . Job Programmer DBA Jr. Third Normal Form (3NF) 4. Programmer Sr. In this table. Programmer Charge/Hour 500 750 300 500 750 300 300 Hours Worked 3 2 5 5 3 5 4 In order to convert the above table to 1NF.

Third Normal Form (3NF) : A relation is said to be in 3NF.PID and EMPID columns. 1. Ename. we can retrieve the values of every other column in the table. Hence PNAME is partially dependent on key attributes. (PID) 2. we have to divide the table as follows. which was actually dependent on JOB but not on EMPID. as they doesn’t contain partial dependencies. In the above three tables that obtained by converting the table of 1NF to 2NF. The above relation is not in 2NF. If a non-key attribute depends on another non-key attribute. But to get PNAME there is no need to provide EMPID. as they don’t contain transient dependencies. (PID. Hence these attributes are also partially dependent on key attributes. CHARGE/HOUR and HOURS WORKED. (EMPID) 3. Job. (PID) 2. If primary key is defined on more than one attribute and a non-key attribute is completely dependent on only one key attribute then that dependency is called as partial dependency. Charge/Hour Hours Worked Now all three relations are said to be in 2NF. (EMPID) 3.EMPID) Pname Ename. Finally Table is represented as follows after defining a primary key on PID and EMPID columns. we have to divide the table as follows. 9 . which was not in 3NF to 3NF. Job. To convert this table. contains PID and EMPID combination as primary key. Charge/Hour. To convert the above relation to 2NF. then that dependency is called as transient dependency. (PID. (PID.EMPID) Pname. if and only if the relation is in 2NF and no transient dependencies exist in the relation.EMPID) Pname Ename. Job Charge/Hour Hours Worked Now all the four tables are in 3NF. second table contains CHARGE/HOUR column. (JOB) 3. Hence the table is said to be in 1NF. JOB. 1. Hours Worked Second Normal Form (2NF) : A relation is said to be in 2NF if and only if the relation is in first normal form and no partial dependencies exist in the relation. The above table after conversion to 1NF. there is no need to provide PID. In the same way to get ENAME.

As the normalization steps proceed to higher normal forms. De-normalization : Converting the tables from their current normal form to their previous normal form is called as de-normalization. of tables increases. When no. the database performance will be reduced as we have to combine the data from more than one table. of tables in the database will increase. 10 . no. This is the reason why database designers are restricted to 3NF.

Reporting Services and Integration Services. which are until now available only in oracle and other expensive DBMS’s. Since then several versions of SQL Server are released and the new version in the market is SQL Server 2005. New Features in SQL Server 2005 1. In SQL Server 2005. It is a bundle of at least four products Relational Database Engine. further development of SQL Server for OS/2 has been cancelled. This is because 1.INTRODUCTION TO SQL SERVER SQL Server is a client-server Relational Database Management System developed by Microsoft Corporation. In 1988. these two programs are combined into a single program called Management Studio. data and the systems that manage that data must always be secure yet available to your users. It provides business intelligence concepts. 2. At almost the same time. SQL Server 2000 provides Enterprise Manager to work with wizards and Query Analyzer to work with SQL queries. It is tightly integrated with Windows 2. analysis service is used to work with business intelligence concepts like data warehousing and data mining. 3. users and information 11 . With SQL Server 2005. SQL Server is the RDBMS chosen as back end by most of the developers on Windows operating system. History Of SQL Server SQL Server was developed and implemented by Sybase Corporation. Microsoft cancels the agreement with Sybase and starts developing SQL Server for windows. A client-server RDBMS is an RDBMS that can be shared. Microsoft licensed SQL Server for OS/2 operating system and began developing it for windows in early 1990. database tuning. 4. It scales from mobile laptop to symmetric multi-processor systems. Analysis Services.. Reporting Services is used to create and deploy enterprise reports and Integration Services is used to integrate data from different types of data sources to SQL Server. Relational Database Engine is used to work with database and database objects. backup etc. In today's connected world. It is easy to use as it provides wizards to perform various tasks like object creation. 5. In 1994.

database snapshots. The connection is activated by members of the sysadmin fixed server role and is only available through the SQLCMD command prompt tool either locally or from a remote computer. The secondary instance detects failure of the primary server within seconds and accepts database connections immediately. and optimize enterprise data and analytical applications. Investments in high-availability technologies. 5. SQL Server 2005 makes it simpler and easier to deploy. 4. 7. 3. manage. as well as Integration Services. Notification Services. and SQL Server Mobile Edition across large numbers of distributed servers and databases. additional backup and restore capabilities. with the intention of providing more precise and flexible control to enable tighter security of the data. applications can immediately reconnect to the database on the secondary server. SQL Server 2005 makes significant enhancements to the security model of the database platform. SQL Server 2005 simplifies management by providing one integrated management console to monitor and manage the SQL Server relational database. Analysis Services. and tight yet flexible security controls. Database mirroring allows continuous streaming of the transaction log from a source server to a single destination server. Availability. snapshot isolation. increased scalability and performance. 12 . and 64-bit support will enable you to build and deploy your most demanding applications using SQL Server 2005. 10. Reporting Services. Scalability advancements such as table partitioning. Innovative high-availability features such as database mirroring. failover clustering. The partitioning of large tables and indexes significantly enhances query performance against very large databases. and replication enhancements will enable enterprises to build and deploy highly available applications. SQL Server 2005 includes key enhancements to enterprise data management in Manageability. 6. 9. This allows you to execute diagnostic functions or Transact-SQL statements so you can troubleshoot problems on a server. 8. In the event of a failure of the primary system. Scalability and Security areas. and enhanced online operations will minimize downtime and help to ensure that critical enterprise systems remain accessible. SQL Server 2005 introduces a dedicated administrator connection to access a running server even if the server is not responding or is otherwise unavailable.technology (IT) professionals across your organization will benefit from reduced application downtime.

Management Studio To work with SQL server 2005 databases and database objects. you can use query editor. Whenever you want to work with SQL Server using SQL commands. then choose “register new server”. Various options available are Relational Database Engine. right click on registered servers. and then provide information required to register a server. Reporting Services and Integration Services. Management Studio provides the following windows. To register a new SQL Server. 13 . Short cut to open object explorer window is F8 Summary : this window will display all the objects available within the selected category in object explorer. By using this window. Type the query within query editor and to execute it. Registered Servers : this window displays all registered SQL Server servers on the current system. Short cut to open registered servers window is Ctrl + Alt + G Object Explorer : this window will display all the databases. To open query editor click on New Query button in the toolbar. use the shortcut F5. we have to use management studio. When there are multiple statements within query editor and you want to execute only one then select the statement you want to execute and then press F5. Analysis Services. database objects. you can use object explorer. You can work with the objects within summary window by double clicking on them or by right clicking on them and then choosing the corresponding option. Whenever you want to work with wizards provided by management studio. Short cut to open summary window is F7 Query Editor : this window is used to write SQL queries and execute them. you can also register a new SQ Server. users and logins available in the selected server within registered servers window as a hierarchy. Connecting To Server Whenever you open management studio immediately “connect to server” dialog box will displayed where you have to provide the following information to connect to a database server in the network Server Type : used to specify what type of server you want to connect to within SQL server.

by default the local system name will be given as server name. If the database is within the local system. TSQL (Transact SQL) SQL (Structured Query Language) is the common language for any RDBMS to work with the database. you have to provide login and password to login to SQL Server. 2. Features of SQL are as follows. SQL is not case sensitive 3. then valid login and password must be specified to login to SQL Server. SQL Server will not provide additional security for the data. 1. Actually SQL was developed by IBM corporation for their Relational project System – R as part of it. Windows Authentication and SQL Server Authentication. But later it was developed as a separate language and was given a name SEQUEL (Structured English Query Language). Data Definition Language (DDL) : The commands of SQL that are used to create database objects. SEQUEL was renamed as SQL and was first commercially released by ORACLE Corporation. Authentication Mode : SQL Server supports two types of authentication modes. Commands of SQL are classified as follows. then also you have to provide the same information to register the server on the client system. in addition to user name and password you provide to login to windows. In this mode. SQL Server will provide additional security for the data in addition to security provided by windows Operating System. 1. In SQL Server authentication mode.Server Name : used to specify the name of the database server within the network to which you want to connect to. Login And Password : if the mode is selected as SQL Server authentication mode. Whenever you try to register a new server using registered servers window. In this mode. In SQL Server the SQL used to work with SQL Server database is called as TSQL. the user name and password you specify to login to windows operating system will be treat as login and password to login to SQL Server as well and in this mode there is no need to provide additional login and password to login to SQL Server. In SQL we can break a single statement into multiple lines without using any continuation character. In windows authentication mode. SQL is a non-procedural or fourth generation language (4GL). alter the structure of the database objects and delete database objects 14 .

along with any user defined data you place in the database. Data Query Language (DQL) : The commands of SQL that are used to retrieve data from the database are collectively called as DQL and example is Select. 3.from database are collectively called as DDL.767 databases. A single SQL Server can maintain 32. 2. A log file will have the extension . Rollback and Savepoint. The database engine has a default data file.ldf. a database is maintained with the help of operating system files. • Data files have the internal data the engine needs.ndf. 4.mdf and additional data files will have the extension . Examples include Insert. Update and Delete. Alter and Drop Commands. modify the data of the database and to delete data from the database are collectively called as DML. 5. Data Manipulation Language (DML) : The commands of SQL that are used to insert data into the database. Within SQL Server. A primary data file will have the extension . An SQL Server database uses two types of files. Examples include Create. and you may add additional data files for storage or organizational reasons. and is heavily used in the process of committing and rolling back changes in the database. data file and Log file. Data Control Language (DCL) : The commands of SQL that are used to control the access to data stored in the database are collectively called as DCL and examples include Grant and Revoke. Database The primary object to create when you want to work with SQL Server is Database. Example : Create Database MyDatabase Syntax 2 : 15 . Transaction Control Language (TCL) : The commands of SQL that are used to control the transactions made against the database are collectively called as TCL and examples include Commit. • Log files are used to store any modifications made to data. Creating A Database Syntax 1 : Create Database DBName With this syntax SQL Server will create a database with specified name and will automatically create a data file and a log file for the database with default specifications.

MaxSize = maximum allowed size for the Data file. Example : 16 . FileName option is used specify the physical path and name of the file. Size option is used specify the initial memory to be allocated to the file. Name option specifies the logical name of the file used by the SQL Server. MaxSize = maximum allowed size for the Log file. Size = initial memory to be allocated for the Data file.Create Database DBName On (Name = Logical Name Of the Data File. FileName = ‘Physical Path and Name Of the Log File’. By default SQL Server will take it in MB and to change it you can explicitly specify KB or any other measurement of memory. Filegrowth = increment to the memory of the Log file ) Here on option is used to specify information related to Data File and log on option is used to specify the information related to Log File. FileGrowth option is used to specify how much increment to be done the file whenever allocated memory is completely utilized by the file. MaxSize option specifies the maximum allowed size for the file. Filegrowth = increment to the memory of the Data file ) Log on (Name = Logical Name Of the Log File. FileName = ‘Physical Path and Name Of the Data File’. Size = initial memory to be allocated for the Log file. It can be specified as unlimited to not to restrict the file growth.

for this purpose SQL server provides Alter Database command that has the following syntaxes. Size = 5. MaxSize = 100. Altering The Structure Of The Database After creating the database you may have to create additional data files or log files to the database or delete a data file or log file or make modifications to file specification etc. MaxSize = 20. FileGrowth = 1 ) Syntax 3 : Create Database DBName as snapshot of Existing DBName This syntax is used to create a copy of an existing database as a new database and this option is available only in SQL Server professional edition and is not available in Standard edition. Size = 5. Alter Database DBName Add File (Data File Specification) 17 .Create Database MyDatabase On (Name = MyDatabase_Dat. FileName = ‘D:\MyDatabase.. FileName = ‘D:\MyDatabase. FileGrowth = 5 ) Log on (Name = MyDatabase_log.Mdf’.Ldf’. 1.

first you have to create a table within the database and to create a table you have to specify columns required for the table along with the type of data you want to store in the table and constraints you want to check during the insertion or updating of the data in the table.e. 2. SP_HELPDB ‘DBNAme’ Deleting A Database To delete a database from SQL server use Drop Database command. Alter Database DBName Remove File Logical Name Of The File This syntax is used to delete a data file or log file from an existing database. Drop Database DBName Tables Or Relations Whenever you want to store data into the SQL server database. MaxSize=n . FileGrowth = n) This syntax is used to change the file specification for an existing file of the database. 3. 5. 4. This will display information about the data files and log files created for the database along with database information. Size=n . Syntax is as follows. Alter Database DBName Modify File (Name = LogicalName .This syntax is used to add an additional data file to an existing database. Alter Database DBName Add Log File (Log File Specification) This syntax is used to add an additional log file to an existing database. Syntax will be as follows. Alter Database DBName Modify Name = NewDBName This syntax is used to change the name of the database i. Data Types In SQL Server 18 . Note : To get the information about an existing database use the system procedure “SP_HELPDB”. renaming the database.

Variable Length Unicode char data and n can be up to maximum 4000.S) Numeric(P.S) 1 2 4 8 5 to 17 1-9 Bytes Range 0 To 255 -32768 To 32767 -2147483648 To 2147483647 -263 To 263 – 1 Decimal(7. (ex : 12345.2) will allow a total of 7 Float 5 bytes digits where 2 digits will be after the decimal point. to Variable length char Data to Variable length Unicode char data to Fixed length binary data to Variable Length Binary Data to Variable Length Binary data True/False/NULL Variable Length Char Data Variable Length Unicode Char Data Nvarchar(n) Text(n) Ntext(n) Binary Binary(n) VarBinary(n) Image(n) Bit Value Varchar(Max) NVarchar(Max) n can be up maximum 2GB N can be up maximum 230 – 1 N can be up maximum 8000 N can be up maximum 8000 N can be up maximum 231 – 1 1 231 – 1 231 – 1 Large Data Types 19 .Category Integer Data Type Tiny int Small int Int Big int Decimal(P.67) 10-19 9 bytes 20-28 13 bytes Float(P) P can be 1-53 Real Small Money Money Char (n) Varchar(n) NChar(n) 29-38 17 bytes If P is 1-24 4 Bytes If P is 25-53 8 Bytes 4 bytes 4 Byte Decimal 8 Byte Decimal Equal to float(24) Character Fixed Length Char Data and n can be up to maximum 8000 Variable Length Char Data And n Can be up to maximum 8000 a Unicode character Fixed Length Unicode char data will occupy 2 bytes in and n can be up to maximum memory 4000.

It is not possible to specify the not null constraint at table level. But you can specify a constraint that span on a single column either at column level or table level.DateTime Miscellaneous VarBinary(Max) SmallDatetime DateTime SQL_variant 231 – 1 2 2byte integers 2 4byte integers Size varies Variable Length Binary Data Jan 1st 1900 to june 6th 2079 Jan 1st 1753 to Dec 31st 9999 Can Store any Type of Data except text. A constraint that is specified along with the column definition is called as column level constraint and a constraint that is specified at the end of the table creation is called as table level constraint. 1. In general table level constraints are used when you have to specify the constraint on more than one column. Syntax : ColumnName DataType Not Null 2. Unique : This constraint is used to restrict the user from inserting duplicate values into a column. Default can be specified only at column level. image and SQL_variant Can Store a Table Can store XML documents Table XML Timestamp Cursor Size varies Size Varies 8 bytes Constraints In SQL Server A constraint is a condition given on a column that is checked during insertion and updating data of the table to maintain data integrity within the database. Syntax : Columnname Datatype [constraint cname] default defautvalue 3. When we create a unique constraint on a column then SQL Server will automatically create an 20 . Default : This constraint is used to specify a default value for a column. Constraints in SQL Server are classified into Declarative Integrity Constraints and Procedural Integrity Constraints. Not Null : This constraint is used to restrict the user from inserting null values in to a column. Procedural integrity constraints are the constraints that are not possible to specify during the table creation and are specified using triggers. Declarative integrity constraints are the constraints that can be specified during the table creation. Declarative integrity constraints supported by SQL Server are as follows. When user insert a row into the table without providing a value for the column having default value then default value will be inserted in to that column. ntext. Declarative integrity constraints can be specified either at column level or table level.

we have to give a primary key or unique column as reference to foreign key. This “on update” or “on delete” option will have four options No Action.Coln) 5. Foreign Key : This constraint is used to create relationship between two tables. Primary Key : A column in the table that uniquely identifies every row of the table is called as primary key. the primary key column must not contain either null values or duplicate values.Coln) 4.…. then user will be restricted from inserting null values as well as duplicate values. When these options are set to no action. By default SQL Server will create a non-clustered index on unique constraint. An index can be clustered or non-clustered. Syntax : Column Level ColumnName DataType [Constraint Cname] Primary Key [Clustered / NonClustered] Table Level [Constraint Cname] Primary Key(Col1.Col2. Now the foreign key will restrict the user from inserting a value that doesn’t exist in the referenced column. and Set Default. When we specify primary key constraint on a column. 21 . Default option for “on update” as well as “on delete” is no action. While specifying the foreign key you can specify “on update” and “on delete” options that will specify the action to be taken on foreign key values when modification was done to primary key column or a primary key row was deleted. On primary key column also SQL Server will create an index. While creating the foreign key constraint. then any modification made to primary key value will be automatically made to foreign key value and if a primary key row was deleted then automatically all its dependent foreign key rows will be deleted. Set Null. which is by default a clustered index. it is not possible to update or delete primary key value without first updating or deleting the corresponding foreign key value.index on that column.Col2. Syntax : Column Level ColumnName DataType [Constraint Cname] Unique [Clustered / NonClustered] Table Level [Constraint Cname] Unique(Col1. Cascade. To uniquely identify every row of the table. When these options are set to Cascade.….

Syntax : Column Level ColumnName Datatype [Constraint Cname] References tablename(columnname) Table Level [Constraint Cname] foreign key(Col1. Check : This constraint is used to specify a custom condition on a column. ColName DataType [Constraint] identity(seed. then any modification made to primary key value or deletion of a primary key row will automatically set all its dependent foreign key values to null. then foreign key value will be set to null.When these options are set to Set Null.increment) select @@Identity select scope_identity() select Ident_seed('Student') select Ident_Incr('Student') select ident_Current('Student') Gives the current value of identity Gives the current value of identity Gives the seed of the identity gives the increment of the identity Gives the current value of identity Creating A Table 22 . When you have to refer to other columns of the table within the condition of the check constraint. If the default value is not specified for the foreign key column. it is not possible to refer to other columns of the table within the condition of the check constraint.Coln) References Tablename(Col1.Col2. When a check constraint is specified at column level.… Coln) 6.Col2. any modification made to primary key value or deletion of a primary key row will automatically set all its dependent foreign key values to default. Syntax : Column Level ColumnName Datatype [Constraint Cname] check(condition) Table Level [Constraint Cname] check(Condition) Identity Column Within a table when you want to automatically generate values for a column then you can create that column as identity column by using identity option that has the following syntax. then you have to specify the check constraint at table level. When these options are set to Set Default.….

SNAME varchar(20) not null.A table can be created using the create table command that has the following syntax. SQL Tinyint Constraint SQL_CHK Check(SQL<=100) default 0. Column2 Datatype [Constraints Information]. TOTAL Smallint. Create table Student (SID Smallint constraint SID_PK primary key identity(1001. COURSE varchar(25) not null ) The same table can be created by specifying the primary key at table level as follows. COURSE varchar(25) not null. Create table TableName (Column1 Datatype [Constraints Information].1). . . SNAME varchar(20) not null. Columnn Datatype [Constraints Information] ) The following example will create a table with the name student with SID. Create table MARKS (SID Smallint Constraint SID_FK references STUDENT(SID). SNAME and COURSE columns. . Constraint SID_PK primary key(SID) ) The following example will create a table called MARKS with a foreign key that refers to STUDENT table. Create table Student (SID Smallint. CPP Tinyint Constraint CPP_CHK Check(CPP<=100) default 0. 23 . C Tinyint Constraint C_CHK Check(C<=100) default 0.

GRADE varchar(30) ) The same table can be created by specifying constraints at table level as follows. AVEG Decimal(5. When didn’t specify a name for the constraint then SQL Server will automatically give a name to the constraint. CPP Tinyint default 0. Constraint CPP_CHK Check(CPP<=100). To get a list of all available columns in a table.AVEG Decimal(5. Sp_HelpConstraint ‘TableName’ 3. SQL Tinyint default 0.2). their data types and constraints information. Create table MARKS (SID Smallint. You can get the details of all constraints available on a table by using the system procedure sp_helpconstraint. TOTAL Smallint. Constraint SQL_CHK Check(SQL<=100) ) Note : 1. Constraint SID_FK Foreign Key(SID) references STUDENT(SID). To get the list of system tables. SQL Server also contains system tables. specify ‘s’ 2. To get the list of tables available in the current database you are using.2). GRADE varchar(30). Sp_help ‘tablename’ 24 . Select * from Sysobjects where type=’u’ Here ‘u’ represents the user defined tables. use the following select statement. C Tinyint default 0. use the system procedure Sp_help that has the following syntax. It is optional to give a name to a constraint when you create it. Constraint C_CHK Check(C<=100).

….value for ColName Enable or Disable a Constraint Alter Table TableName Check/NoCheck Constraint Constr.Name] Constraint This Syntax can be used to add constraints like default. check and foreign key Adding Default Constraint Alter Table TableName Add [Constraint Constr. changing data type of a column.Col2 DataType [null/not null]..Name Deleting a Column Alter Table TableName Drop Column ColName Deleting a Constraint 25 .Col2 Datatype [Constraints].… Changing Data Type of a Column Alter Table TableName Alter Column Col1 Datatype [null/not null]. Adding Constraint to a Column Alter Table TableName [with check/nocheck] Add [Constraint Constr. Adding New Column Alter Table TableName Add Col1 Datatype [Constraints]. unique. This syntax can be used to change the data type of a column or add and remove not null constraint on a column.Name] Default Def. like adding a new column.Altering the Table Structure You can use Alter Table command to alter the structure of a table. deleting a column or constraint etc. add a constraint . primary key.

’SAI’. SQL Server provides Insert command for inserting data into the database.null) 26 .66.null. Update command to make modifications to the data and Delete command to delete data from the database. Insert into tablename values(val1.valn) When you are using this syntax.table_constraints where table_name='Emp' Data Manipulation Language (DML) The commands of SQL that are used to insert data into the database. the insert statement will be written as follows.’NewName’ Renaming A Column Sp_Rename ‘TableName.77.Name Renaming A Table Sp_Rename ‘OldName’. If you want to insert the default value for a column then use the keyword default.55. modify the contents of the database and to delete the data from the database are collectively called as DML. Hence I will specify null as the value for those columns. average and grade columns. In this example I don’t want to give values for total.Alter Table TableName Drop Constraint Constr.’NewName’ Getting information about tables. the insert statement will be written as follows.’SQL’) Ex 2 : To insert a row into Marks table. Insert into Marks Values(1001. Insert into student values(1001. you must specify a value for every column of the table. Inserting Data Into A Table To insert data into a table SQL Server provides insert command and it has the following syntaxes. columns in tables and constraints on tables select * from information_schema.Tables select * from information_schema. Ex 1 : To insert a row into student table.….val2.val3.OldName’.null. Even for a column which allows null values you must specify the value as null to insert null value into that column. 1.Columns Where table_name='Emp' select * from information_schema.

the insert statement will be written as follows. average. the update command will be as follows.Col2. Update tablename set column1=val1. Ex 1: to insert a row into marks table without giving values for total. Within the column list after the table name specify the names of columns for which you are providing values and then give values for those columns within the values list. Update Marks Set Total = C+Cpp+Sql. Insert into tablename(Col1. Average = (C+Cpp+Sql)/3 27 . provided no. Ex 1: To update the course of a student with sid 1002 to SQL. average columns. Update Student set course=’SQL’ where sid=1002 Ex 2: To update rows in marks table by calculating total.77) 3.…. the update statement will be as follows.….Coln) values(Val1.Col3. and grade columns.. Insert into Marks(Sid.sql) values(1001. of columns and their data types match in those two tables.column=valn [where condition] Specifying where clause is optional and when you didn’t specify the where clause then the modification will be made to every row in the table. Updating Data In The Table When you want to make modifications to the data available in the table.Val2. Select * into Tablename From Tablename Syntax is used create a new table from existing table.cpp.2.…. But the columns you exclude must not contain not null constraint.66. you have to use update command.Valn) By using this syntax you can insert a row into a table without giving values for specified columns. Insert into tablename select statement This syntax is used when we have to insert rows from an existing table in to a new table.c.55.column2=val2.Val3. Update command has the following syntax.

Ex 3: To update marks table by calculating grade, the update statement will be as follows. SQL server provides case statement to check for a condition and then execute the statements within update command and this update statement will use case to update grade based on average marks of the student. Update Marks set Grade = case When Average>=90 then ‘DISTINCTION’ When Average>=70 then ‘FIRST CLASS’ When Average>=55 then ‘SECOND CLASS’ When Average>=35 then ‘THIRD CLASS’ Else ‘FAIL’ End Note : SQL Server supports calculated columns. Calculated columns are the columns for which values are calculated automatically based on expressions given for those columns during the table creation. For example to create marks table with total and average as calculated columns, the create table statement will be as follows. Create table Marks (SID smallint constraint SID_Fk references Student(SID), C Tinyint, Cpp Tinyint, SQL Tinyint, Total as C+Cpp+SQL, Average as (C+Cpp+SQL)/3, Grade varchar(30) ) Deleting Data From The Table When you want to delete a row or rows from the table then you can use delete command. Delete command has the following syntax. Delete [From] tableName [where Condition] Here also specifying where clause is optional and when you didn’t specify the where clause, every row in the table will be deleted. Ex 1: To delete a row from student table, whose SID is 1002, the delete statement will be as follows. Delete Student Where SID=1002 28

Ex 2: To delete all rows from marks table, the delete statement will be as follows. Delete Marks Truncate Command For deleting rows from a table you can also use truncate command. Differences between delete and truncate commands are as follows. Delete You can delete only specified rows using where clause Truncate It is not possible to delete specified rows from the table as this command doesn’t support where clause and this command is used only Deletes rows one by one Deleted rows can be rollback. Memory will not be released to server Syntax : Trucate table TableName when you want to delete all rows from a table. Deletes rows page by page. Hence deletion will be fast. Deleted rows can’t be rollback. Memory will be released to server

Retreiving Data
A statement that requests data from the database is called as a query. In SQL select statement is used to retrieve data from the database and hence the select statement is called as a query. Select statement has the following syntaxes. 1. Select * From TableName This syntax is used to retrieve every row from the table with information from every column of the table. Here * represents “all columns”. Examples: i. Display The Details of all employees in the company Select * From emp ii. Display the details of all students Select * from Student 2. Select Column1,column2,column3,… From TableName This syntax is used to retrieve the information from only specified columns of the table from every row of the table. Examples: i. Display Employee no,name,job and salary for every empoloyee select empno,ename,job,sal from emp

29

ii. Display sid and sname from student select sid,sname from student 3. Select */ColumnList From TableName Where Condition This syntax is used retrieve only specified rows from table. The given condition will be verified with every row and only the rows that satisfy the given condition will be displayed in the output. Examples: i. Display the details of employees working in department 30 Select * from emp where deptno=30 ii. Display the details of employees working as manager Select * from emp where job=’manager’ iii. Find employees whose salary is more than 2000 and less than 3000 Select * from emp where Sal>2000 and sal<3000 4. Select distinct ColumnList From TableName [Where Condition] Distinct is used to eliminate duplicate values in the output of a select statement. Distinct can be used only once in a select statement and it must be immediately after select key word. When you specify a single column in the selection list after distinct then duplicates will be eliminated in that column. When you specify multiple columns in the selection list after distinct then duplicates will be eliminated in the combination of values of specified columns. Examples : i. Find Department nos in which employees are working Select Deptno from Emp This query will display Department nos 10,20 and 30 with duplicates. To display the result without duplicates we have to write the query as Select Distinct Deptno from emp 5. Select [Distinct] */ColumnList From TableName [Where Condition] Order By ColumnName Asc/Desc Order By clause is used in select statement to arrange the rows in the out put in either ascending or descending order of specified columns In the order by clause. In order by clause you can specify more than one column and when you specify more than one column, first the rows are arranged in specified order of first column in order by clause and then if more than one row has same value in that column then those rows will be arranged in specified order of second column in order by clause and so on. Examples: i. Display all employees in the order of highest salary to lowest salary Select * from emp order by sal desc ii. Display all employees in alphabetical order of their name 30

Select * from emp order by ename 6. Select ColumnName AliasName, ColumnName AliasName,… From TableName Within the select statement you can give alias names for the columns so that column names will be changed in the output of the select statement. When alias name is more than one word then it is compulsory to include it in double quotes. Generally alias names are used for the expressions like “sal *12” Examples: i. Display empno,name,job,salary and annual salary for every employee Select empno,ename,job,sal,sal*12 as annualsal from emp

Predicates
SQL supports various key words and operators that can be used in where clause of select statement and these key words and operators are called as predicates. Among the predicates supported by SQL, Four predicates are as follows. 1. Between … And : This predicate is used to verify whether the given value exists in given range of values. This predicate can be used with numeric type of data as well as date type of data. Examples: i. Find all employees whose salary is more than 2000 and less than 3000 Select * from emp where sal between 2000 and 3000 ii. Find all employees who are joined in the company in the year 1982 Select * from emp where sal between ‘1/1/1982’ and ‘12/31/1982’ 2. In : This predicate is used to verify whether the given value exists in a given list of values. This can be used with numeric, character and date type of data. Examples: i. Find all employees whose salary is either 800 or 1250 or 1600 Select * from emp where sal in(800,1250,1600) ii. Find all employees who are working as either manager or clerk or analyst Select * from emp where job in (‘manager’,’clerk’,’analyst’) 3. Like : this predicate is used to verify for a specific pattern in character columns. This is used only with character type of data. With the like predicate you have to use two wild characters % and _ (Underscore). Examples: i. Find all employees whose name starts with ‘S’ Select * From emp Where Ename like ‘S%’ ii. Find all employees whose name ends with ‘E’ Select * from emp where ename like ‘%E’ 31

e. Ranking Functions Scalar Functions : The built in functions in SQL Server that work on a single value are called as scalar functions.713 7. base e logarithm. SQL also provides Built in functions. 9. 4.e. 8. 5. Built in functions in SQL are classified into following categories. Scalar functions are again classified into following categories based on data type on which they work. Examples: i. Exp(n) : Returns e raised to the power of n. Is Null : This predicate is used to verify for a null value in a given column. Log10(n) : Returns base 10 logarithm of n. i. 2. 6. a) Numeric Functions b) String Functions c) Date Functions d) Conversion Functions e) System Functions Numeric Functions : The scalar functions of SQL that work on numeric type of data are called as numeric functions. Degrees(n) : Converts the given n in radians to degrees. 32 . 10. 1. 11. Ceiling(n) : Returns smallest integer greater than or equal to n. Abs(n) : Returns absolute value of the given n i. Radians(n) : Converts the given n in degrees to radians. e is exponential whose value is constant and is 2. 3. n value without any sign.4. Find all employees who are not drawing commission Select * from emp where comm Is null Built In Functions As in other languages like C and C++. Aggregate Functions 3. Power(m. 1. Scalar Functions 2. Numeric functions in SQL are as follows. Sqrt(n) : Returns Square Root of given n.n) : Returns m raised to the power of n. Square(n) : Returns Square of given n. Log(n) : Returns natural logarithm of n. Floor(n) : Returns Largest integer less than or equal to n.

Len) : returns last Len characters from the string S1.D2) : calculates the difference between the two dates D1 and D2 and returns the result as an integer in units specified by the item. 9. Stuff(s1. Left(S1. DatePart(item. Pi() : Return mathematical constant pi value i. If t is specified as 1 then it truncates n to p decimal places instead of round the value. String Functions : The built-in functions of SQL that work on string type of data are called as string functions.e. DateDiff(item.D1.t) : Rounds the given in n to p decimal places. 6.s2. 5.[pos]) : returns the starting position where the partial string s1 first occurs in the string s2.s2) : Replaces the partial string s1 with the partial string s2 starting at position a. Rtrim(S1) : Removes trailing blank spaces in the string s1. Sin(n) : Returns sine value of given n in radians. Tan(n) : Returns tangent value of given n in radians. DateName(item.n.p. 1. 10.n. 5.D) : returns the specified item of the date D as a string. Cos(n) : Returns cosine value of given n in radians. 14. String functions in SQL are as follows. Soundex(a) : Returns how the given string is pronounced in a four character soundex code. Upper(s1) : Converts all lowercase letters of the string s1 to upper case letters. 4.D) : Adds the number n no. Char(int) : Converts ascii code to the equivalent character. Reverse(S1) : Reverses the string S1. Right(S1. 2. 3. 7.a. 15. of characters. 1 if n is positive and 0 if n is zero. 11. ASCII(char) : Converts the specified character to the equivalent ascii code.12. Date Functions : The built-in functions of SQL that work on date type of data are called as date functions and date functions in SQL server are as follows. Substring(S1. 13. DateAdd(item.a. 1.Len) : returns first len characters from the string S1. 33 . 8. 2. 3.len) : creates a partial string from string s1 starting at the position a with a length of len. 16.D) : returns the specified item of a date D as an integer. Lower(S1) : Converts all uppercase letters of the string s1 to lower case letters. 13. 3. Ltrim(s1) : removes leading blank spaces in the string s1.14 17. 4. of units specified by the item to the given date D and returns a date. GetDate() : Returns the current system date and time. Round(n. Returns zero if s1 does not exist in s2. CharIndex(s1. 12. replacing n no. Sign(n) : Return -1 if n is negative.

user_name(uid) : returns the name of the user with id uid. 3. Object_ID(objname) : returns the identifier of the database object objname. DB_Id(Db_name) : returns the id of the database db_name. 34 . 2. Object_name(obj_id) : returns the name of the database object with id obj_id.Conversion Functions : The Built-In functions of SQL Server that are used to convert one type of data to another are called as conversion functions and conversion functions in SQL Server are as follows.a) : Equivalent to cast. Convenient Aggregate Functions 2. 8. Min(Col) : Returns the smallest value among all values in the given column. 6. of rows in the given table.Col) : returns the length of the column belonging to a database object obj. Avg(Col) : Returns average of all values in the given column. 10. 9. 5. Current_TimeStamp : returns the current timestamp of the database. Datalength(s1) : calculates the length of the result of the expression s1. but the arguments are specified differently. Col_Length(obj. User_Id(username) : returns the id of specified user name. 2. Super Aggregates 1.S_Id) : returns the name of the column belonging to the object obj_id with the identifier s_id. 7. Statistical Aggregate Functions 3. Cast(a as type[(length)]) : converts an expression a into the specified data type type. Aggregate Functions : The Built-In Functions of SQL Server that operate on a set of values are called as aggregate functions. 4. Convenient Aggregate Functions : o o o o o o Sum(Col) : Returns the sum of all values in the specified column. of non-null values in the given column. 1. Count(*)/Count_Big(*) : Returns the total no. Count(Col)/Count_Big(Col) : Returns the no. Aggregate functions are again classified into following categories. System Functions : The SQL Server system functions provide extensive information about database objects. Col_Name(Obj_Id. Convert(type[(length}]. DB_Name(Db_id) : returns the name of the database with id Db_id. Max(Col) : Returns the highest value among all values in the given column. 1. 1.

Hence we must use having instead of where clause. Calculate sum of salaries of employees job wise Select Job. Stdev(Col) : Returns standard deviation of all values in the given column. Find the total salary paid to employees job wise In each department Select Deptno. For example if you want to find the departments with three or more employees then the query will be as follows.Sum(Sal) from emp group by Deptno. Group By : Group By is used to group the rows of table based on values of a given column and applies the aggregate function on each group separately. ii. Statistical Aggregate Functions : Var(Col) : Returns Variance of all values in the given column. Because where clause can check a condition without any aggregate function but not a condition with aggregate function.2.Sum(sal) from emp group by job iii. This contains an aggregate function.Count(*) from emp group by Deptno iv. Find the number of employees working in each department Select Deptno.job Rule : A rule to be followed when working with group by is the columns that are selected in the select list except aggregate functions must be in group by.Sum(Sal) from emp group by Deptno In the above query group by will divide the table in to groups based on deptno and then calculates sum(sal) for each group separately. Examples: i.Count(*) From Emp group by Deptno having Count(*)>=3 In the above query condition is Count(*)>=3. Having : Having is used to check the condition that contains an aggregate function and in this case it is not possible to use where clause. Varp(Col) : Returns Variance of population of all values in the given column. calculate sum of salaries of employees department wise Select Deptno. o o o o 35 . which will give the sum of salaries of employees department wise. Stdevp(Col) : Returns Standard Deviation of population of all values in the given column. Select Deptno.Job.

Cube : Cube is used to calculate sub totals at the end of each group based on values of second column in group by along with the result of rollup when data is grouped on more than one column in group by. the row aggregate function is applied to all rows of a result query. Sum(Sal) from emp group by Deptno. Roll up and Cube can be used only with group by. then the following query is used.Job with roll up / with cube COMPUTE Clause : The compute clause uses aggregate functions to calculate summary values that appear as additional rows in the result of a query. The main difference between the use of the GROUP BY clause and grouping using the OVER clause is that the OVER 36 . Super Aggregates : SQL Server provides Two super aggregates Cube and Rollup.Find the Jobs whose average salary is more than 2000 Select Job. Example : Display Employee Details Along with Total salary department wise Select * from Emp order by Deptno Compute Sum(sal) by Deptno OVER Clause : OVER Clause can be used to group the data like GROUP BY. of employees more than 3. BY defines the grouping form of the result. The aggregate functions used with the compute clause are referred to as row aggregate functions. Avg(Sal).Count(*) from emp group by Deptno Having avg(sal)>2000 and count(*)>3 Rule : A Rule to follow when using having clause is a corresponding group by is must. The ORDER BY clause is required if the COMPUTE clause with BY is used. Job. Roll Up : Roll up is used to calculate sub totals at the end of each group based on values of first column in group by when you group the data on more than one column. Select Deptno. Select Deptno . The compute clause has an optional BY portion. If BY is omitted.Avg(Sal) from emp group by job having Avg(sal)>2000 Find the Departments whose average salary is more than 2000 and no. For example if you want to calculate sub totals at the end of each department when grouping data on both Deptno and Job.

if two or more rows in a result set have same value in the ordering column. Example : Display Employee Details Along with Total salary department wise Select *.e. Example : Display Employee details along with a rank department wise Select empno.clause displays each of the rows from a group separately. while the GROUP BY clause displays only one row for each group.ename.job. In other words. ROW_NUMBER() : It returns the sequential number of a row within a result set.ename.Dense_rank() over(partition by Deptno order by Sal Desc) as Rank from emp TOP n Clause : This clause specifies the first n rows of the query result that are to be retrieved. DENSE_RANK() : This function works same as Rank(). The RANK function uses logical aggregation.job.rank() over(order by sal desc) as Rank from emp 2. starting at 1 for the first row. they will have the same rank. Example : Display employee details along with a rank based on salary Select empno.sal. functions that return a ranking value for each row in a partition group.Sum(Sal) over(partition by deptno) from emp RANKING FUNCTIONS SQL Server 2005 defines several functions that are categorized as ranking functions.Dense_rank() over(order by sal desc) as Rank from emp 2. In that case.job. The additional option WITH TIES specifies 37 . the first n percent of the rows are retrieved from the result set. The TOP n clause can also be used with the additional PERCENT option. i. except that it will not skip a rank when two or more rows got the same rank. The system supports following ranking functions.sal. 1. PARTITION BY : Ranking functions can be applied to partitions by using partition by clause within the OVER() clause along with ORDER BY.sal.ename.. Example : Display employee details along with a rank based on salary Select empno. RANK() : This function is used to return a number that specifies the rank of the row among all rows.

job.20 Select Job From Emp Where Deptno=10 Union Select Job From Emp Where Deptno=20 2. Example : i.Sal from emp order by sal desc SET OPERATORS SQL Server supports the following three set operators that connect two or more queries. INTERSECT : The intersection of two tables is the set of rows belonging to both tables. Example : Find jobs available in departmenents 10.ename. UNION : The result of the UNION of the two sets is the set of all elements appearing in either or both of the sets by eliminating duplicate values.sal from emp order by sal desc ii. If UNION ALL is used. including duplicates.that additional rows will be retrieved from the query result if they have the same value in the ORDER BY column as the last row that belongs to the displayed set. The difference of two tables is the set of all rows. Find Top3 salaried employees Select Top 3 empno. are to be displayed. 1. find Top 10% salaried employees Select Top 10 Percent Empno.ename.job. Example : Find jobs available Both in departmenents 10 and 20 Select Job From Emp Where Deptno=10 Intersect Select Job From Emp Where Deptno=20 3. Example : Find jobs available in departmenent 10 And not in 20 Select Job From Emp Where Deptno=10 38 . EXCEPT : This finds the difference of two tables. where the resulting rows belong to the first table but not to the second one. UNION 2. EXCEPT 1. INTERSECT 3. all resulting rows.

Example : Display Employee Details along with department details in which employee is working. Join is Equi join 2.Deptno 2.Loc From Emp E join Dept D on E. 1. Select * From Emp E join Dept D on E. OUTER JOIN : The join statement that displays the data that doesn’t satisfy the given join condition along with the data that satisfies the condition is called as outer join.Deptno=D.*. Joining in SQL Server is classified as follows.Deptno=D.Deptno 3. Hence join is needed whenever we have to retrieve data from more than one table. The corresponding columns in all select statements must be of same type JOINING The process of combining data from more than one table using a single select statement is called as joining. a. Within a relational database data will not be stored in a single table. Left Outer Join : the outer join that displays rows from LHS table that does not contain a corresponding row in RHS table is called as Left Outer Join. 39 . NATURAL JOIN : A join is called as natural join when it satisfies the following. Select E. All common columns in the tables that are joined are used in Where clause 3.Except Select Job From Emp Where Deptno=20 Rules 1.Dname. All the select statements must select same number of columns 2. Outer join is again three types. Only one set of common columns is displayed in the output Example : Display Employee Details along with department details in which employee is working. EQUI JOIN : Joining more than one table by using a join condition that uses = operator is called as equi join. 1.

Deptno 4. SELF JOIN : The join statement that joins a table to it self is called as self join.E.Job. THETA JOIN : The join operation that uses a condition that contains an operator other than = is called as theta join. of join conditions must be one less than no.E.E. Right Outer Join : the outer join that displays rows from RHS table that does not contain a corresponding row in LHS table is called as Right Outer Join. SUB QUERIES A statement that requests data from the database is called as a query. c.Deptno=D. A select 40 .ename. CROSS JOIN : The join statement without any join condition is called as cross join. Example : Display Employee Details along with his/Her manager name Select E. Example : Display Employee Details by associating every employee with every department Select * From Emp E Cross join Dept D 6. Select is used to request data from the database and hence select statement is called as a query.b.M.E.Empno Rule : A rule to be followed when writing a join statement with SQL server Syntax is no. Example : Display Employee Details along with Grade of employee based on salary Select *.Mgr. Full Outer Join : The outer join that displays rows from both the tables that doesn’t contain a corresponding row in the opposite table is called as full outer join.Ename From Emp E join Emp M on E.Mgr=M.Sal.Empno.grade From Emp join salgrade on Sal between losal and hisal 5. The result of this cross join is called as Cartesian product. of tables on which you perform join. Also display the details of departments in which there are no employees. Example : Display Employee Details along with department details in which employee is working. Select * From Emp E right outer join Dept D on E.

statement within another select statement is called as a sub query. Find Employees not working in dept 30 and drawing salary more than any one employee in dept 30. Select * From Emp where Deptno= (Select Deptno From Dept Where Dname=’Sales’) ii. When a sub query returns more than one row then it is not possible use the operators like =. Sub queries are classified as follows. Single Row Sub Queries 2.<=. Example : i. SINGLE ROW SUB QUERIES : The sub query that returns only one row is called as single row sub query. Co-related sub queries 1. MULTI ROW SUB QUERIES : The Sub query that returns more than one row is called as multi row sub query. Any and All. and >=.>. Nested Sub Queries 4.<. To make this possible SQL Server provides two operators. Example : i. “Any” operators returns true when the given condition is true with at least one value returned by the sub query and “All” operator will return true only when the condition is true with every value returned by the sub query. Multi Row Sub Queries 3. Find The Employee Who is drawing highest salary. 1. Select * from Emp where Deptno!=30 and sal> Any (Select Distinct sal from emp where deptno=30) iii. Find highest salaried employees department wise Select * from emp where sal in (Select max(sal) from emp group by deptno) ii. Find Employees not working in dept 30 and drawing salary more than all employees in dept 30. Select * from emp where sal= (Select max(sal) from emp) 2. Find The Employees Working In Sales Department. Select * from Emp where Deptno!=30 and sal> All (Select Distinct sal from emp where deptno=30) 41 .

Empno=E. We can find a topic in a book very fast with the help of an index. SQL Server provides two operators that can be used only with co-related sub queries.Mgr) iii.Deptno=S. Select * From emp M where exists (Select * From Emp e where M. Example : i. Find Employees To Whom At least one employee is Reporting.Deptno) ii. “Exists” returns true only when the co-related sub query returns at least one row and “NotExists” will return true only when the co-related sub query doesn’t return any rows. An 42 . Find Departments in which there are no employees Select * From Dept D where not exists (Select * From emp Where D. then data retrieval will be very fast.Deptno=E. Exists and NotExists. CO-RELATED SUB QUERIES : The sub query that refers a column of the outer query within its condition is called as co-related sub query. Select * from Emp E where Sal > (Select Avg(sal) from Emp S where E. NESTED SUB QUERIES : The sub query that contains another sub query within it is called as nested sub query. Example : Find Employees whose salary is more than average salary of sales Dept. Select * from emp where sal > (Select Avg(sal) from emp where deptno= (Select Deptno from Dept where Dname=’Sales’)) 4. In the same way if an index is available in SQL Server.Deptno) INDEXES An index in SQL Server is similar to an index in a book.3. Hence the main purpose of an index is to speed up the data retrieval. Find Employees whose salary is more than average salary of the dept in which he is working.

Create Index DnoIDX on Emp(Deptno Asc) ii. Syntax : Alter Index IdxName on TableName Rebuild/Reorganize/Disable Rebuild will rebuild the entire index. then along with the index unique constraint will also be created on that column. If the index is created on more than one column. When an index is a clustered index.Deptno Desc) SQL Server will use index only in the following situations 1.Col2. To create an index. Reorganize will reorganize the leaf level nodes of Index Disable will disable the index and to enable the index use rebuild option. Altering An Index After creating index you can alter the index using alter index command that has the following syntax. 2. Deleting an Index To Delete an index use drop index command as follows. Create [Unique] [Clustered/NonClustered] index idxname on tablename(Col1. then the index is called as single column index and when the index is created on more than one column. Example : i. then the physical order of rows in the table will not be in the order of rows in the index. The column on which index was created is referred in where clause. all the columns on which index was created must be referred in where clause. Drop Index IdxName 43 . the following syntax is used.index is maintained by SQL server in the form of a B-Tree data structure. Create Index DnoJobIDX on Emp(Job Asc. Create an index on deptno column of emp table.…) When we use Unique keyword during the creation of index. When an index is created on a single column. then the physical order of rows in table will be in the same order of rows in index and when an index is an unclustered index. then the index is called as a multi column index or composite index. Create An Index On Deptno And Job Columns Of Emp Table.

3. If the view is created from a select statement that combines the data from more than one table. Once a view is created you can use it like a table and you can perform any DML operation on that view as you perform on table.Col2. A view is not an independent object and is created from a table or another view. then insertion and updation can be done for the rows that doesn’t satisfy the condition specified in where clause of select statement of the view and if a view is created with with check option clause then insertion and updation of rows in the view is not possible if the row fails to satisfy the condition specified in where clause of the select statement of the view. Creating A View : Create view viewname(Col1.…) [with encryption] as select statement [with check option] Example : Create a view that will provide access to only dept 10 rows from emp table Create View Emp10 As Select * From emp Where Deptno=10 If we create a view without with check option clause. The main purpose of a view is as follows. To hide the complexity of a complex query like join or subquery.VIEWS A view is a logical object that doesn’t contain data directly. the select statement written for the view will be executed and data is retrieved from the base table of the view. If the select statement of the view contains distinct or group by. 1. To restrict the access to specific rows and or columns in the table. 2. 1. Complex View A view is called as a complex view if it satisfies any of the following conditions. 44 . But any modification made to the view will be done in the table from which the view was created and whenever you select data from the view. To restrict the insertion and updation to only specified range of values. 2.

Dname. Example : Create a view that will contain data of employees along with department details in which employee is working. if the Select statement contains Aggregate functions. any changes made to the database will not be made permanent to the database and user will have the choice to cancel 45 .Col2.view_table_usage where table_name='Emp' getting definition of a view sp_helptext ‘viewname’ TRANSACTION PROCESSING A series of changes made to one or more tables of the database is called as a transaction. If the select statement of the view contains an expression like Sal*12 as a column. But user can select data from the complex view. When we make changes to the database by creating a transaction.3. Performing DML operations is not possible on complex view. Syntax : Alter View ViewName[(Col1. 4.…)] As Select Statement [With Check Option] Deleting A View Drop view viewname Getting Details of a View select * from information_schema. Create View EmpDept as Select E.Loc from emp join dept Where e.deptno=d.*.deptno Altering a View A view can be altered by using Alter view command when you want to change the definition of the view.views getting list of view available on a table select * from information_schema.

after image will be used to make the changes in current transaction permanent to the database other wise before image will be used to cancel the changes made to the database. 1. 2. Save Transaction : This command will create a save point that will divide the transaction in to more than one part so that user can commit one part while rollback the other part. Commit Transaction : This command will make changes in the current transaction permanent and ends the transaction. Whenever a change was made to the database in a transaction. 4. Begin Transaction : This command will start a transaction. If a transaction was started and there is system failure before the transaction was committed or rollback.those changes or make those changes permanent. When user rollback the transaction to a save point. Rollback Transaction : This command will cancel the changes in the current transaction and ends the transaction. In case transaction was committed. 3. For transaction processing SQL Server provides the following commands. SQL Server will use log files to record the changes and uses the information in log file to commit or rollback the changes in current transaction. then all the changes in the current transaction will be automatically rollback. During the transaction processing. before image of the table and after image of the table are written to the log file. all the changes made to the database prior to the save point will be committed while all the changes after the save point are rollback. 46 .

Block : A set of statements written within Begin and End statements is called as a block. Hence procedural features are provided for SQL.PROCEDURAL STATEMENTS SQL is a non-procedural language and hence it is very easy to work with SQL. Print ‘Out put To Display To The User’ Declaration : to declare variables within a block use Declare key word and a variable in SQL Server must be prefixed with @ Declare @Var1 Datatype. But solving some complex queries is not possible is not possible using SQL. use set statement. which is called as PL/SQL.… Setting Value : To set value for a variable. @Var2 Datatype. Set @Var=Value IF If condition Begin 47 . Begin ------------End Print : Print command is used to print any output to the out put window.

This example will determine whether an integer is even or odd Begin 48 .Statements End If Condition Begin Statements End Else if Condition Begin Statements End Else if condition Begin Statements End Else Begin Statements End WHILE While Condition Begin Statements End Examples : i. @S int Set @A=10 Set @B=20 Set @S=@A+@B Print ‘Sum is ‘ + cast(@S as varchar(5)) End ii.@B int. This examples adds two numbers and prints the sum Begin Declare @A int.

This Example will print integers from 1 to 10 Begin Declare @N int Set @N=1 While @N<=10 Begin Print @N Set @N=@N+1 End End STORED PROCEDURES SQL Server supports the creation of user defined functions as well as procedures. the following syntax is used.Declare @N int Set @N=5 If @N%2=0 Print ‘Even Number’ Else Print ‘Odd Number’ End iii. …) Returns Datatype [with encryption] as Begin Statements Return Value End Sp_Helptext System procedure can be used to get the source code written for a function or procedure. An user defined function is a stored subprogram that will return a value back to the calling location. To create a function. 49 . which are called as stored Subprograms. @Param2 Datatype. Create Function FunctionName(@Param1 Datatype.

Drop Function FunctionName A procedure is a stored subprogram that will not return a value back to the calling location and syntax for creating a procedure is as follows.SP_HelpText ‘ProcName’ When you create the stored sub program with with encryption then source code will not be displayed and will be encrypted. you can use select statement as follows Select Dbo. Create a Function that will calculate Sum of three integers Create Function Total(@A int. 50 [with .…) Example : i. Create A Function That Will Generate New Deptno Automatically. Create Function NewDno() returns int as Begin Declare @NDno int Set @NDno=(Select isnull(max(deptno). use Drop Function Command as follows.Functionname(Arg1.@B int.…) encryption] as Begin Statements End To execute a procedure. Create Procedure ProcedureName(@param1 Datatype. To execute an user defined function. @C int) returns int as Begin Return @A+@B+@C End ii.0)+10 from dept) Return @NDno End To Delete a function. @Param2 Datatype.Arg2. use execute command as follows.

Advantage is a procedure can be called with variable number of arguments. Create A Procedure To Update A Row Of Dept Table.@L) End ii.20.@Dn varchar(30).@E int=0) As Begin Print @A+@B+@C+@D+@E End Execute MySum 10. use Drop Procedure command as follows.20 Execute MySum 10. Example : This example will create a procedure that can be called with 2 or 3 or 4 or 5 integers to calculate Sum. When an argument is created as default argument. @Dn varchar(30). Create Procedure InsertDept(@Dno int. … Example : i.Execute ProcName Arg1 . Functions doesn’t support default arguments.30 51 .@B int. Arg3. Drop Procedure Procedurename Default Arguments A procedure can be created with default arguments. Create A Procedure that will insert a row into Dept table.@Dn.@D int=0.Loc=@L where Deptno=@Dno End iii. Create A Procedure To Delete A Row From Dept table. Create procedure MySum(@A int.@L varchar(30)) as Begin Insert into Dept values(@Dno. it is optional to pass a value to that argument during function call and if you don’t pass a value then default value will be used other wise the value you pass will overwrite the default value. Create Procedure UpdateDept(@Dno int. A default argument is an argument that is initialized within the procedure creation. Create procedure DelDept(@Dno int) As Delete Dept Where Deptno=@Dno To Delete a procedure. Arg2.@l varchar(30)) as Begin Update Dept Set Dname=@Dn. @C int=0.

Cursor Declaration : first we have to declare the cursor.Execute MySUm 10.@B int Set @A=10 Set @B=20 Print ‘Before Swap A = ‘ + cast(@A as varchar(3)) + ‘ B = ‘ + cast(@B as varchar(3)) Swap @A output.20.40 Execute mySum 10. 1. Any changes made to input parameters within the function or procedure will not reflect in arguments passed to them. By default every parameter is an input parameter. But any changes made to output parameters will reflect in arguments. Begin Declare @A int. During the declaration a name was given to the cursor and a select statement is associated with the cursor.30.40. 52 .30. @Y int output) As Begin Declate @T int Set @T=@X Set @X=@Y Set @Y=@T End To execute this procedure we have to create a block as follows. To work with cursors we have to follow the following steps. But with the help of cursors we can access the rows of a table one by one sequentially.50 Output Parameters In SQL Server Parameters of functions and procedures are classified into input parameters and output parameters.@B output Print ‘After Swap A = ‘ + cast(@A as varchar(3)) + ‘ B = ‘ + cast(@B as varchar(3)) End Cursors Cursors are used within a stored procedure when you want to access the rows of a table in a sequence. Create procedure Swap(@X int output.20. Actually we can access only one row at a time within a stored procedure. Example : This example will create a procedure Swap that will swap two integers.

Open CursorName 3.@J.@J varchar(30). When we open the cursor. You can verify whether fetch was success or not by using the system variable @@FETCH_STATUS. Opening Cursor : Before using the cursor. it is not possible to fetch the rows.2) Declare MyCur Cursor for select empno. Fetching Rows : Retrieving a row in the buffer pointed by cursor into local variables is called as fetching. Deallocate Cursorname Example : This example will Read one by one record from Emp table and increments salary based on job Create procedure Increment as Begin Declare @Eno int. the select statement associated with the cursor will be executed and the returned rows will be stored in buffer and cursor will point to this buffer. As it is not possible to make changes to the data within the buffer. When the cursor was closed. But you can reopen the cursor to fetch rows.sal from emp Open MyCur Fetch next from mycur into @Eno. Fetch Next / Prior / First / Last / Absolute n / Relative n from Cursorname To Local variables list 4.job.@S decimal(7. If fetch was success this variable will contain “0” other wise a negative value. Close CursorName 5. Deallocating Cursor : Finally you can deallocate cursor so that memory resources associated with the cursor will be released. cursor must be opened.@S While @@Fetch_Status=0 53 .Declare Cursorname Cursor [forward_only/Scroll] [static/dynamic/keyset] for select statement 2. Closing Cursor : After the work with cursor was finished. cursor must be closed. first they must be copied to the local variables.

@S End Close Mycur Deallocate Mycur End 54 .Begin If @J=’President’ Set @S=@S+5000 Else if @J=’Manager’ Set @S=@S+3000 Else if @J=’Analyst’ Set @S=@S+2000 Else if @J=’Salesman’ Set @S=@S+1500 Else Set @S=@S+700 Update Emp set Sal=@S where Empno=@Eno Fetch Next From MyCUr into @Eno.@J.

3. To record Audit information of a table. To Create procedural integrity constraints 2. Inserted table will contain new values of the row and deleted table will contain old values of the row. Purpose of trigger is 1. Declarative integrity constraints are the constraints that can be specified during table creation and procedural integrity constraints are the constraints that are not possible to specify during table creation and for the specification of procedural integrity constraints triggers are used.delete 55 .update. Create trigger Sunday On Dept For insert. This example will create a trigger that will restrict the user from performing DML operation on Dept table on Sunday.TRIGGERS A trigger is like a stored procedure stored within the database. Constraints within SQL Server are classified into declarative integrity constraints and procedural integrity constraints. While working with the triggers SQL server will automatically create two virtual tables inserted and deleted. the trigger will be executed automatically based on the DML event specified for the trigger during trigger creation. But unlike stored procedure. To Make DML operation possible on complex view Trigger creation has the following syntax Create trigger trigger name On Table/View name For/After/Instead of Insert / Update / Delete As Begin Statements End Examples : 1.

update.@OL.@L varchar(30) Set @Odno=(Select Deptno from Deleted) Set @Odn =(select Dname from Deleted) Set @OL=(Select Loc From Deleted) Set @Dno=(Select Deptno From Inserted) Set @Dn=(Select Dname From Inserted) Set @L=(Select Loc From Inserted) Insert into AuditDept values(@ODno.getdate())) If @Day=’sunday’ Begin Print ‘Transaction Are Not Allowed on Sunday’ Rollback Transaction End End 2..mgr.@OL varchar(30) Declare @Dno int.sal. Create trigger Audit on Dept for insert.@Dn. DML operations will not be possible on that view. This example will create a trigger on dept table that will record audit information of dept table in to another table called auditdept.hiredate. which a complex view created from emp and dept tables and will make insert possible on this view. Create Trigger InsteadInsert on Empdept instead of insert as begin Insert into emp select empno.@ODn varchar(30).@ODn.@Dno.@Dn varchar(30).job. Example: This example will create trigger on EMPDEPT view.deptno from inserted.delete as begin Declare @Odno int.@L.As begin Declare @Day varchar(30) Set @Day=(Select datename(dw.Getdate()) End Instead of triggers When a view is created as complex view. End 56 .ename.comm. Instead of triggers are used to make DMLoperations possible on a complex view.

use SP_HELPTEXT system procedure.Deleting A Trigger To Delete a trigger use drop trigger command as follows Drop trigger TriggerName To get the list of trigger created on a table use the system procedure SP_HELPTRIGGER SP_HELPTRIGGER ‘TableName’ To get the code written for either a trigger or function or procedure or view. SP_HELPTEXT ‘procedurename’ 57 .

and integration with heterogeneous systems. Figure 1: The SQL Server 2005 Data Platform The SQL Server data platform includes the following tools: • Relational database: Secure. • Analysis Services: Online analytical processing (OLAP) capabilities for the rapid. scalable concurrency with secondary data stores for enterprise reporting solutions. Web-based reports. and automation of routine tasks. integrated end-to-end data solution that empowers users across your organization by providing them with a secure. high systems availability. transform. SQL Server 2005 delivers powerful. and delivering both traditional. interoperability with existing systems. timely information updates to a variety of connected and mobile devices. and productive platform for enterprise data and business intelligence (BI) applications. • Notification Services: Advanced notification capabilities for the development and deployment of scalable applications that can deliver personalized. Figure 1 shows the layout of the SQL Server 2005 data platform. managing. familiar tools to Information Technology professionals as well as to information workers. sophisticated analysis of large and complex datasets using multidimensional storage. managing. SQL Server 2005 provides a complete data solution for enterprises of all sizes. • Integration Services: Extract. and using enterprise data and analytical applications on platforms ranging from mobile devices to enterprise data systems. • Reporting Services: A comprehensive solution for creating. reliable. paper-oriented reports and interactive. reducing the complexity of creating. Through a comprehensive feature set. reliable. scalable. and load capabilities for data warehousing and enterprise-wide data integration. 58 . highly available relational database engine with improved performance and support for structured and unstructured (XML) data. • Replication Services: Data replication for distributed or mobile data processing applications. deploying.Microsoft SQL Server 2005 Overview SQL Server Data Platform SQL Server is a comprehensive. including existing Oracle databases.

The goal is to extend BI to all users within an organization and ultimately to allow users at all levels of the organization to make better business decisions based on one of their most valuable assets—their data. and data mining. and loading (ETL). timely business information that is tailored to their specific needs. transformation. SQL Server 2005 also includes many new and improved capabilities to help make your Information Technology staff more productive. users and Information Technology professionals across your organization will benefit from reduced application downtime. • Increase productivity: Through comprehensive business intelligence capabilities and integration with familiar tools such as the Microsoft Office System. In addition. SQL Server 2005 includes key enhancements to enterprise data management in the following areas: • • Manageability Availability 59 . and maintenance costs for rapid return on your database investment. increased scalability and performance. The SQL Server 2005 data platform provides organizations of all sizes with the following benefits: • Leverage data assets: In addition to delivering a secure. deployment. data mining. automated management tools for database administrators. SQL Server 2005 provides information workers across your organization with critical. analysis. OLAP. Every major subsystem in SQL Server ships with it’s own object model and set of APIs to extend the data system in any direction that is unique to your business. and management of line-of-business and analytical applications by providing a flexible development environment for developers and integrated. SQL Server 2005 enables customers to get more value from their data by including embedded functionality such as reporting. Standard data access protocols drastically reduce the time it takes to integrate data in SQL Server with existing systems. • Lower total cost of ownership (TCO): The integrated approach and focus on ease-of-use and deployment provides the industry’s lowest upfront. implementation. data extraction. data and the systems that manage that data must always be secure yet available to your users. and reporting that are tightly integrated with Microsoft Visual Studio® to provide end-to-end application development capabilities. What’s New in SQL Server 2005 Enterprise Data Management In today’s connected world. reliable database for line-of-business and analytical applications. • Development tools: SQL Server offers integrated development tools for the database engine.• Management tools: SQL Server includes integrated management tools for advanced database management and tuning as well as tight integration with tools such as Microsoft Operations Manager (MOM) and Microsoft Systems Management Server (SMS). With SQL Server 2005. native Web service support is built into SQL Server to ensure interoperability with other applications and platforms. and tight yet flexible security controls. • Reduce Information Technology complexity: SQL Server 2005 simplifies the development.

Management Studio also hosts tools for scheduling SQL Server Agent jobs and managing maintenance plans to automate daily maintenance and operation tasks. Analysis Services. These Dynamic Management Views (DMVs) provide greater transparency and visibility into the database and a powerful infrastructure for proactive monitoring of database health and performance. and optimize enterprise data and analytical applications. In fact. editing and managing scripts and stored procedures using Transact-SQL. The integration of management and authoring in a single tool coupled with the ability to manage all types of servers provides enhanced productivity for database administrators. locking. Proactive Performance Monitoring and Performance Tuning SQL Server 2005 exposes more than 70 new measures of internal database performance and resource usage from memory. As an enterprise data management platform. as well as Integration Services.NET Framework assembly. It provides an extensible management infrastructure that can be easily programmed using SQL Management Objects (SMO). creating SQL Server Agent jobs. manage. SMO is implemented as a Microsoft . viewing server objects. additional backup and restore capabilities. Database administrators can perform several tasks at the same time including: authoring and executing a query. creating new databases. and SQL Mobile across large numbers of distributed servers and databases. Availability Investments in high availability technologies. such as programmatically retrieving configuration settings. which was included with earlier versions of SQL Server. SQL Server Management Studio hosts a development environment for authoring. managing an object. You can use SMO to automate common SQL Server administrative tasks. monitoring system activity. SQL Server Management Studio SQL Server 2005 simplifies management by providing one integrated management console to monitor and manage the SQL Server relational database. and scheduling backups. Management Studio is readily integrated with source control. and SQL Server Mobile Edition. Notification Services. Multidimensional Expressions (MDX). applying Transact-SQL scripts. reliable. Innovative high 60 . and tune all of the databases and associated services across your enterprise. enabling users to customize and extend their management environment and Independent Software Vendors (ISVs) to build additional tools and functionality to further extend the capabilities that come out of the box. Reporting Services. SQL Management Objects SQL Management Objects (SMO) is a new set of programming objects that exposes all of the management functionality of the SQL Server database. Management Studio was built with SQL Management Objects. and scalable replacement for Distributed Management Objects (DMO). and scheduling to transactions and network and disk I/O. it provides a single management console that enables data administrators anywhere in your organization to monitor.• • Scalability Security Manageability SQL Server 2005 makes it simpler and easier to deploy. and replication enhancements will enable enterprises to build and deploy highly available applications. and viewing online help. manage. The SMO object model is a more secure. XMLA.

database mirroring. and enhanced online operations will minimize downtime and help to ensure that critical enterprise systems remain accessible. Database Mirroring Database mirroring allows continuous streaming of the transaction log from a source server to a single destination server. The secondary instance detects failure of the primary server within seconds and accepts database connections immediately. Figure 2 shows the basic configuration of database mirroring. Notification Services. Figure 2: Basic Configuration of Database Mirroring Failover Clustering Failover clustering is a high availability solution that exploits Microsoft Windows® Clustering Services to create fault-tolerant virtual servers that provide fast failover in the event of a database server failure. SQL Server failover clustering is now a complete fault-tolerant server solution. database snapshots. The maximum number of cluster nodes has been increased to eight. In SQL Server 2005.availability features such as. read-only views of a database. and SQL Server replication. reconnect to same IP No impact Yes Yes No 61 . Availability Feature Automatic Failover Transparent Client Redirection Impact on Overall Throughput Zero Work Loss Requires Certified Hardware Provides Redundant Data Database Snapshots SQL Server 2005 introduces the ability for database administrators to create instant. applications can immediately reconnect to the database on the secondary server. auto-redirect No impact to minimal Yes No Yes Failover Clustering Yes Yes. support for failover clustering has been extended to SQL Server Analysis Services. In the event of a failure of the primary system. failover clustering. Database mirroring works on standard server hardware and requires no special storage or controllers. We will review these enhancements in greater detail in this section. The database snapshot provides a stable view without the time or storage overhead of creating a Database Mirroring Yes Yes.

Users can reconnect to a recovering database after the transaction log has been rolled forward. Replication Replication is designed to increase data availability by distributing the data across multiple database servers. Fast Recovery SQL Server 2005 improves the availability of SQL Server databases with a new faster recovery option. The connection is activated by members of the sysadmin fixed server role and is only available through the SQLCMD command prompt utility either locally. Earlier versions of SQL Server require that you bring a database offline before you restore the database. Dedicated Administrator Connection SQL Server 2005 introduces a dedicated administrator connection to access a running server even if the server is not responding or is otherwise unavailable. As the primary database diverges from the snapshot. and inserts) to the underlying table or clustered index data and any associated indexes during index data definition language (DDL) execution. or from a remote machine. SQL Server 2005 offers enhanced replication using a new peer-to-peer model that provides a new topology in which databases can be synchronized transactionally with any identical peer database. the server workload allows index operations to take advantage of parallel processing SQL Server 2005 also introduces the ability to perform a restore operation while an instance of SQL Server is running. Thus the snapshot may be used to quickly recover from an accidental change to a database by simply reapplying the original pages from the snapshot to the primary database. snapshot isolation. Online restoration capabilities improve the availability of SQL Server because only the data that is being restored is unavailable. the snapshot adds its own copy of pages as they are modified. The online index option allows concurrent modifications (updates. The partitioning of large tables and indexes significantly enhances query performance against very large databases. Online Operations (index operations and restore) The ability to create. With support for online index operations. Availability is increased by allowing applications to scale out the SQL Server read workload across databases. Earlier versions of SQL Server required users to wait until incomplete transactions had rolled back. and 64-bit support will enable you to build and deploy your most demanding applications using SQL Server 2005. or drop an index online is an enhanced feature of SQL Server 2005 that augments the indexing capabilities of earlier versions of SQL Server.complete copy of the database. Scalability Scalability advancements such as table partitioning. you can add indexes without interfering with access to tables or other existing indexes. This allows you to execute diagnostic functions or Transact-SQL statements in order to troubleshoot problems on a server. even if the users did not need to access the affected parts of the database. deletes. Additionally. Table and Index Partitioning 62 . The rest of the database remains online and available. rebuild.

This new isolation level provides the following benefits: • • • • Increased data availability for read-only applications. reducing the need to perform multiple I/O operations to bring data in and out of memory from disk. with the intention of providing more precise and flexible control to enable tighter security of the data. databases. At the same time. This is where snapshot isolation comes in. caches. SQL Server 2005 provides a new capability for the partitioning of tables across filegroups in a database. The snapshot isolation level allows users to access the last row that was committed. Automatic mandatory conflict detection for write transactions. Users certainly benefit from looking at a transactionally consistent version of the database. and archived to an analysis-oriented database it must be maintained and/or rebuilt periodically. Security SQL Server 2005 makes significant enhancements to the security model of the database platform. by using a transactionally consistent view of the database. and speeds numeric calculations. Table partitioning is designed for very large databases. A considerable investment has been made in a number of features to provide a high level of security for your enterprise data including: • Enforcing policies for SQL Server login passwords in the authentication space. transformed. The end result is a platform that leverages the existing wealth of 32-bit applications while also providing a smooth migration path to 64-bit computing.Table and index partitioning eases the management of large databases by facilitating the management of the database in smaller. more manageable chunks. Simplified migration of applications from Oracle to SQL Server. and sort heaps. The underlying architecture is based on 64-bit extensions to the industry-standard x86 instruction set. which processes more data per clock cycle. Replication Monitor Replication Monitor is a tool that sets a new standard for ease of use in managing complex data replication operations with its intuitive user interface and wealth of data metrics. While the concept of partitioning data across tables. Horizontal partitioning allows for the division of a table into smaller groupings based on a partitioning scheme. allowing today's 32-bit applications to run natively on x64 processors. SQL Server (64-bit) takes advantage of advanced memory addressing capabilities for essential resources such as buffer pools. from hundreds of gigabytes to terabytes and beyond. It can take many hours to build and index the and that might not be what the user really needs. Nonblocking read operations allowed in an OLTP environment. new 64-bit applications are executed in 64-bit mode. Snapshot Isolation Once data is copied. Windows Server™ 2003 x64 provides high performance for both 32-bit and 64-bit applications on the same system. however. the version of the data that they are viewing is no longer current. Support for 64-Bit System Itanium2 and x64 Optimized for the Intel Itanium processor. 63 . Greater processing capacity without the penalties of I/O latency opens the door to new levels of application scalability. allows greater access to memory. and servers is not new to the world of databases.

server policy can be defined to reject unencrypted communications. These steps help to protect the confidentiality. As a result of these design efforts. • Allowing for the separation of owners and schemas in the security management space. Native Encryption SQL Server 2005 supports encryption capabilities within the database itself. To centralize security assurance. SQL and Trustworthy Computing The Trustworthy Computing initiative outlines a framework that defines the steps necessary to support secure computing as well as measures that help you deploy and maintain a secure environment. Administrators can specify Microsoft Windows-style policies on standard logins so that a consistent policy is applied across all accounts in the domain.• Providing for more granularity in terms of specifying permissions at various scopes in the authorization space. SQL Server 2005 includes many new server security features. • Secure by default. By default. making management of permissions easier as well as ensuring that the principle of least privileges is upheld. 64 . fully integrated with a key management infrastructure. Upon installation. Authentication SQL Server 2005 clustering supports Kerberos authentication against a SQL Server 2005 virtual server. This feature also acts as an excellent mechanism for granular permission management. SQL Server deployment tools provide the information necessary to understand the decisions you need to make during deployment. SQL Server 2005 chooses the right set of configuration values for all setup options. Tools are also available to help you assess and manage security risks across organizations. it will be in a secure state by default. ensuring that when a new system is installed. client/server communications are encrypted. Microsoft has created content to help organizations deploy SQL Server using the proper security credentials and to fully understand the steps and permissions required. Authorization A new security model in SQL Server 2005 allows administrators to manage permissions at a granular level and at a designated scope. Microsoft and the SQL Server team have taken the following steps: • Secure by design. to maintenance. and availability of data and systems at every phase of the software life cycle—from design. to delivery. SQL Server 2005 allows you to specify a context under which statements in a module execute. • Secure in deployment. the updates install automatically. To uphold the four tenets of the Trustworthy Computing initiative. For each potential security threat. integrity. The SQL Server development team conducted multiple security audits and spent more than two months studying SQL Server components and the interaction between them. the team did a threat analysis to evaluate the issue and completed additional design and testing work to neutralize potential security issues. Security updates are easy to find and install—and if you choose the option.

two new types of database objects—aggregates and user-defined types—are available.NET Framework support to tight integration with Visual Studio®. Additionally. Microsoft Visual Basic . functions. robust database applications at a lower cost. namespaces.NET.NET Framework integration With the release of Microsoft SQL Server 2005. Using common language runtime (CLR) integration. and Microsoft Visual C#® . CLR hosting will provide developers with increased flexibility through the use of user-defined types and functions.NET Framework language of your choice. From . arrays. additionally. these features provide developers with the ability to more easily create secure. Microsoft Visual Basic® .NET. and classes. Many tasks that were awkward or difficult to perform in Transact-SQL can be better accomplished by using managed code. developers can choose from a variety of familiar languages to develop database applications. including Transact-SQL.NET Framework provides thousands of classes and methods that have extensive built-in capabilities that you can easily use on the server-side. You can now better use the knowledge and skills that you have already acquired to write in-process code. SQL Server 2005 enables you to extend the database server to more easily perform appropriate computation and operations on the back end. and triggers in the . Native XML capabilities will also allow developers to build new classes of connected applications across any platform or device. Enhancements for developer productivity include: • • • • • • Expanded language support Improved development tools Extensibility Improved data access XML and Web services Application Framework Expanded Language Support Because the common language runtime (CLR) is hosted in the database engine. SQL Server 2005 enables developers to leverage existing skills across a variety of development languages while providing an end-to-end development environment for the database.NET Framework class library and modern programming languages to implement functionality within the server. The CLR will also provide opportunities to use third-party code for rapid database application development. 65 . database programmers can now take full advantage of the Microsoft .NET and the C# programming language both offer object-oriented constructs. structured exception handling.Developer Productivity SQL Server 2005 includes many new technologies that bring significant increases in developer productivity. the . CLR/. you can code your stored procedures. In addition. In short.

• Enhanced safety and security: Managed code runs in a CLR environment. Visual Basic . math functions.NET and C# offer object-oriented capabilities such as encapsulation. You can use the same tools for developing and debugging database objects and scripts that you use to write middle-tier or client-tier . offering constructs and capabilities that were previously not available to SQL developers. access to system resources. with the functionality that is available in the . regular expressions. date operations. By using languages such as Visual Basic .This integration between SQL Server and the CLR provides several major benefits: • Enhanced programming model: Programming languages that are compatible with the . trigger. Before managed code is executed. Managed code is more efficient than Transact-SQL at processing numbers and managing complicated execution logic.NET Framework components and services. inheritance.NET Framework class library. the code is checked to ensure that memory is not read that has not been written to. that allows you to better find and relate different pieces of code in a large database implementation. You can easily organize related code into classes and namespaces. For example. Also. advanced encryption algorithms. image processing. and so on. Everything from improved string-handling functions. hosted by the database engine. • Common development environment: Database development is integrated into the Microsoft Visual Studio 2005 development environment. you can achieve significant performance increases in some scenarios. and polymorphism. you can capitalize on CLR integration to write code that has more complex logic and is more suited for computation tasks. This allows . file access. which means that you can more easily organize and maintain your code investments when you are working with large amounts of code. One of the major benefits of managed code is type safety. and provides extensive support for string handling. or user-defined function. the CLR performs several checks through a process known as verification to ensure that the code is safe to run. and XML data manipulation is easily accessible from managed stored procedures. 66 . • Performance and scalability: Because managed code compiles to native code prior to execution. you have full access to thousands of pre-built classes and routines that you can access easily from any stored procedure. and aggregates. functions.NET and C#. In addition. triggers.NET Framework are in many respects richer than Transact-SQL. The ability to logically and physically organize code into assemblies and namespaces is a huge benefit. • User-defined types and aggregates: Two new database objects that expand the storage and querying capabilities of SQL Server are enabled by hosting the CLR.NET Framework database objects to be safer and more secure than the extended stored procedures available in earlier versions of SQL Server.

Transact-SQL enhancements Transact-SQL has long been the basis for all programmability of SQL Server. Business Intelligence Development Studio The Business Intelligence Development Studio is a common development environment for building BI solutions based on Visual Studio including a database engine. setting their properties. developed. 67 . Improved Development Tools Developers will be able to use one development tool for Transact-SQL. The continuous effort that is being put into enhancing Transact-SQL shows a firm belief in its significant role in SQL Server. and XML for Analysis (XML/A). Multidimensional Expressions (MDX). Transact-SQL enhancements in SQL Server 2005 increase your expressive powers in query writing. and connecting tasks with precedence constraints. and reporting services. Use the Business Intelligence Development Studio graphical user interface to design SQL Server Integration Services (SSIS) packages for data management applications. allowing you to improve the performance of your code and extend your error management capabilities. SSIS packages are designed. Integration with the Visual Studio development environment will provide more efficient development and debugging of line-of-business and business intelligence (BI) applications. analysis services. Figure 3 shows the interface in Visual Studio for the Business Intelligence Development Studio. and debugged in the Business Intelligence Development Studio by dragging tasks from the toolbox. These enhancements include error handling. new recursive query capabilities. SQL Server 2005 provides many new language capabilities for developing scalable database applications. XML. and support for new SQL Server Database Engine capabilities.

The combination allows you to seamlessly debug both CLR and Transact-SQL code using the same Visual Studio debugging interface and it allows you to debug from CLR to Transact-SQL and back again. user-defined types. They can deploy these new database objects directly from Visual Studio without having to switch tools. Cross-Tier and Cross-Language Debugging SQL Server 2005 and Visual Studio 2005 together provide even deeper integration in the area of application debugging. Developers now have the ability to create CLR stored procedures. and user-defined aggregates directly from within the Visual Studio development environment. You can also add your CLR database objects to the same source control system that you use for all you Visual Studio projects. thus providing an even greater level of integration and security to your development processes. such as native XML directly. regardless of the location of the code. 68 .Figure 3: Business Intelligence Development Studio interface in Visual Studio Visual Studio Integration SQL Server 2005 and Visual Studio 2005 together provide deeper levels of integration between the database and the application development environment than ever before. functions. whether it is on the developer machine or stored in the SQL Server database. Visual Studio 2005 supports all of the new SQL Server data types.

This includes performing statistical calculations. SMO is the primary tool for developing database management applications using . the underlying data that is stored by the type. Example scenarios for such types include custom date/time data types in various calendars. stddev. nvarchar. Where possible. for example. They are a way to extend the scalar type system of the database. Everyone that needs to access the data has to use the user defined type programmatic interface. If you can leverage existing functionality in the . Write the aggregate using a CLR stored procedure. The scalar type system includes the columnar types that ship with SQL Server (types like int.NET Framework managed code. It is a simple to use but rich object model that is based on . Use user-defined types if you need to define your own scalar type. SMO incorporates similar objects as SQL-DMO for ease of use. etc. Use a server-side cursor.). uniqueidentifier. With user-defined types. You can still use SQL Server 2005 with SQL-DMO. SMO is used by every dialog box in SQL Server Management Studio. such as avg.NET Framework. With user-defined types.NET Framework (such as the internationalization or calendar functionality). you can define your own type that can be used for column definitions. Create a user-defined type if your type really is an atomic value that is appropriate to be modeled as a column. There are a number of scenarios where you may need to perform aggregations over data. and encapsulate. but SQL-DMO will not be updated to manage features that are specific to SQL Server 2005. If the desired aggregation function is not directly supported as a built-in aggregate function. or hide. The new SMO object model and the Microsoft Windows Management Instrumentation (WMI) APIs replace SQL-DMO. 69 . and currency data types. that is another really good reason to consider implementing your type as a user-defined type. SQL Management Objects(SMO) SQL Management Objects (SMO) is the management object model for SQL Server 2005. and every administrative action that you can perform in SQL Server Management Studio you can also accomplish by using SMO. there are three ways to perform a custom aggregation in SQL Server 2005: • • • Write the aggregation as a user-defined aggregate. SMO represents significant design and architectural improvements for the SQL Server management object model. you can create a single object that exposes all the behaviors that are available on the type. etc.Extensibility User-Defined Types and Aggregates User-defined types in SQL Server 2005 are not an object relational extensibility mechanism.

to allow the execution of SQL statements and invocation of functions and procedures. Applications using AMO can either connect and work directly with objects on an Analysis Services instance. For each statement that is executed as part of the request. Commands that are sent to the server through any of the client APIs such as ADO. making SQL Server an HTTP listener. You accomplish this by using a dependency object that detects when the underlying data is changed. ADO.Analysis Management Objects Analysis Management Objects (AMO) allows client applications to access the range of administrative commands and capabilities available to Analysis Services using an object library that can provide object-level validation capabilities. Notifications are delivered through a SQL Service Broker queue that applications can poll. Query results are returned in XML format and can take advantage of the Web services infrastructure of Visual Studio. In SQL Server 2005 you can use HTTP to access SQL Server directly.NET 2. AMO also “wraps” ASSL commands and elements. Microsoft ActiveX® Data Objects (ADO).NET.NET. ADO.NET There is much that's new in the next version of ADO. You can use this support to send a command to SQL Server and to request that a notification be generated if executing the same command again produces different results from those obtained initially. or SOAP may include a tag that requires a notification. without using a middle-tier listener such as Microsoft Internet Information Services (IIS). Query notification SQL Server 2005 introduces notification support for SQL Server queries. This provides a new type of data access capability for applications that are centralized around Web services. Query notifications are useful for enabling the caching of results in applications such as database-driven Web sites. the server creates a notification subscription that fires once for each statement that is included in the request. Improved Data Access and Web Services In SQL Server 2005. From new support for query change notifications. you can develop XML Web services in the database tier. Open Database Connectivity (ODBC).NET evolves dataset access and manipulation to achieve greater scalability and flexibility. Figure 4 shows the query notification process. 70 . OLE DB. and use activation services or blocking statements that return whenever the notifications are available. to Multiple Active Result Sets (MARS).0/ADOMD. or create such objects without an existing connection and persist the metadata for later deployment. instead of having to manually generate DDL scripts for Analysis Services commands and the often-lengthy contents of the Analysis Services Scripting Language (ASSL) ObjectDefinition element. SQL Server exposes a Web service interface.

in particular to have more than one default result set open per connection. XML. as well. the work can be shifted over to the backup server automatically. For default result sets. manage. Support for existing and emerging open standards such as Hypertext Transfer Protocol (HTTP). XQuery. XML Support Advancements such as native XML data type and XQuery help organizations to seamlessly connect internal and external systems.NET 2. If a SQL Server instance fails. and XML Schema definition language (XSD) will also facilitate communication across extended enterprise systems.Figure 4: Query notification MARS MARS provides the ability to have more than one pending request per connection. Default result sets are forward-only read-only result sets. and analyze data in the format that best suits their needs. Simple Object Access Protocol (SOAP). SqlClient in ADO. Hot spare scenarios require that existing client connections must "know" to fail over (establish a connection with the new server instance). The application can use a simple row-at-a-time programming model without compromising performance. Client connections that produce an error on the next attempted access and must be manually "failed over" by client programming are suboptimal. SQL Server 2005 will support both relational and XML data natively. 71 . so enterprises can store. Transparent failover for data mirroring SQL Server 2005 supports a "hot spare" capability through database mirroring. The multiple active result sets feature removes the current restriction in which an open default result set blocks the driver from sending requests to the server until the entire result set is consumed. the client drivers transparently retrieve the data in large chunks (Tabular Data Stream buffer sized chunks) so that application requests are satisfied without a roundtrip to the server (as in the case of server cursors). This requires an instance to witness the failover known as (not surprisingly) the witness instance.0 supports client failover without special programming of the application program.

SQL Server 2005 allows you to query portions of an XML document. inserts. validate that the document conforms to an XML schema. and even modify the contents of the XML document in place. the World Wide Web Consortium (W3C) oversees the development of XQuery. As with many of the XML standards. or even retrieve contiguous bytes from it. making SQL Server an HTTP listener.0 as a subset. SQL Server 2005 also provides several DDL statements for managing schemas on the server. and support for better iteration. and updates. For example. SQL Server 2005 ships with deep XQuery capabilities that allow for XML object manipulation in the data tier. It supports a statically typed subset of the XQuery 1.0.0 Working Draft of November 15. as well as optimizations for storage and query processing. such as typing. 72 . you can insert or select an entire document. if you have experience using XPath 1. With XQuery you can run queries against variables and columns of the XML data type using the latter's associated methods. A collection of XML schemas can be associated with a column of type XML. This provides validation for constraints. It also integrates traditional. built-in data type such as char or varchar does not suffice to make full and effective use of the power and the numerous advantages of XML. or XQuery. 2003. Web Services Support In SQL Server 2005. It also contains XPath 2. sorting of results. XQL. XQuery evolved from a query language called Quilt. By providing the XML data type. however. relational data with data in unstructured or semistructured XML documents in ways that are not possible with SQL Server 2000. In SQL Server 2005. SQL Server exposes a Web service interface to allow the execution of SQL statements and invocation of functions and procedures. is an intelligent and robust language that is optimized for querying all types of XML data. and typing of values inside stored XML data. and SQL.XML Data Type XML can model complex data. you can capitalize on your skills and do not have to learn an entirely new query language. XML data is stored as binary large objects (BLOBs) in an internal representation that allows efficient reparsing and some compression. which was itself based on a variety of other query languages such as the XML Path Language (XPath) version 1. it is not limited to the scalar types that are supported by SQL Server. if XML is stored as a string. As such.0. a string-based. There are. but you cannot query into the contents of the document itself. special functions. This provides a new type of data access capability for applications that are centralized around Web services. and construction. you can develop XML Web services in the database tier. you can use HTTP to access SQL Server directly without using a middle-tier listener such as Microsoft Internet Information Services (IIS). In SQL Server 2005. significant enhancements that go beyond XPath 1. XQuery The XML Query Language. Therefore. Query results are returned in XML format and can take advantage of the Web services infrastructure of Visual Studio.0.

Analysis Services clients can be configured to have a zero footprint. and SQL Server Express. SQL Server Mobile. Service Broker Over the last 10 years. Waiting for each of these processes to happen in order doesn't scale well. shipping. Notification Services. the proliferation of e-commerce applications has created the need for increased workflow management across database applications. standards-based protocol for communicating with the Analysis Services server. this order needs to commit transactions into the inventory. Many users will continue to use the ADOMD. Figure 5: Service Broker architecture 73 . Figure 5 outlines the Service Broker architecture.NET. and credit card systems. When an online customer places an order for a book.XML for Analysis Services (XML/A) XML for Analysis Services (XML/A) is the native. A light-footprint Win32 layer is available for backward compatibility with tools that work with Analysis Services 2000 on OLE DB for OLAP. SQL Server 2005 provides a new scalable architecture for building asynchronous message routing. Service Broker is a distributed application framework that provides reliable asynchronous messaging at the database to database level. and also needs to send an order confirmation using another Web application. Application Framework SQL Server 2005 introduces a new SQL Server application framework including: Service Broker. and ADOMD. ADOMD. and each server is automatically a Web service. New kinds of applications are enabled and easy to develop—applications that integrate analytics with operations in real time.NET object model to build custom applications on Analysis Services. With XML/A as the native protocol.

Messages are sent to a queue in the same database as the sender. You can use SQL Server Management Studio to run queries that target a SQL Server Mobile Edition database on the device or on the desktop. It also allows binding to data objects that are on devices. or it can be generated and sent on a predetermined schedule that the user specifies. The user's subscription specifies when the notification should be generated and sent. updateable cursor. • • You can now code against SQL Server Integration Services (SSIS) objects to exchange data. Notifications are personalized. The new SqlCeResult set is derived from the SQLResult set that is in SQL Server 2005. Because these devices often accompany the user. or to another instance of SQL Server either on the same server or on a remote server.The Service Broker technology allows internal or external processes to send and receive streams of reliable. timely messages that can be sent to a wide variety of devices. or e-mail account." A notification can be generated and sent to the user as soon as a triggering event occurs. asynchronous messages by using extensions to normal Transact-SQL data manipulation language. Notifications can be sent to a wide variety of devices. notifications are ideal for sending high-priority information. Notifications reflect the preferences of the subscriber." or "notify me when the strategy document my team is writing is updated. and you can have two separate applications access the same database on the device at the same time.00. There are a number of new key features in SQL Server Mobile Edition that relate to developers: • You can create a SQL Server Mobile Edition database on the desktop or on the device. to another database in the same instance of SQL Server. • You can code an application to synchronize data while leaving the main application open. For example. Microsoft Windows Messenger. personal digital assistant (PDA). a notification can be sent to a user's mobile phone. 74 . The subscriber enters a subscription to express an interest in information. For example. directly from SQL Server Management Studio. which is now SQL Server Mobile Edition version 3. This allows SQL Server Mobile Edition to have a true scrollable.0. SQL Server Mobile Edition SQL Server 2000 shipped with SQL Server 2000 Windows CE Edition. "notify me when the stock price of Adventure Works reaches $70. You can also take advantage of new SQL Server Mobile Edition features that include an XML showplan rendered in a GUI format just like native SQL Server and the ability to use query hints to override the query optimizer in SQL Server Mobile Edition. Notification Services Microsoft SQL Server Notification Services is a platform for developing and deploying applications that generate and send notifications to users. regardless of whether the database resides on the mobile device or on the desktop. you can control the optimization plan on a device. You can also manipulate the schema of the SQL Server Mobile Edition database directly from Management Studio. For the first time.

and query local databases. and robust database. all inside the Visual Studio 2005 environment.• You can get notifications that you can code into status bars that will give the status of a synchronization. will have a small download size. SQL Server 2000. Both local and remote connections are possible using XM. SQL Server Express More than ever developers are leveraging relational databases to provide a rich end-user experience. Microsoft Visual Studio 2005 and SQL Server Express reduce this complexity by providing a simple but powerful development environment for building data-driven applications. such as the instance. etc. Object Explorer will enumerate and display the common objects used. Too often database systems are overly complex for building simple applications. to notify users that a device had not stopped responding. tables. Microsoft SQL Server Express helps developers build robust and reliable applications by providing a free. XM allows easy database management and query analysis capabilities. Developers can design schemas. and will be freely redistributable. Protecting and managing information inside these applications is critical. there was no way to know how far synchronization status was. stored process. easy to use. XM supports connections to SQL Server Express and other SQL Server 2005 editions. add data. 75 . If developers need more advanced database features. A simplified connection dialog box guides the user through the selection of the instance and the authentication methods to be used. in a hierarchical manner and will help the user visualize access to the database. then SQL Server Express can be seamlessly upgraded to more sophisticated versions of SQL Server. Previously. • You can maintain the small size of the database through a much more aggressive page reclamation policy.. and MSDE 2000. Figure 6 shows the Query Editor interface in SQL Server Express Manager Figure 6: The Query Editor in SQL Server Express Manager (XM) A new GUI tool called SQL Server Express Manager (XM) is freely available as a separate Web download. • You can share parameterized query code with SQL Server syntax.

Many of these common database operations are available as task wizards that guide the user through the process. employees will be able to quickly and easily harness data to make better decisions faster. and highlights new functionality that makes it easier than ever to build and manage complex BI systems. 76 . Some of the database management options to be exposed include creating and modifying databases. XM will provide a New/Edit Database document for creating new databases and editing existing databases.All database management functionalities are available by invoking the right-click context menu from Object Explorer. source control. and reporting capabilities of SQL Server 2005 enable companies to extend the value of their existing applications. and script and code development are available for all components of the BI platform. From the CEO to the information worker. The comprehensive integration. For instance. and users. regardless of the underlying platform. Debugging. logins. the Business Intelligence Development Studio delivers a rich. tools. Built on Visual Studio 2005. The Query Editor will have rich features such as keyword color-coding and a results pane that returns results in a data grid. Many database users prefer to manage their servers using Transact-SQL. timely information in the hands of employees across your organization. integrated. if any. The following provides an introduction to the tools that you will use to build an analytical application. The Query Editor in XM will allow users to develop and execute Transact-SQL statements and scripts. analysis. while many others are available as tabbed window documents. and rich analytics. tables. Business Intelligence SQL Server 2005 will further Microsoft’s leadership in the are of business intelligence (BI) through innovations in scalability. professional development platform for BI system developers. The SQL Server 2005 business intelligence toolset delivers end-to-end BI application integration: • Design: Business Intelligence Development Studio is the first integrated development environment designed for the business intelligence developer. development tools. The error messages. Business intelligence features include enhancements in the following areas: • • • • • End-to-end integrated business intelligence platform Integration Services Analysis Services Reporting Services Integration with the Microsoft Office System End-to-End Integrated Business Intelligence Platform SQL Server 2005 is a complete business intelligence platform that provides the features. SQL Server 2005 enables scalable business intelligence by putting critical. and functionality to build both classic and innovative kinds of analytical applications. will also be shown in the results pane. since this approach offers finergrained control than using the graphical user interface. data integration.

and Naïve Bayes. and Reporting Services work together to present a seamless view of data from heterogeneous sources. By analyzing data across a wide array of operational systems.• Integrate: SQL Server Integration Services (SSIS) has been rewritten to perform complex data integration. transformation. Time Series. New with SQL Server 2005 is the reporting tool. in the multidimensional database. with a range of interactivity and printing options. embeddable. reliability. Analysis Services. Enterprise ETL Platform This new platform is the successor to the popular feature in SQL Server 2000. availability. SQL Server 2005 blurs the lines between relational and multidimensional databases. Report Builder. and extensible—characteristics that make it an ideal ETL platform. The Business Intelligence Development Studio makes building and debugging packages positively fun. programmability. Business intelligence practitioners will benefit from Microsoft's extension of the server abilities you expect from the relational engine—scalability. Important new analytical capabilities have been added to Analysis Services cubes as well: these include Key Performance Indicator (KPI) framework. SSIS is fully programmable. and synthesis at high speed for very large data volumes. called SQL Server Integration Services (SSIS). • Report: Reporting Services extends the Microsoft business intelligence platform to reach the business user who needs to consume the analysis. SSIS provides the breadth of features. SSIS is completely new for SQL Server 2005. Reporting Services is an enterprise managed reporting environment. Reports can be personalized and delivered in a variety of formats. Data Mining and text mining in the data flow. XML) out-of-the box through: • • SSIS brings analytics to the data without persisting the data. SQL Server Integration Services enables organizations to more easily integrate and analyze data from multiple heterogeneous information sources. 77 . • Manage: SQL Server Management Studio integrates the management of all SQL Server 2005 components. You can store data in the relational database. called Data Transformation Services (DTS). Neural Network. Beyond Traditional ETL SQL Server 2005 supports nontraditional data (Web Services. including Association Rules. Integration Services. • Analyze: Microsoft Data Mining has always been easy to use. Now it's even better with the addition of important new algorithms. and very high scale performance that is necessary to build enterprise-class ETL applications. and other built-in advanced business analytics. Complex analyses can reach a broad audience through the distribution of reports as a data source for downstream business intelligence. organizations may gain a competitive edge through a holistic understanding of their business. and so on—to the full set of BI platform components. Integration Services SQL Server 2005 includes a redesigned enterprise ETL platform. embedded and managed via Web services. MDX scripts. or use the new Proactive Cache feature to get the best of both worlds. Sequence Clustering. Regression Trees. The Reporting Services report delivery and management framework enables easy distribution of complex analytics to the widest possible audience.

OLAP browsers. Reporting Services Reporting Services extends the Microsoft BI platform to reach the information worker who needs access to business data. multiple perspectives. By creating an easy to use. Complex analyses can reach a broad audience through the distribution of reports as a data source for downstream business intelligence. The UDM is a central metadata repository defining business entities. Microsoft SQL Server 2005 Analysis Services establishes new ground for data mining. users will find it easy to explore the corporate business data. increase profits and reduce costs by providing customized data-driven solutions to a broad range of business problems. Reporting Services provides: • • • A high performance engine for processing and formatting reports. business logic. a unified and integrated view of all your business data as the foundation for all of your traditional reporting. OLAP analysis. a deep integration with the SQL Server family of business intelligence tools. and a rich set of tools. An extensible architecture and open interfaces for embedding reports or integrating reporting solutions in diverse Information Technology environments. and viewing reports. Unified Dimensional Model By combining the best aspects of traditional OLAP analysis and relational reporting. accessible. 78 . and even automatic translations to native languages. extensible. An integrated component of SQL Server 2005.• Data Mining and analytics are brought to the data flow for data quality and data cleansing. for the first time. with a range of interactivity and printing options. Reporting Services is a server-based enterprise reporting environment. managed via Web services. calculations. and metrics that serves as the source for all reports. and analytical applications. managing. navigation hierarchies. and flexible platform. APIs and algorithms. Reports can be delivered in a variety of formats. With the UDM’s friendly descriptions of the business entities. A set of cubes and dimensions defined in Analysis Services 2005 is referred to as a Unified Dimensional Model (UDM). Analysis Services 2005 provides a metadata model that covers both sets of needs. Using the powerful new Data Source View feature. Analysis Services provides. A complete set of tools for creating. Through an enterprise class architecture. and data mining. and integrate those models with your business operations. the UDM is mapped to a host of heterogeneous back-end data sources allowing a complete and integrated picture of the business regardless of the location of the data. KPIs. Data Mining Microsoft SQL Server 2005 Data Mining is the business intelligence technology that helps you build complex analytical models. SQL Server 2005 Analysis Services data mining capabilities introduces data mining to organizations that previously would never have considered a data mining solution. spreadsheets. Analysis Services With SQL Server 2005. SQL Server enables the creation of a new breed of intelligent applications that enhance productivity.

Reporting Services allows you to easily build reports together or separately. Figure 7 shows a sample Report Builder report. a new component of SQL Server 2005 Reporting Services.Relational and OLAP Reports Reports built on relational data are useful but the ability to add additional analytic capabilities makes reporting powerful. allows business users to create their own reports using a user-friendly model of their data. The Report Builder user interface is built on top of familiar Microsoft Office paradigms such as Excel and PowerPoint. SQL Server 2005 supports both relational and OLAP data and provides a query editor for both including SQL Query Editor and MDX Query Editor. Report Builder leverages the Reporting Services platform to bring ad hoc reporting to all end users. Figure 7: Design reports with Report Builder 79 . Report Builder Report Builder. Users create and edit reports with the Report Builder client application.

Report Builder is a ClickOnce application deployed via the browser. create new versions of reports. • SQL Server 2005 Notification Services is installed side-by-side with Notification Services 2. and features. Microsoft SQL Server Pricing and Licensing The family of SQL Server editions includes everything you need in one product for a comprehensive. Pricing & licensing 80 . print. Export report data to formats such as Microsoft Excel. and business value to all customers. and distribute reports. Upgrading to SQL Server 2005 Following are some tips for upgrading to SQL Server 2005. You can run DTS packages using the DTS runtime components. You can also open reports in Word or Excel to view HTML versions of the reports. the replacement for DTS. They drag and drop report items from the model to the design surface and set constraints to filter the report data. • Use the Surface Area Configuration tool after upgrading to enable or disable SQL Server 2005 services. SQL Sever provides the same performance. Users start by selecting report layout templates containing predefined data sections such as tables.0. and publish reports. SQL Server Integration Services. You must migrate instances of Notification Services to SQL Server 2005 when you upgrade the Database Engine. Preview. Integration with the Microsoft Office System Reports that are served up by the Report Server in Reporting Services can run in the context of Microsoft SharePoint® Portal Server and Microsoft Office System applications such as Microsoft Word and Microsoft Excel. Run Upgrade Advisor before upgrading to determine if any product changes are expected to break existing applications.0 or SQL Server 2000. matrices and charts. analysis and reporting platform with flexible licensing that allows you to choose the solution that best fits your unique needs. Create new fields and calculations defined using the model. SQL Server supports implementations ranging from multi-terabyte data warehouses to Pocket PC devices running SQL Server Windows CE Edition. management. reliability. is installed side-by-side with DTS. • • Upgrade to SQL Server 2005 from SQL Server 7. and Reporting Services can be upgraded by Setup. The Report Builder also allows users to: • • • • Add text and formatting to reports. You can use SharePoint features to subscribe to reports. network protocols. • • The Database Engine. The model contains all of the necessary information for the Report Builder to automatically generate the source query and retrieve the requested data. out-ofthe-box data storage. security. Designed to scale from the largest enterprise down to the smallest business. Analysis Services.

500 per Fully data and integrated Unlimited Scale Advanced management & Partitioning analysis mirroring. & database Complete parallel for (server + 25 platform business-critical users) enterprise applications.and 64-bit editions Supports Itanium2 and x64 Enterprise $25. Advanced ETL with complex data routing and transformation capabilities. Workgroup $3. way build Size to 1 CPU Key Features Simple Management Tool Simple Reporting Replication & SSB Client Management Studio Import/Export Limited Publishing Clustering Back-up Log Shipping Replication and 1-GB RAM deploy simple data4-GB DB size driven applications.000 processor $13. and database analysis tools including full OLAP & Data Advanced reporting with customized.000 processor $2.900 processor per Most affordable and 1-2 CPUs easiest to use 3-GB RAM solution smaller and $739 (server database for + 5 users) growing businesses. high scale. online snapshot. 81 .Edition Express Pricing Free Benefit Fastest learn. Advanced Mining. with Analysis Services Standard Reporting with Reporting Services Data Mining Full Replication & SSB Publishing Available in native 32. Standard $6.799 per Complete departments data 1-4 CPUs Database Mirroring Basic ETL Standard OLAP Server management and Unlimited RAM analysis platform for (server + 10 medium businesses and larger users) departments. operations. and ad hoc reporting.

purchases within the United States. 82 . reliability.asp http://www. and operation of flexible business solutions. Supports Itanium2 and x64 This table outlines the pricing and benefits for each edition of the Microsoft SQL Server 2005 product line.microsoft. deployment.asp All prices are in US dollars and reflect pricing for Windows Server System Common Engineering Roadmap SQL Server is part of the Windows Server System—a comprehensive and integrated server infrastructure that simplifies the development.Edition Pricing Benefit Size Key Features Available in native 32 and 64 bit editions. and tools such as the Microsoft Baseline Security Analyzer to deliver a consistent and predictable experience to Windows Server System customers. As a key part of the Windows Server System family.com/sql/howtobuy/default. Watson support. The goal of the Windows Server System Common Engineering Roadmap is to create a set of common services that will be implemented across all Windows Server System server products. manageability. Note Bold indicates a feature that is new for Microsoft SQL Server 2005. The Windows Server System Common Engineering Roadmap builds on the following initiatives to enable customers to meet today’s business challenges and the challenges of tomorrow. SQL Server 2005 includes a standard set of capabilities such as common patch management. This set of common services raises the bar for server infrastructure and helps ensure that products throughout Windows Server System are engineered for greater security. For more information on pricing and licensing and the SQL Server 2005 product line please visit the following: http://www.microsoft. and flexibility.com/sql/howtobuy/understdbpricing. Each higher edition includes the same functionality as the edition below it.

software. Microsoft’s Web services strategy.com/windowsserversystem. and collaborative effort to create and deliver more secure. private. In the Common Engineering Criteria for 2005. people. http://www. while reducing the demands on users and Information Technology administrators. These specifications and their implementation details. including any exception information. Beginning with 2005 versions. company-wide.NET. security-enhanced systems based on Web services. and service vendors around a model-based management that enables customers to harness the power of industry-standard hardware and brings simplicity. 16 different specifications have been defined and applied throughout the Windows Server System. and devices through software. These systems enable faster. This initiative unifies hardware. Adopting services-oriented architecture throughout the Microsoft platform provides businesses with the ability to quickly build. The goal of Trustworthy Computing is to deliver the security. or have specific reasons for any exemptions. • Trustworthy Computing is a long-term. reliability. automation. and business integrity that people expect from the computing industry. The goal is to reduce management and operations costs. deploy. all Windows Server System products will either comply with these criteria. anywhere. and increase responsiveness throughout the entire Information Technology life cycle. will be published regularly on the Windows Server System Web site. connects information. 83 . systems. on any device. with implementation plans for future releases. and use connected. Microsoft is currently focusing on three key initiatives: • .microsoft.To deliver on this vision of flexible Information Technology. and reliable computing experiences for users. Microsoft will add specifications at regular intervals to continue to address customer requirements and deliver on the vision for Windows Server System. improve reliability. and flexibility to Information Technology operations. more agile business integration and deliver on the promise of information anytime. • Dynamic Systems Initiative (DSI) is focused on delivering systems that are designed with operations in mind and are built to monitor ongoing operations and adjust dynamically based on models that can change with the business. privacy. manage.