Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 4 SQL. SQL server Microsoft SQL Server is a client/server database management system. Microsoft SQL Server is a client/server database management.

Similar presentations


Presentation on theme: "Chapter 4 SQL. SQL server Microsoft SQL Server is a client/server database management system. Microsoft SQL Server is a client/server database management."— Presentation transcript:

1 Chapter 4 SQL

2 SQL server Microsoft SQL Server is a client/server database management system. Microsoft SQL Server is a client/server database management system. A client/server database management system consists of two components: A client/server database management system consists of two components: A front-end component (the client), which is used to present and manipulate data; A front-end component (the client), which is used to present and manipulate data; A backend component (the database server), which is used to store, retrieve, and protect the databases. A backend component (the database server), which is used to store, retrieve, and protect the databases.

3 Components of SQL Server The commands you primarily use to query a database on a database server are The commands you primarily use to query a database on a database server are part of the Structured Query Language (SQL). part of the Structured Query Language (SQL). The Structured Query Language is a standardized set of commands used to work with databases. The Structured Query Language is a standardized set of commands used to work with databases. Microsoft SQL Server 2000 supports an enhanced version of SQL referred to as Transact-SQL Microsoft SQL Server 2000 supports an enhanced version of SQL referred to as Transact-SQL Transact-SQL commands used to create, maintain, and query databases Transact-SQL commands used to create, maintain, and query databases Microsoft Microsoft SQL Server supports the most recently published standards for ANSI SQL. Sometimes, the version of SQL implemented in SQL Server referred to as SQL-92. SQL Server supports the most recently published standards for ANSI SQL. Sometimes, the version of SQL implemented in SQL Server referred to as SQL-92.

4 Transact-SQL Data Definition Language (DDL) statements, which enable you to create database objects. Data Definition Language (DDL) statements, which enable you to create database objects. Data Manipulation Language (DML) statements, which enable you to query or modify data. Data Manipulation Language (DML) statements, which enable you to query or modify data. Data Control Language (DCL) statements, which enable you to determine,set, or revoke users’ permissions to SQL databases and their objects Data Control Language (DCL) statements, which enable you to determine,set, or revoke users’ permissions to SQL databases and their objects

5 Microsoft SQL Server 2000 supports two login authentication modes : Microsoft SQL Server 2000 supports two login authentication modes : Windows Authentication mode Windows Authentication mode Mixed mode Mixed mode

6 Database Master – Information about the operation of SQL Server,including user accounts, other SQL servers,environment variables,error messages,databases, storage space allocated to databases,and the tapes and disk drives on the SQL server. Master – Information about the operation of SQL Server,including user accounts, other SQL servers,environment variables,error messages,databases, storage space allocated to databases,and the tapes and disk drives on the SQL server. Model – A template for creating new databases. SQL Server automatically copies the objects in this database to each new database you create. Model – A template for creating new databases. SQL Server automatically copies the objects in this database to each new database you create. Msdb – Information about all scheduled jobs,defined alerts,and operators on your server. This information is used by the SQL Server Agent service. Msdb – Information about all scheduled jobs,defined alerts,and operators on your server. This information is used by the SQL Server Agent service. Tempdb –Temporary information. This database is used as a scratchpad by SQL Server. Tempdb –Temporary information. This database is used as a scratchpad by SQL Server. Northwind, pubs – A sample database for learning SQL Server. Northwind, pubs – A sample database for learning SQL Server.

7 Components of SQL Server The SQL Server Services The SQL Server Services

8 SQL Server Enterprise Manager can also create your own server groups to organize your SQL servers can also create your own server groups to organize your SQL servers

9 SQL Query Analyzer Use SQL Query Analyzer to run SQL queries as well as to optimize the performance of the queries. Use SQL Query Analyzer to run SQL queries as well as to optimize the performance of the queries. A query is simply a command you send to your server. This query can request data from the server, change data, or delete information. A query is simply a command you send to your server. This query can request data from the server, change data, or delete information.

10 SQL Query Analyzer

11 Using SQL Query Analyzer

12 SQL Server Database Structure the term database refers to a collection of tables and other database objects such as indexes the term database refers to a collection of tables and other database objects such as indexes A table consists of rows and columns; these rows and columns contain the data for the table. A table consists of rows and columns; these rows and columns contain the data for the table. A database can contain a virtually unlimited number of tables; each table can contain a maximum of 1,024 columns (fields). A database can contain a virtually unlimited number of tables; each table can contain a maximum of 1,024 columns (fields).

13 Designing and Implementing Databases To design, create, and manage databases: To design, create, and manage databases: Identify the issues for designing databases Identify the issues for designing databases Create and configure databases Create and configure databases Manage databases Manage databases

14 Identifying Database Design Issues Databases and Files: Databases and Files: A database is a collection of database objects; these objects include tables, indexes, views, and stored procedures. A database is a collection of database objects; these objects include tables, indexes, views, and stored procedures. At a minimum, each database consists of a primary data file with an extension of.mdf. At a minimum, each database consists of a primary data file with an extension of.mdf. In addition to its primary data file,you can optionally configure SQL Server to store a database in a secondary data file. These files use the extension of.ndf. In addition to its primary data file,you can optionally configure SQL Server to store a database in a secondary data file. These files use the extension of.ndf.

15 Identifying Database Design Issues Transaction Logs:In addition to a database’s primary data file, you must also create a transaction log for each database. Transaction Logs:In addition to a database’s primary data file, you must also create a transaction log for each database. SQL Server automatically assigns the extension of.ldf to each transaction log file. SQL Server automatically assigns the extension of.ldf to each transaction log file. SQL Server uses the transaction log to make it possible to either recover (roll forward) or undo (roll back) a transaction to protect your database from corruption in the event of a server crash.. SQL Server uses the transaction log to make it possible to either recover (roll forward) or undo (roll back) a transaction to protect your database from corruption in the event of a server crash..

16 File groups When create a database, SQL Server automatically creates a default filegroup that contains your database’s primary data file When create a database, SQL Server automatically creates a default filegroup that contains your database’s primary data file

17 SQL Server uses disk space in 8 KB pages. SQL Server uses disk space in 8 KB pages. SQL Server uses some pages to keep track of the space allocated within a database SQL Server uses some pages to keep track of the space allocated within a database Within a database, SQL Server allocates space for database objects such as tables and indexes in extents. Within a database, SQL Server allocates space for database objects such as tables and indexes in extents. An extent is a contiguous block of eight pages for a total of 64 KB of disk space. An extent is a contiguous block of eight pages for a total of 64 KB of disk space. A database consists of 16 extents per megabyte. A database consists of 16 extents per megabyte.

18

19 Creating Databases Create a database by using: Create a database by using: the CREATE DATABASE Transact-SQL statement. the CREATE DATABASE Transact-SQL statement. the Create Database Wizard. the Create Database Wizard. SQL Server Enterprise Manager SQL Server Enterprise Manager

20 Using the Create Database Wizard

21 Creating a Database Using Transact-SQL CREATE DATABASE logical_database_name ON PRIMARY (NAME = logical_file_name, FILENAME = 'path\file_name', SIZE = size, MAXSIZE = maxsize, FILEGROWTH = filegrowth_increment) LOG ON (NAME = logical_file_name, FILENAME = 'path\file_name', SIZE = size, MAXSIZE = maxsize, FILEGROWTH = filegrowth_increment)

22 Creating a Database Using Transact-SQL CREATE DATABASE SalesDb ON (NAME = SalesDb_dat, FILENAME = 'c:\data\salesDB_dat.mdf', SIZE = 10, MAXSIZE = 50, FILEGROWTH = 5) LOG ON (NAME = 'SalesDb_log', FILENAME = 'c:\data\salesDB_log.ldf', SIZE = 5MB, MAXSIZE = 25MB, FILEGROWTH = 10%) GO

23 Creating a Database Using Transact-SQL Creating Filegroup CREATE DATABASE logical_database_name ON PRIMARY (NAME = logical_file_name, FILENAME = 'path\file_name.mdf', SIZE = size, MAXSIZE = maxsize, FILEGROWTH = filegrowth_increment) FILEGROUP filegroup_name (NAME = logical_file_name, FILENAME = 'path\file_name.ndf', SIZE = size, MAXSIZE = maxsize, FILEGROWTH = filegrowth_increment) LOG ON (NAME = logical_file_name, FILENAME = 'path\file_name', SIZE = size, MAXSIZE = maxsize, FILEGROWTH = filegrowth_increment)

24 ALTER DATABASE Adding Filegroups to an Existing Database ALTER DATABASE logical_database_name ADD FILEGROUP new_filegroup_name Adding Files ALTER DATABASE logical_database_name ADD FILE (NAME = logical_file_name, FILENAME = 'path\file_name.ndf', SIZE = size, MAXSIZE = maxsize, FILEGROWTH = filegrowth_increment) TO FILEGROUP filegroup_name

25 ALTER DATABASE Configuring Database Options ALTER DATABASE database_name SET option[, status] ALTER DATABASE movies SET READ_ONLY

26 ALTER DATABASE Expanding a Database and its Transaction Log ALTER DATABASE database_name MODIFY FILE (NAME = 'logical_name', SIZE = size, MAXSIZE = maxsize, FILEGROWTH = filegrowth_increment) support unrestricted file growth by using the clause MAXSIZE = UNLIMITED

27 Deleting a Database DROP DATABASE database_name.

28 Using SQL Server Enterprise Manager


Download ppt "Chapter 4 SQL. SQL server Microsoft SQL Server is a client/server database management system. Microsoft SQL Server is a client/server database management."

Similar presentations


Ads by Google