Section 1 Your Data Any Place Any Time

  • Slides: 33
Download presentation
Section 1 Your Data, Any Place, Any Time 1

Section 1 Your Data, Any Place, Any Time 1

What Is SQL Server 2008? q Microsoft SQL Server is a Relational Database Management

What Is SQL Server 2008? q Microsoft SQL Server is a Relational Database Management System (RDBMS) designed to run on platforms ranging from laptops to large multiprocessor servers. q SQL Server is commonly used as the backend system for websites and corporate and can support thousands of concurrent users. q SQL Server comes with a number of tools to help you with your database administration and programming tasks. q SQL Server is much more robust and scalable than a desktop database management system such as Microsoft Access. q Anyone who has ever tried using Access as a backend to a website will probably be familiar with the errors that were generated when too many users tried to access the database! q Although SQL Server can also be run as a desktop database system, it is most commonly used as a server database system. 2

u. Why SQL Server? q There a couple of reasons why SQL Server is

u. Why SQL Server? q There a couple of reasons why SQL Server is the best choice for a broad spectrum of end users and database programmers building business applications q SQL Server is certainly the best system for Windows OS Ø Because of its tight integration (and low pricing) Ø Because the number of installed Windows systems is enormous and still increasing rapidly, SQL Server is a widely used system. q Database Engine, as the relational database system component, is the easiest database system to use. q In addition to the well-known user interface, Microsoft offers several different tools to help you create database objects, tune your database applications, and manage system administration tasks. q Generally, SQL Server isn’t only a database system. q It is a platform that comprises Database Engine, Analysis Services, Reporting Services and Integration 3 Services

u. Comparing with other DB Engines http: //www. microsoft. com/sqlserver/2008/en/us/compare. aspx 4

u. Comparing with other DB Engines http: //www. microsoft. com/sqlserver/2008/en/us/compare. aspx 4

Goals of the Course …. . & Why I learn SQL Server q Data

Goals of the Course …. . & Why I learn SQL Server q Data Base developer [60%] q Data Base administrator [35%] q Business Intelligence developer [5%] 5

Overview of Client/Server Architecture (1) Client SQL Server Results OLTP Query OLAP Relational Database

Overview of Client/Server Architecture (1) Client SQL Server Results OLTP Query OLAP Relational Database Management System Client Application 6

Selecting an Application Architecture for SQL Server Intelligent Server (2 -Tier) Intelligent Client (2

Selecting an Application Architecture for SQL Server Intelligent Server (2 -Tier) Intelligent Client (2 -Tier) N-Tier Presentation Internet Browser Client Presentation Business Data Business Data 7

SQL Server 2008 Services 8

SQL Server 2008 Services 8

SQL Server Version History SQL Server 1. 0 (1989) Developed by Microsoft, Sybase, and

SQL Server Version History SQL Server 1. 0 (1989) Developed by Microsoft, Sybase, and Ashton-Tate for OS/2 SQL Server 4. 2 (1992) Developed for Windows NT 3. 1 SQL Server 6. 0 (1995) First version architected specifically for Windows NT SQL Server 7. 0 (1999) Total rewrite of code base resulted in performance and scalability improvements SQL Server 2000 Further improvements in performance, scalability, and reliability SQL Server 2005 New and improved features: Integration Services, Analysis Services, Notification Services, Reporting Services, XML support SQL Server 2008 R 2 SQL Server 2014

SQL Server 2008 Editions Enterprise For large scale, business-critical applications Standard For small/medium, departmental

SQL Server 2008 Editions Enterprise For large scale, business-critical applications Standard For small/medium, departmental applications Workgroup For small scale, branch applications Express Entry level/learning edition Compact For embedded databases Web For low-end Web hosting Developer For development and testing Evaluation Trial edition

SQL Server 2008 Installation 11

SQL Server 2008 Installation 11

Planning for SQL Server 2008 installation q Careful planning is absolutely necessary because several

Planning for SQL Server 2008 installation q Careful planning is absolutely necessary because several decisions have to be made before the installation of the system is started. The system administrator should have clear answers to the following questions before beginning the installation process: q What is the purpose of the SQL Server system? Ø Educational Ø Production § number of users & amount of stored data § Is the system used for operational or analytical tasks q What are the hardware and network requirements? q How many users will be active at the same time? 12

SQL Server 2008 Hardware and Software Requirements q Hardware Ø Pentium III 1 GHz

SQL Server 2008 Hardware and Software Requirements q Hardware Ø Pentium III 1 GHz processor (32 bit or 64 bit) Ø 1 GB memory Ø 280 MB disk space for a minimal install q Software Ø Windows XP SP 2, Windows Server 2003 SP 1, Windows Server 2008, Windows Vista , windows 7 , 8, 10. Ø Windows Installer 3. 1 and MDAC 2. 8 SP 1 Ø Internet Explorer 6 SP 1 13

Ready To Install. . The SQL Server Installation Center 14

Ready To Install. . The SQL Server Installation Center 14

Results from the system configuration check. 15

Results from the system configuration check. 15

Results from the Setup Report Rules check 16

Results from the Setup Report Rules check 16

Selecting features for this SQL Server instance 17

Selecting features for this SQL Server instance 17

Configuring the SQL Server instance 18

Configuring the SQL Server instance 18

Setting usernames, passwords, and startup options 19

Setting usernames, passwords, and startup options 19

Provisioning database engine configuration. 20

Provisioning database engine configuration. 20

Reporting Services configuration. 21

Reporting Services configuration. 21

Viewing selected features and options. 22

Viewing selected features and options. 22

Login Authentication AUTHENTICATION Windows Group or User SQL Server Verifies Trusted Connection Windows SQL

Login Authentication AUTHENTICATION Windows Group or User SQL Server Verifies Trusted Connection Windows SQL Server OR SQL Server Verifies Name and Password SQL Server Login Account 23

Connecting to SQL Server q Server Type: Database Engine. q Server name: Ø 127.

Connecting to SQL Server q Server Type: Database Engine. q Server name: Ø 127. 0. 0. 1 Ø (Local) Ø. q Authentication: Ø windows Ø sql server (user name & password) 24

SSMS q SSMS is a client tool not a server. Ø Developer machines connect

SSMS q SSMS is a client tool not a server. Ø Developer machines connect to sql server using SSMS. 25

Creating and altering database q SQL server database can be Created, altered and dropped

Creating and altering database q SQL server database can be Created, altered and dropped Ø GUI using SSMS. Ø Using Query. q Creating database query Ø Create database db_name Ø Two files are created §. mdf fiel: data file (contains actual data). §. ldf file : transaction log file (used to recover database). q Altering database Ø Alter database db_name modify name=new_Dbname Ø Sp_rename. DB old. DB_name , new. DB_name 26

Deleting or Dropping a database q To Delete or drop a DB Ø Drop

Deleting or Dropping a database q To Delete or drop a DB Ø Drop database db_name q Dropping a DB, deletes the LDF and MDF files. q If DB is currently in use it can not be dropped. An error will appear. q Error will appear if another user is connected to DB. It should be put in single user mode then drop the DB. Ø Alter database db_name set single_user with rollback immediate q With rollback immediate option, all in complete transactions will be rollback and open connections will be closed. q Note: system databases(e. g. master) cannot be dropped. 27

Creating tables q Tables can be created using Ø GUI. Ø Using SQL query.

Creating tables q Tables can be created using Ø GUI. Ø Using SQL query. CREATE TABLE table_name ( column_name 1 data_type(size) constraint_name, column_name 2 data_type(size) constraint_name, ); CREATE TABLE Persons ( Person. ID int, Last. Name varchar(255), First. Name varchar(255), Address varchar(255), City varchar(255) ); Ø SQL constraints: can be specified when the table is created or after the table is created (ALTER TABLE statement). § NOT NULL § PRIMARY KEY § CHECKDEFAULT >UNIQUE >FOREIGN KEY 28

UNIQUE Constraint q Uniquely identifies each record in a database table. q The UNIQUE

UNIQUE Constraint q Uniquely identifies each record in a database table. q The UNIQUE and PRIMARY KEY constraints both provide a guarantee for uniqueness for a column or set of columns. q PRIMARY KEY constraint automatically has a UNIQUE constraint defined on it. q Note that you can have many UNIQUE constraints per table, but only one PRIMARY KEY constraint per table. CREATE TABLE Persons ( P_Id int NOT NULL, Last. Name varchar(255) NOT NULL, City varchar(255), CONSTRAINT uc_Person. ID UNIQUE (P_Id, Last. Name) ALTER TABLE Persons ADD UNIQUE (P_Id) 29 ALTER TABLE Persons DROP CONSTRAINT uc_Person. ID ) ALTER TABLE Persons ADD CONSTRAINT uc_Person. ID UNIQUE (P_Id, Last. Name)

PRIMARY KEY Constraint q q q Uniquely identifies each record in a database table.

PRIMARY KEY Constraint q q q Uniquely identifies each record in a database table. Must contain UNIQUE values. CREATE TABLE Persons ( Cannot contain NULL values. P_Id int NOT NULL, Last. Name varchar(255) NOT NULL, Most tables should have a primary key. First. Name varchar(255), A table can have only ONE primary key. Address varchar(255), City varchar(255), CONSTRAINT pk_Person. ID PRIMARY KEY (P_Id, Last. Name) ) CREATE TABLE Persons ( P_Id int NOT NULL PRIMARY KEY, Last. Name varchar(255) NOT NULL, City varchar(255) ) ALTER TABLE Persons ADD CONSTRAINT pk_Person. ID PRIMARY KEY (P_Id, Last. Name) ALTER TABLE Persons ADD PRIMARY KEY (P_Id) ALTER TABLE Persons DROP PRIMARY KEY 30

FOREIGN KEY Constraint Ø Used to enforce database integrity. Ø Foreign key in on

FOREIGN KEY Constraint Ø Used to enforce database integrity. Ø Foreign key in on table points to a primary key in another table. Ø Foreign key constraint prevents invalid data being inserted into the foreign key column. Ø The values that you enter into the foreign key column has to be one of the values contained in the table it points to (no null). CREATE TABLE Orders ( O_Id int PRIMARY KEY, Order. No int NOT NULL, P_Id int FOREIGN KEY REFERENCES Persons(P_Id) ) CREATE TABLE Orders ( O_Id int, Order. No int NOT NULL, P_Id int, PRIMARY KEY (O_Id), CONSTRAINT fk_Per. Orders FOREIGN KEY (P_Id) REFERENCES Persons(P_Id) ) ALTER TABLE Orders ADD CONSTRAINT fk_Per. Orders FOREIGN KEY (P_Id) REFERENCES Persons(P_Id) 31 ALTER TABLE Orders DROP CONSTRAINT fk_Per. Orders

Default constraint q The DEFAULT constraint is used to insert a default value into

Default constraint q The DEFAULT constraint is used to insert a default value into a column if no other value is specified. ALTER TABLE Persons ADD CONSTRAINT DF_persons_city DEFAULT ‘Tanta FOR COLUMN City CREATE TABLE Persons ( Id int NOT NULL, Last. Name varchar(255) NOT NULL, First. Name varchar(255), Address varchar(255), City varchar(255) DEFAULT ‘Tanta' ) ALTER TABLE Persons Drop CONSTRAINT DF_persons_city 32

CHECK Constraint q Used to limit the value range that can be placed in

CHECK Constraint q Used to limit the value range that can be placed in a column. q A CHECK on a single column allows only certain values for this column. q A CHECK on a table it can limit the values in certain columns based on values in other columns in the row. CREATE TABLE Persons ( P_Id int Primary Key, First. Name varchar(255), Address varchar(255), City varchar(255), CONSTRAINT chk_Person CHECK (P_Id>0 AND City='Sandnes') ) CREATE TABLE Persons ( P_Id int Primary Key, First. Name varchar(255), Address varchar(255), City varchar(255), CHECK (P_Id>0) ) ALTER TABLE Persons ADD CONSTRAINT chk_Person CHECK (P_Id>0 AND City='Sandnes') CREATE TABLE Persons ( P_Id int Primary Key CHECK (P_Id>0), First. Name varchar(255), Address varchar(255), City varchar(255) ) 33 ALTER TABLE Persons Drop CONSTRAINT chk_Person