SQL Server An Overview



Similar documents
Using SQL Server Management Studio

How To Create A Table In Sql (Ahem)

ODBC Client Driver Help Kepware, Inc.

Setting Up ALERE with Client/Server Data

Creating Database Tables in Microsoft SQL Server

Video Administration Backup and Restore Procedures

Data Tool Platform SQL Development Tools

Using the Query Analyzer

Microsoft SQL Server Connector for Apache Hadoop Version 1.0. User Guide

Sophos Enterprise Console Auditing user guide. Product version: 5.2

Conventional Files versus the Database. Files versus Database. Pros and Cons of Conventional Files. Pros and Cons of Databases. Fields (continued)

SQL Server Integration Services with Oracle Database 10g

Comparison of Open Source RDBMS

Jet Data Manager 2012 User Guide

Table and field properties Tables and fields also have properties that you can set to control their characteristics or behavior.

Exploring Microsoft Office Access Chapter 2: Relational Databases and Multi-Table Queries

MS Access Lab 2. Topic: Tables

Connectivity Pack for Microsoft Guide

2874CD1EssentialSQL.qxd 6/25/01 3:06 PM Page 1 Essential SQL Copyright 2001 SYBEX, Inc., Alameda, CA

Ontrack PowerControls V8.1 for SQL ReadMe

A Tutorial on SQL Server CMPT 354 Fall 2007

Introduction to Microsoft Access 2003

Chapter Replication in SQL Server

SQL Server Administrator Introduction - 3 Days Objectives

Specifications of Paradox for Windows

SQL Server Table Design - Best Practices

PROJECT ON MICROSOFT ACCESS (HOME TAB AND EXTERNAL DATA TAB) SUBMITTED BY: SUBMITTED TO: NAME: ROLL NO: REGN NO: BATCH:

Ontrack PowerControls User Guide Version 8.0

A Basic introduction to Microsoft Access

Notes Transfer instructions INTRODUCTION More information

Toad for Oracle 8.6 SQL Tuning

SQL Server for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach

Developing Web Applications for Microsoft SQL Server Databases - What you need to know

Lesson 07: MS ACCESS - Handout. Introduction to database (30 mins)

ODBC Driver Version 4 Manual

Guide to Upsizing from Access to SQL Server

Preparing to Install SQL Server 2005

Optimizing the Performance of the Oracle BI Applications using Oracle Datawarehousing Features and Oracle DAC

A Brief Introduction to MySQL

Oracle Migration Workbench

Working with SQL Server Integration Services

Field Properties Quick Reference

Information Technology NVEQ Level 2 Class X IT207-NQ2012-Database Development (Basic) Student s Handbook

SQL Server Automated Administration

MS SQL Performance (Tuning) Best Practices:

FileMaker 11. ODBC and JDBC Guide

Legal Information Trademarks Licensing Disclaimer

Administering a Microsoft SQL Server 2000 Database

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.

A Migration Methodology of Transferring Database Structures and Data

ATTACHMENT 6 SQL Server 2012 Programming Standards

Visual Studio.NET Database Projects

Microsoft Access 3: Understanding and Creating Queries

How To Create An Easybelle History Database On A Microsoft Powerbook (Windows)

DataLogger Kepware, Inc.

4 Simple Database Features

WhatsUp Gold v16.3 Installation and Configuration Guide

DiskBoss. File & Disk Manager. Version 2.0. Dec Flexense Ltd. info@flexense.com. File Integrity Monitor

FileMaker 12. ODBC and JDBC Guide

MapInfo SpatialWare Version 4.6 for Microsoft SQL Server

Optimizing Performance. Training Division New Delhi

Tutorial 3. Maintaining and Querying a Database

Microsoft Office 2010

Chapter 4 Accessing Data

Accounts Receivable: Importing Remittance Data

Synthetic Monitoring Scripting Framework. User Guide

Full Text Search. Objectives. Full Text Search

Choosing a Data Model for Your Database

2 SQL in iseries Navigator

QAD Business Intelligence Release Notes

Implementing and Maintaining Microsoft SQL Server 2008 Integration Services

AV-005: Administering and Implementing a Data Warehouse with SQL Server 2014

Administering a Microsoft SQL Server 2000 Database

BID2WIN Workshop. Advanced Report Writing

Module 1: Getting Started with Databases and Transact-SQL in SQL Server 2008

AssetWise Performance Management. APM Remote Upgrade Guide

SAP BusinessObjects Business Intelligence (BI) platform Document Version: 4.1, Support Package Report Conversion Tool Guide

1 Changes in this release

Writing Queries Using Microsoft SQL Server 2008 Transact-SQL

Results CRM 2012 User Manual

DiskPulse DISK CHANGE MONITOR

Deployment Guide. Cartagena as. Cartagena ERP Integration 3.0 for Microsoft Dynamics CRM. Knut Eivind Handeland

Chapter 5. Microsoft Access

Black Hat Briefings USA 2004 Cameron Hotchkies

Abstract. For notes detailing the changes in each release, see the MySQL for Excel Release Notes. For legal information, see the Legal Notices.

MySQL for Beginners Ed 3

SQL Server Database Coding Standards and Guidelines

HansaWorld SQL Training Material

Microsoft. Course 20463C: Implementing a Data Warehouse with Microsoft SQL Server

Microsoft SQL Server 2008 Administrator's Pocket Consultant

Exploring SQL Server Data Tools in Visual Studio 2013

Master Data Services. SQL Server 2012 Books Online

How to Copy A SQL Database SQL Server Express (Making a History Company)

Connecting to Manage Your MS SQL Database

CHAPTER 4: BUSINESS ANALYTICS

Basic SQL Server operations

Microsoft SQL connection to Sysmac NJ Quick Start Guide

MS Access: Advanced Tables and Queries. Lesson Notes Author: Pamela Schmidt

B.1 Database Design and Definition

Siemens Applied Automation Page 1 11/26/03 9:57 PM. Maxum ODBC 3.11

Transcription:

SQL Server An Overview SQL Server Microsoft SQL Server is designed to work effectively in a number of environments: As a two-tier or multi-tier client/server database system As a desktop database system Client/Server Database Systems Client/server systems are constructed so that the database can reside on a central computer, known as a server, and be shared among several users. Users access the server through a client or server application: In a two-tier client/server system, users run an application on their local computer, known as a client, which connects over a network to the server running SQL Server. The client application runs both business logic and the code to display output to the user, and is also known as a thick client This is a typical scenario for an Internet application. For example, a server application can run on a Microsoft Internet Information Services (IIS) and service thousands of thin clients running on the Internet or an intranet. SQL Server can be installed on the same computer as IIS, or it can be installed on a separate server in the network. Features of SQL Server Ease of installation, deployment, and use. SQL Server includes a set of administrative and development tools that improve your ability to install, deploy, manage, and use SQL Server across several sites. Scalability The same database engine can be used across platforms ranging from laptop computers running Microsoft Windows XP to large, multiprocessor servers running Microsoft Windows NT, Enterprise Edition. Data warehousing SQL Server includes tools for extracting and analyzing summary data for online analytical processing (OLAP). SQL Server also includes tools for visually designing databases and analyzing data using English-based questions. System integration with other server software Server integrates with e-mail, the Internet, and Windows.

SQL Serve -an Overview Microsoft Management Console (MMC) is a tool that presents a common interface for managing different server applications in a Microsoft Windows network. SQL Server Enterprise Manager SQL Server Enterprise Manager allows for easy enterprise-wide configuration and management of SQL Server and SQL Server objects. SQL Server Enterprise Manager provides a powerful scheduling engine, administrator alert capability, and a built-in replication management interface. You can also use SQL Server Enterprise Manager to: Manage logins, permissions, and users. Create scripts. Manage backup devices and databases. Back up databases and transaction logs. Manage tables, views, stored procedures, triggers, indexes, rules, defaults, and user-defined data types. Create full-text indexes, database diagrams, and database maintenance plans. Import and export & Transform data. Perform various Web administration tasks. SQL Server Query Analyzer SQL Server Query Analyzer is a graphical query tool that provides a way to analyze the plan of a query, execute multiple queries simultaneously, view data, and recommend indexes. SQL Server Query Analyzer provides the SHOWPLAN option, which is used to report data retrieval methods chosen by the SQL Server query optimizer. SQL Server Query Analyzer offers the following features: Free-form text editor for keying in Transact-SQL statements. Color coding of Transact-SQL syntax to improve the readability of complex statements. Results presented in either a grid or a free-form text window. Graphical diagram of the show plan information showing the logical steps built into the execution plan of a Transact-SQL statement. This allows programmers to determine what specific part of a poorly-performing query is using a lot of resources. They can then explore changing the query in ways that minimize the resource usage while still returning the desired data. SQL Server Service Manager You can do following tasks with SQL Server Service Manager: Open the SQL Server Service Manager dialog box. Select a service. 92

SQL Serve an Overview Start, continue, pause, or stop the selected service. Set options for the selected service. Get information about the SQL Server Service Manager application. Exit the application. Stored Procedure In Transact-SQL programs, two methods are available for storing and executing the programs. You can store the programs locally and create applications that send the commands to SQL Server and process the results, or you can store the programs as stored procedures in SQL Server. The benefits of using stored procedures are: They allow modular programming. You can create the procedure once, store it in the database, and call it any number of times in your program. Stored procedures can be created by a person who specializes in database programming, and they can be modified independently of the program source code. They allow faster execution. If the operation requires a large amount of Transact- SQL code or is performed repetitively, stored procedures can be faster than batches of Transact-SQL code. They are parsed and optimized when they are created, and an in-memory version of the procedure can be used after the procedure is executed the first time.. They can reduce network traffic. An operation requiring hundreds of lines of Transact-SQL code can be performed through a single statement that executes the code in a procedure, rather than by sending hundreds of lines of code over the network. Stored procedures in SQL Server are similar to procedures in other programming languages in that they can: Accept input parameters and return multiple values in the form of output parameters to the calling procedure or batch. Contain programming statements that perform operations in the database, including calling other procedures. Return a status value to a calling procedure or batch to indicate success or failure (and the reason for failure). You can use the Transact-SQL EXECUTE statement to run a stored procedure. Stored procedures are different from functions in that they do not return values in place of their names and they cannot be used directly in an expression. Stored Procedures can be used as a security mechanism. Users can be granted permission to execute a stored procedure even if they do not have permission to execute the procedure s statements directly. 93

SQL Serve -an Overview Database A database in Microsoft SQL Server 2000 consists of a collection of tables that contain data, and other objects, such as views, indexes, stored procedures, and triggers, defined to support activities performed with the data. The data stored in a database is usually related to a particular subject or process, such as inventory information for a manufacturing warehouse. SQL Server can support many databases, and each database can store either interrelated data or data unrelated to that in the other databases. For example, a server can have one database that stores personnel data and another that stores product-related data. You can create databases using Transact-SQL, SQL Server Enterprise Manager, the Create Database Wizard. To create a database using the Create Database Wizard (Enterprise Manager) Expand a server group; then expand the server in which to create a database. On the Tools menu, click Wizards... Expand Database. Double-click Create Database Wizard. Complete the steps in the wizard. Taking a database backup Expand a server group; then expand a server. Expand Databases, right-click the database, point to All Tasks, and then click Database Backup... On the General tab, in Name, enter the set name. Optionally, in Description, enter a description of the backup set. Under, select Database choose complete. Under Destination, click Add... to add an existing or create a new device, or click Remove to remove a device from the list of devices to be used. In the SQL Server dialog box, under Overwrite, select: Append to media to append the to any existing on the device. Overwrite existing media to overwrite any existing on the device. Optionally, select Schedule to schedule the operation for later or periodic execution. Importing and Exporting Data Importing and exporting data is the process of exchanging data between applications by reading and writing data in a common format. For example, DTS can import data from an 94

SQL Serve an Overview ASCII text file or Access database into SQL Server. Alternatively, data can be exported from SQL Server to an OLE DB data destination, such as an Excel spreadsheet. Understanding Data Transformation Services Data Transformation Services (DTS) provides the functionality to import, export, and transform data between Microsoft SQL Server and any OLE DB, ODBC, or text file format. Transferring Database Objects When using heterogeneous data sources, the built-in facilities of DTS only move table definitions and data. To transfer other objects such as indexes, constraints, and views you must use methods such as specifying tasks that execute the SQL statements needed to create these objects on the destination data source. However, if both the source and destination are SQL Server 2000 data sources, you can define a Transfer SQL Server Objects task to transfer indexes, views, logins, stored procedures, triggers, rules, defaults, constraints, and user-defined data types in addition to transferring the data. Data Types In Microsoft SQL Server, each column, local variable, expression, and parameter has a related data type, which is an attribute that specifies the type of data (integer, character, money, and so on) that the object can hold. SQL Server supplies a set of system data types that define all of the types of data that can be used with SQL Server. Assigning a data type to an object defines four attributes of the object: The kind of data contained by the object. For example, character, integer or binary. The length of the stored value, or its size. The length of an image, binary, and varbinary data type is defined in bytes. The length of any of the numeric data types is the number of bytes required to hold the number of digits allowed for that data type. The length of the character string and Unicode data types is defined in characters. The precision of the number (numeric data types only). The precision is the number of digits the number can contain. For example, a smallint object can hold a maximum of 5 digits; it has a precision of 5. The scale of the number (numeric data types only). The scale is the number of digits that can be stored to the right of the decimal point. For example, an int object cannot accept a decimal point and has a scale of 0. A money object can have a maximum of 4 digits to the right of the decimal point and has a scale of 4. If an object is defined as money, it can contain a maximum of 19 digits, 4 of which can be to the right of the decimal. The object uses 8 bytes to store the data. The money data type therefore has a precision of 19, a scale of 4, and a length of 8. 95

SQL Serve -an Overview When two expressions that have different data types, collations, precision, scale, or length are combined by an operator: The data type of the resulting value is determined by applying the rules of data type precedence to the data types of the input expressions. If the result data type is char, varchar, text, nchar, nvarchar, or ntext, the collation of the result value is determined by the rules of collation precedence. The precision, scale, and length of the result depend on the precision, scale, and length of the input expressions. A subset of data types supported by Microsoft SQL Server are described below: int Integer (whole number) data from -2^31 (-2,147,483,648) through 2^31-1 (2,147,483,647). smallint Integer data from 2^15 (-32,768) through 2^15-1 (32,767). bit Integer data with either a 1 or 0 value. decimal Fixed precision and scale numeric data from -10^38 +1 through 10^38 1. numeric Functionally equivalent to decimal. money Monetary data values from -2^63 (-922,337,203,685,477.5808) through 2^63-1 (+922,337,203,685,477.5807), with accuracy to a ten-thousandth of a monetary unit. smallmoney Monetary data values from -214,748.3648 through +214,748.3647, with accuracy to a tenthousandth of a monetary unit. Approximate Numerics float Floating precision number data from -1.79E + 308 through 1.79E + 308. 96

SQL Serve an Overview real Floating precision number data from -3.40E + 38 through 3.40E + 38. datetime and smalldatetime datetime Date and time data from January 1, 1753, through December 31, 9999, with an accuracy of three-hundredths of a second, or 3.33 milliseconds. smalldatetime Date and time data from January 1, 1900, through June 6, 2079, with an accuracy of one minute. Character Strings char Fixed-length non-unicode character data with a maximum length of 8,000 characters. varchar Variable-length non-unicode data with a maximum of 8,000 characters. text Variable-length non-unicode data with a maximum length of 2^31-1 (2,147,483,647) characters. Unicode Character Strings nchar Fixed-length Unicode data with a maximum length of 4,000 characters. nvarchar Variable-length Unicode data with a maximum length of 4,000 characters. sysname is a system-supplied user-defined data type that is functionally equivalent to nvarchar(128) and is used to reference database object names. ntext Variable-length Unicode data with a maximum length of 2^30-1 (1,073,741,823) characters. 97

SQL Serve -an Overview Binary Strings binary Fixed-length binary data with a maximum length of 8,000 bytes. varbinary Variable-length binary data with a maximum length of 8,000 bytes. image Variable-length binary data with a maximum length of 2^31-1 (2,147,483,647) bytes. Tables Tables are database objects that contain all the data in a database. A table definition is a collection of columns. In tables, data is organized in a row-and-column format similar to a spreadsheet. Each row represents a unique record, and each column represents a field within the record. For example, a table containing employee data for a company can contain a row for each employee and columns representing employee details such as employee number, name, address, job title, and home phone number. It is a good idea to outline your plans on paper before creating a table and its objects. Decisions that must be made include: Types of data the table will contain. Columns in the table and the data type (and length, if required) for each column. Which columns accept null values. Whether and where to use constraints or defaults and rules. Types of indexes needed, where required, and which columns are primary keys and which are foreign keys. How to create a table: Expand a server group; then expand a server. Expand Databases; then expand the database in which to create the table. Right-click Tables; then click New Table... In the Choose Name dialog box, enter a name for the table. Fill in the columns as appropriate as in the Creating Tables (Ref. fig. 1) Right-click any row; then click Properties. Click the Tables tab. Fill in desired parameters 98

SQL Serve an Overview Creating Tables (fig. 1) Using Constraints, Defaults, and Null Values PRIMARY KEY constraints A table usually has a column or combination of columns whose values uniquely identify each row in the table. This column (or columns) is called the primary key of the table and enforces the entity integrity of the table.you can create a primary key by defining a PRIMARY KEY constraint when you create or alter a table. A table can have only one PRIMARY KEY constraint, and no column that participates in the PRIMARY KEY constraint can accept null values. Because PRIMARY KEY constraints ensure unique data, they are often defined for identity column. FOREIGN KEY constraints A foreign key (FK) is a column or combination of columns used to establish and enforce a link between the data in two tables. A link is created between two tables by adding the column or columns that hold one table s primary key values to the other table. This column becomes a foreign key in the second table. UNIQUE constraints You can use UNIQUE constraints to ensure that no duplicate values are entered in specific columns that do not participate in a primary key. While both a UNIQUE constraint and a 99

SQL Serve -an Overview primary key enforce uniqueness, use a UNIQUE constraint instead of a PRIMARY KEY constraint when you want to enforce the uniqueness of: A column or combination of columns, that is not the primary key. CHECK constraints CHECK constraints enforce domain integrity by limiting the values that are accepted by a column. You can create a CHECK constraint with any logical (Boolean) expression that returns TRUE or FALSE based on the logical operators. DEFAULT definitions Each column in a record must contain a value, even if that value is NULL. Nullability The nullability of a column determines if the rows in the table can contain a null value for that column. A null value, or NULL, is not the same as zero (0), blank, or a zero-length character string such as ""; NULL means that no entry has been made. Its presence usually implies that the value is either unknown or undefined. Indexes Indexes in databases are similar to indexes in books. In a book, an index allows you to find information quickly without reading the entire book. In a database, an index allows the database program to find data in a table without scanning the entire table. An index in a book is a list of words with the page numbers that contain each word. An index in a database is a list of values in a table with the storage locations of rows in the table that contain each value. When you create a database and tune it for performance, you should create indexes for the columns used in queries to find data. SQL Server automatically creates indexes for certain types of constraints (for example, PRIMARY KEY and UNIQUE constraints). You can further customize the table definitions by creating indexes that are independent of constraints. The performance benefits of indexes, however, do come with a cost. Tables with indexes require more storage space in the database. Also, commands that insert, update, or delete data can take longer and require more processing time to maintain the indexes. When you design and create indexes, you should ensure that the performance benefits outweigh the extra cost in storage space and processing resources. Optionally: In Index name, enter a name for the index if different from the default name supplied. In Index file group, select a file group on which to create the index. Select Create UNIQUE to make this index a unique constraint. Or click Index to make this index unique. Select Create as CLUSTERED to make this index clustered. 100

SQL Serve an Overview Views A view is a virtual table whose contents are defined by a query. Like a real table, a view consists of a set of named columns and rows of data. However, a view does not exist as a stored set of data values in a database. The rows and columns of data come from tables referenced in the query defining the view and are produced dynamically when the view is referenced. A view acts as a filter on the underlying tables referenced in the view. The query that defines the view can be from one or more tables or from other views in the current or other databases. Distributed queries can also be used to define views that use data from multiple heterogeneous sources. This is useful, for example, if you want to combine similarly structured data from different servers each of which stores data for a different region of your organization. There are no restrictions on querying through views and few restrictions on modifying data through them. A view is a virtual table whose contents are defined by a query. However, a view does not exist as a stored set of data values in a database. The rows and columns of data come from tables referenced in the query defining the view and are produced dynamically when the view is referenced. Create View in Enterprise Manager Expand Databases; then expand the database in which to create the view. Right-click Views; then click New View... Right-click in the diagram pane of Creating Views (Ref. fig. 2); then click Add Table... On the Tables or Views tabs, click the table or view to add to the new view, and then click Add. Repeat for each table or view you want to add to the new view. In the Column box of the grid pane, select the columns to be referenced in the view. Select Output if the column is to appear in the result set of the view. To group by column, right-click the column, and then click Group By. In the Criteria column, enter the criteria specifying which rows to retrieve; this determines the WHERE clause. If Group By is specified, this determines the HAVING clause. In the OR column, enter any additional criteria to specify which rows to retrieve. Right-click anywhere in the grid pane; then click Properties. 101

SQL Serve -an Overview Diagram Pane Grid Pane SQL Pane Results Pane Creating Views (fig. 2) 102