Sunteți pe pagina 1din 21

Introduction to Microsoft SQL Server 2008

- Pradeep K Dash

SQL Server 2008


Manage any data, any place, any time. Store data from structured, semistructured, and unstructured documents, such as images and rich media, directly within the database. SQL Server 2008 delivers a rich set of integrated services that enable you to do more with your data such as query, search, synchronize, report, and analyze.

SQL Server 2008 New Features


SQL Server Integration Service: SSIS (SQL Server Integration Services) is a built in application for developing and executing ETL (extraction, transformation, and load) packages. SSIS replaced SQL 2000 DTS. Integration Services includes the necessary wizards, tools, and tasks for creating both simple import export packages, as well very complex data cleansing operations. FILESTREAM Data Type: My favorite new feature is the FILESTREAM data type. It takes binary large objects (BLOBs), such as the varchar (MAX) data type, out of the database files and moves them to standalone files on the Windows file system. This helps cut down on the database size and actually provides great performance (as it turns out, Windows is pretty good at reading and writing files all by itself).

SQL Server 2008 New Features


Policy-Based Management: Makes managing multiple SQL Server instances easier. It allows you to define centralized configuration policies, and SQL Server will enforce and report on those settings throughout the enterprise. Policy-Based Management, which requires no changes to your applications or databases to function, also allows you to run a TSQL query against multiple servers from a centralized management server. This is (sort of) a part of the Policy-Based Management framework. Transparent data encryption: If you deal with sensitive data, transparent data encryption improves SQL Server's encryption capabilities by transparently encrypting the entire database file rather than specific columns. Data auditing: Finally, if you're dealing with compliance and auditing concerns, the new data auditing features help audit events like logons, password changes, data access, data modification, schema modification and more.

SQL Server 2008 New Features


MERGE: SQL 2008 includes the TSQL command MERGE. Using this statement allows a single statement to UPDATE, INSERT, or DELETE a row depending on its condition.
MERGE InventoryMaster AS im USING (SELECT InventoryID, Descr FROM NewInventory) AS src ON im. InventoryID = src. InventoryID WHEN MATCHED THEN UPDATE SET im.Descr = src.Descr WHEN NOT MATCHED THEN INSERT (InventoryID, Descr) VALUES (src. InventoryID, src.Descr);

Declare and Initialize Variables Microsoft SQL Server 2008 enables you to initialize variables inline as part of the variable declaration statement instead of using separate DECLARE and SET statements. This enhancement helps you abbreviate your code. The following code example demonstrates inline initializations using a literal and a function:
DECLARE @i AS INT = 0, @d AS DATETIME = CURRENT_TIMESTAMP; SELECT @i AS [@i], @d AS [@d];

SQL Server 2008 New Features


Compound Assignment Operators Compound assignment operators help abbreviate code that assigns a value to a column or a variable. The new operators are: += (plus equals) -= (minus equals) *= (multiplication equals) /= (division equals) %= (modulo equals) You can use these operators wherever assignment is normally allowedfor example, in the SET clause of an UPDATE statement or in a SET statement that assigns values to variables. The following code example demonstrates the use of the += operator:
DECLARE @price AS MONEY = 10.00; SET @price += 2.00; SELECT @price;

This code sets the variable @price to its current value, 10.00, plus 2.00, resulting in 12.00.

SQL Server 2008 New Features


Table Value Constructor Support through the VALUES Clause SQL Server 2008 introduces support for table value constructors through the VALUES clause. You can now use a single VALUES clause to construct a set of rows. One use of this feature is to insert multiple rows based on values in a single INSERT statement, as follows:
CREATE TABLE dbo.Customers ( custid INT NOT NULL, companyname VARCHAR(25) NOT NULL, phone VARCHAR(20) NOT NULL, address VARCHAR(50) NOT NULL, CONSTRAINT PK_Customers PRIMARY KEY(custid) ); INSERT INTO dbo.Customers(custid, companyname, phone, address) VALUES (1, 'cust 1', '(111) 111-1111', 'address 1'), (2, 'cust 2', '(222) 222-2222', 'address 2'), (3, 'cust 3', '(333) 333-3333', 'address 3');

SQL Server 2008 New Features


To read more about SQL Server 2008 new features like new Date data types, enhanced CONVERT and CAST features etc visit, http://technet.microsoft.com/enus/library/cc721270.aspx

Chapter: II

Database Migration to SQL Server 2008

Using Detach and Attach Features of SQL Server


Detaching a database removes it from the instance of the Microsoft SQL Server Database Engine but leaves intact the database, with its data files and transaction log files. After detaching a SQL Server 2005 database, you can reattach it to the same or another instance of SQL Server 2005. To detach a database In SQL Server Management Studio Object Explorer, connect to the instance of the SQL Server Database Engine and then expand the instance. Expand Databases, and select the name of the user database you want to detach. Detaching a database requires exclusive access to the database. If the database is in use, restrict access to a single user: Right-click the database name and point to Properties. In the Select a page pane, select Options. In the Other options pane, scroll down to the State options. Select the Restrict Access option, and in its drop-down list, select Single. Click OK. A message box appears to inform you that this action will close all connections to the database. To proceed, click OK. Right-click the database name, point to Tasks, and then click Detach. The Detach Database dialog box appears.

10

Using Detach and Attach Features of SQL Server


The Databases to detach grid displays the name of the selected database in the Database Name column. Verify that this is the database you want to detach. By default, the detach operation retains any out-of-date optimization statistics when detaching the database; to update the existing optimization statistics, click the Update Statistics check box. By default, the detach operation keeps any full-text catalogs that are associated with the database. To remove them, clear the Keep Full-Text Catalogs check box. The Status column displays the current database state (either Ready or Not Ready). If the status is Not Ready, the Message column displays hyperlinked information about the database. When a database is involved with replication, the Message column displays Database replicated. When a database has one or more active connections, the Message column displays <number_of_active_connections> Active connections; for example, 1 Active connection(s). Before you can detach the database, you must disconnect any active connections by selecting the Drop Connections check box. To obtain more information about a message, click the hyperlink. When you are ready to detach the database, click OK.

11

Using Detach and Attach Features of SQL Server


Attaching a database places it in exactly the same state that it was in when it was detached. To attach a database
In SQL Server Management Studio Object Explorer, connect to an instance of the Microsoft SQL Server Database Engine, and then expand that instance. Right-click Databases and click Attach. In the Attach Databases dialog box, to specify the database to be attached, click Add; and in the Locate Database Files dialog box, select the disk drive where the database resides and expand the directory tree to find and select the .mdf file of the database; for example: C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\AdventureWorks_Data.mdf Important: Trying to select a database that is already attached generates an error. Optionally, to specify a different name for the database to attach as, enter the name in the Attach as column of the Attach Databases dialog box. Optionally, change the owner of the database by selecting a different entry in the Owner column. When you are ready to attach the database, click OK.
12

Demonstration

Demonstration Session 6

13

Using Copy Database Wizard Feature


The Copy Database Wizard lets you move or copy databases and their objects easily from one server to another, with no server downtime. Using this wizard, you can do the following: Pick a source and destination server. Select databases to move or copy. Specify the file location for the databases. Create logins on the destination server. Copy additional supporting objects, jobs, user-defined stored procedures, and error messages. Schedule when to move or copy the databases. In addition to copying databases, you can copy associated metadata, for example, logins and objects from the master database that are required by a copied database. Also, you can move and copy databases between different instances of SQL Server, and you can upgrade databases from SQL Server 2000 to SQL Server 2005 or later. The destination server must be SQL Server 2005 or later.

14

Demonstration

Demonstration Session 7

15

Back Up and Restore


Back up the database in the old server and restore it in the destination server. Microsoft SQL Server enables you to back up and restore your databases. The SQL Server backup and restore component provides an important safeguard for protecting critical data stored in SQL Server databases. A well-planned backup and restore strategy helps protect databases against data loss caused by a variety of failures. A copy of data that can be used to restore and recover the data is called a backup. Backups let you restore data after a failure. With good backups, you can recover from many failures, such as:
Media failure. User errors, for example, dropping a table by mistake. Hardware failures, for example, a damaged disk drive or permanent loss of a server. Natural disasters.

Additionally, backups of a database are useful for routine administrative purposes, such as copying a database from one server to another, setting up database mirroring, and archiving.

16

Demonstration

Demonstration Session 8

17

Create Script and Run in New Database Server


The last type is to generate the create script using Generate Script Wizard (SSMS) and execute it in the destination server. Select the database in the source server in SSMS Right click ->Tasks->Generate Scripts Wizard to launch the wizard. Select the various scripting options needed and select the objects needed to generate the scripts for them. Make sure script data = true in the scripting option to generate script for data as well (INSERT statements) click next ->next and finish to generate the script (new query window or clip board or file) connect to the destination server and create the new database in it. Click new query window and paste the script generated using GSW above and execute them with the destination database context.

18

Demonstration

Demonstration Session 9

19

20

Thank You!

S-ar putea să vă placă și