0% found this document useful (0 votes)
8 views21 pages

Primera Parte SQL

Uploaded by

Rubiera
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views21 pages

Primera Parte SQL

Uploaded by

Rubiera
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

||||||||||||||||||||

Introduction
Microsoft SQL Server is a database system that
comprises many components, including the Database
Engine, Analysis Services, Reporting Services, SQL
Server Graph Databases, SQL Server Machine Learning
Services, and several other components. The following
are a few of the reasons SQL Server is the best choice for
a broad spectrum of end users and database
programmers building business applications:

• SQL Server is certainly the best system for


Windows operating systems, because of its tight
integration (and low pricing). Because the number
of installed Windows systems is enormous and still
increasing, SQL Server is a widely used database
system.
• As of SQL Server 2017, Microsoft supports other
operating systems as well: several Linux
distributions, such as Ubuntu and Red Hat Linux,
as well as macOS.
• The Database Engine, as the relational database
system component, is the easiest database system
to use. In addition to the Database Engine’s well-
known Windows-style user interface, Microsoft
offers several different tools to help you create

NEWOUTLOOK.IT
Technet24
||||||||||||||||||||
||||||||||||||||||||

database objects, tune your database applications,


and manage system administration tasks.

Generally, SQL Server isn’t only a relational database


system. It is a platform that not only manages
structured, semistructured, unstructured, and graph data
but also offers comprehensive, integrated operational
and analysis software that enables organizations to
reliably manage mission-critical information.

Goals of the Book


Microsoft SQL Server 2019: A Beginner’s Guide follows
six previous editions that covered SQL Server 7, 2000,
2005, 2008, 2012, and 2016. SQL Server has evolved
significantly since I wrote the first edition over 20 years
ago, but my overarching goal has remained the same: to
provide a comprehensive introduction to SQL Server that
is friendly to beginners.
Generally, all SQL Server users who want to get a good
understanding of this database system and to work
successfully with it will find this book very helpful. If you
are a new SQL Server user but understand SQL, read the
section “Differences Between SQL and Transact-SQL
Syntax” later in this introduction.
This book addresses users of different components of
SQL Server. For this reason, it is divided into several
parts: The first three parts are most useful to users who
want to learn more about Microsoft’s relational database
component called the Database Engine. The fourth part

NEWOUTLOOK.IT
||||||||||||||||||||
||||||||||||||||||||

of the book is dedicated to Business Intelligence (BI)


users who use Analysis Services and/or Reporting
Services. The fifth part of the book provides insight for
users who want to learn about SQL Server features
beyond those specific to relational data, such as
integration of the JSON format with the relational
engine, support for temporal and spatial data, and
support for graph databases as an integral part of SQL
Server. The last part of the book describes SQL Server
Machine Learning Services, which provides the
integration of the R system and the Python programming
language with SQL Server

SQL Server 2019 New Features Described in


the Book
SQL Server 2019 has a lot of new features, and almost all
of them are discussed in this book. For each feature, at
least one running example is provided to enable you to
understand that feature better. The following table lists
and summarizes the most important new features and
identifies the chapter in which each is covered.

NEWOUTLOOK.IT
Technet24
||||||||||||||||||||
||||||||||||||||||||

NEWOUTLOOK.IT
||||||||||||||||||||
||||||||||||||||||||

NEWOUTLOOK.IT
Technet24
||||||||||||||||||||
||||||||||||||||||||

Organization of the Book


The book has 33 chapters and is divided into six parts.
Part I, “Basic Concepts and Installation,” provides an
overview of database systems and explains how to install
SQL Server 2019 and its components. It includes the
following chapters:

• Chapter 1, “Relational Database Systems: An


Introduction,” discusses database systems in
general and then narrows focus to relational
database systems—the SQL Server Database
Engine in particular. It presents the sample
database used in examples throughout the book
and introduces the Structured Query Language
(SQL) that is used in relational database systems.
It then provides an overview of two important
database design concepts, normal forms and the
entity-relationship model. The chapter also
introduces the syntax conventions that are used in
the rest of the book.
• Chapter 2, “Planning the Installation and Installing
SQL Server,” describes the first system
administration task: the planning and installation
of the overall system. Planning includes selection
of the appropriate SQL Server edition and
management tools, so the chapter begins with an
overview of the editions and tools available. It then
provides general recommendations to consider

NEWOUTLOOK.IT
||||||||||||||||||||
||||||||||||||||||||

during the planning phase. Turning to the


installation of SQL Server, which overall is a
straightforward task, the chapter not only explains
how to install SQL Server on Windows, but also
describes the installation process on Ubuntu as an
example of Microsoft’s new support (as of SQL
Server 2017) for several Linux distributions as well
as macOS.
• Chapter 3, “Front-End Tools for the Database
Engine,” describes two components with similar
functionality: SQL Server Management Studio
(SSMS) and Azure Data Studio. The main
difference between them is that the former runs
exclusively on Windows, while the latter also can
be used for Linux distributions and macOS. These
components are presented early in the book in case
you want to create database objects and query data
but don’t yet have a working knowledge of SQL.

Part II, “Transact-SQL Language,” is intended for end


users and application programmers of the Database
Engine. It comprises the following chapters:

• Chapter 4, “SQL Components,” describes the


fundamentals of the most important part of a
relational database system: a database language.
For all such systems, there is only one language
that counts: SQL. This chapter describes all
components of SQL Server’s own database
language, Transact-SQL, and introduces the basic

NEWOUTLOOK.IT
Technet24
||||||||||||||||||||
||||||||||||||||||||

language concepts and data types. Finally, the


chapter details the system functions and operators
of Transact-SQL.
• Chapter 5, “Data Definition Language,” describes
all data definition language (DDL) statements of
Transact-SQL. The DDL statements are presented
in three groups, depending on their purpose. The
first group contains all forms of the CREATE
statement, which is used to create database objects.
The second group contains all forms of the ALTER
statement, which is used to modify the structure of
some database objects. The third group contains all
forms of the DROP statement, which is used to
remove different database objects.
• Chapter 6, “Queries,” discusses the most important
Transact-SQL statement: SELECT. This chapter
introduces you to database data retrieval and
describes the use of simple and complex queries.
Each SELECT clause is separately defined and
explained with reference to the sample database.
• Chapter 7, “Modification of a Table’s Contents,”
discusses the four Transact-SQL statements used
for updating data: INSERT, UPDATE, DELETE,
and MERGE. Each of these statements is explained
through numerous examples.
• Chapter 8, “Stored Procedures and User-Defined
Functions,” introduces batches and routines. A
batch is a sequence of Transact-SQL statements

NEWOUTLOOK.IT
||||||||||||||||||||
||||||||||||||||||||

and procedural extensions. A routine can be either


a stored procedure or a user-defined function
(UDF). Routines can be used to create powerful
programs that are stored on the server and can be
reused. Because Transact-SQL is a complete
computational language, all procedural extensions
are inseparable parts of the language. Some stored
procedures are written by users; others are
provided by Microsoft and are referred to as
system stored procedures.
• Chapter 9, “System Catalog,” describes one of the
most important parts of a database system: the
system catalog, which consists of tables describing
the structure of objects such as databases, base
tables, views, and indices. The system catalog
contains tables that are used to store the
information concerning database objects and their
relationships. The main characteristic of system
tables of the Database Engine is that they cannot
be accessed directly. The Database Engine
supports several interfaces that you can use to
query the system catalog.
• Chapter 10, “Indices,” covers the first and most
powerful method that database application
programmers can use to tune their applications to
get better system response and therefore better
performance. This chapter describes the role of
indices and gives you guidelines for how to create
and use them. The end of the chapter introduces

NEWOUTLOOK.IT
Technet24
||||||||||||||||||||
||||||||||||||||||||

the special types of indices supported by the


Database Engine.
• Chapter 11, “Views,” explains how you create views,
discusses the practical use of views (using
numerous examples), and shows how views can be
used with SELECT, INSERT, UPDATE, and
DELETE statements.
• Chapter 12, “Security System of the Database
Engine,” provides answers to all your questions
concerning security of data in the database. It
addresses questions about data encryption,
authorization (which user has been granted
legitimate access to the database system), and
authentication (which access privileges are valid
for a particular user). It discusses three Transact-
SQL statements—GRANT, DENY, and REVOKE—
that provide the access privileges of database
objects against unauthorized access. The end of the
chapter explains how data changes can be tracked
using the Database Engine.
• Chapter 13, “Concurrency Control,” describes
concurrency control in depth. The beginning of the
chapter discusses the two different concurrency
control models supported by the Database Engine,
pessimistic and optimistic. Next, the chapter
explains transactions, which are used by the
database system to guarantee data consistency. It
then discusses locking as a method to solve
concurrency control problems. The end of the

NEWOUTLOOK.IT
||||||||||||||||||||
||||||||||||||||||||

chapter explains two mechanisms for


implementing concurrency control: isolation levels
and row versioning.
• Chapter 14, “Triggers,” describes the
implementation of business logic using triggers. It
discusses DML triggers and DDL triggers and
shows their application areas. Each example in this
chapter concerns a problem that you may face in
your everyday life as a database application
programmer.

Part III, “SQL Server: System Administration,”


describes all objectives of Database Engine system
administration. It comprises the following chapters:

• Chapter 15, “System Environment of the Database


Engine,” discusses some internal issues concerning
the Database Engine. It provides a detailed
description of the Database Engine system
databases, disk storage elements, and utilities.
Additionally, several DBCC commands are
explained, and the Policy-Based Management is
introduced. (This component allows you to manage
instances of the Database Engine.)
• Chapter 16, “Backup, Recovery, and System
Availability,” provides an overview of the fault-
tolerance methods used to implement a backup
strategy using either SQL Server Management
Studio or corresponding Transact-SQL statements.
The chapter first covers the reasons for data loss

NEWOUTLOOK.IT
Technet24
||||||||||||||||||||
||||||||||||||||||||

and specifies the different methods used to


implement a backup strategy. The middle of the
chapter discusses performing database backups
and the restoration of databases. The chapter then
describes in detail (and then compares) the
following techniques (and a few others) for
ensuring system availability: database mirroring,
failover clustering, log shipping, and AlwaysOn.
The chapter wraps up by describing how to
maintain your database with the assistance of the
Maintenance Plan Wizard.
• Chapter 17, “Automating System Administration
Tasks,” describes the Database Engine component
called SQL Server Agent that enables you to
automate certain system administration jobs, such
as backing up data and using the scheduling and
alert features to notify operators. This chapter also
explains how to create jobs, operators, and alerts.
• Chapter 18, “Data Replication,” provides an
introduction to data replication, including concepts
such as the publisher and subscriber. It introduces
the different replication models and serves as a
tutorial for how to configure publications and
subscriptions using the existing wizards.
• Chapter 19, “Query Optimizer,” describes the role
and the work of the query optimizer. It explains in
detail all the Database Engine tools (the SET
statement, SQL Server Management Studio, and
various dynamic management views) that can be

NEWOUTLOOK.IT
||||||||||||||||||||
||||||||||||||||||||

used to edit the optimizer strategy. The end of the


chapter provides optimizer hints.
• Chapter 20, “Performance Tuning,” discusses
performance issues and the tools for tuning the
Database Engine that are relevant to daily
administration of the system. After introductory
notes concerning the measurements of
performance, this chapter describes the factors
that affect performance and presents tools for
monitoring the performance of the Database
Engine. The end of the chapter describes additional
performance tools, including automatic plan
tuning, a new feature that provides insights into
potential query performance problems,
recommends solutions, and automatically fixes
identified problems.
• Chapter 21, “In-Memory OLTP,” describes the
Database Engine component that can be used to
optimize OLTP (online transactional processing)
queries. This means that a user can achieve
significant performance improvements when
specific database objects are stored entirely in
memory instead of on disk. The chapter describes
in detail the use of memory-optimized tables and
compiled stored procedures, which are part of In-
Memory OLTP.

Part IV, “SQL Server and Business Intelligence,”


discusses business intelligence (BI) and all related topics.

NEWOUTLOOK.IT
Technet24
||||||||||||||||||||
||||||||||||||||||||

The chapters in this part of the book introduce Microsoft


Analysis Services and Microsoft Reporting Services.
SQL/OLAP, existing optimization techniques concerning
relational data storage, as well as Intelligent Query
Processing are described in detail, too. This part includes
the following chapters:

• Chapter 22, “Business Intelligence: An


Introduction,” introduces the concept of data
warehousing. The first part of the chapter explains
the differences between online transaction
processing and data warehousing. The data store
for a data warehousing process can be either a data
warehouse or a data mart. Both types of data stores
are discussed, and their differences are listed in the
second part of the chapter. The end of the chapter
explains different forms of data access.
• Chapter 23, “SQL Server Analysis Services,”
introduces the BI Semantic Model, which contains
two submodels: Multidimensional and Tabular.
The chapter explains the integration of both
models into Visual Studio 2019 and provides an
example showing the creation and deployment of
each solution. It also introduces the MDX language
for the Multidimensional model and the DAX
language for the Tabular model. The end of the
chapter presents security issues of SSAS.
• Chapter 24, “Business Intelligence and Transact-
SQL,” explains how you can use Transact-SQL to

NEWOUTLOOK.IT
||||||||||||||||||||
||||||||||||||||||||

solve business intelligence problems. This chapter


discusses the window construct, with its
partitioning, ordering, and framing. It also
discusses several operators, ranking functions, the
TOP clause, and the PIVOT relational operator.
The end of the chapter explains the new group of
functions in relation to Approximate Query
Processing.
• Chapter 25, “SQL Server Reporting Services,”
describes the Microsoft enterprise reporting
solution. This component is used to design and
deploy reports. The chapter discusses the
development environment that you use to design
and create reports and shows you different ways to
deliver a deployed report. The end of the chapter
describes performance and security issues related
to SQL Server Reporting Services.
• Chapter 26, “Optimizing Techniques for Data
Warehousing,” describes three of the several
specific optimization techniques that can be used
especially in the area of business intelligence: data
partitioning, star join optimization, and indexed
views. The data partitioning technique called range
partitioning is described. In relation to star join
optimization, the role of bitmap filters in the
optimization of joins is explained. The final part of
the chapter explains the special index form called
indexed views.
• Chapter 27, “Columnstore Indices,” is devoted to

NEWOUTLOOK.IT
Technet24
||||||||||||||||||||
||||||||||||||||||||

the topic of columnar storage because of its


importance. First, the chapter explains the benefits
of this technique. After that, it discusses the
technical details. The chapter also explains two
forms of columnstore indices: clustered and
nonclustered. The last part of the chapter, which is
entirely new in this edition, compares performance
of the columnstore index and a corresponding row
store.
• Chapter 28, “Intelligent Query Processing,”
describes a group of sophisticated and related
features concerning the Query Processor of the
Database Engine. The main goal of these features is
to improve performance of existing workloads
while requiring only minimal implementation
effort to adopt the features. The following features
belong to Intelligent Query Processing: Adaptive
Query Processing, Batch mode on Rowstore,
Approximate Query Processing, Scalar UDF
Inlining, and Table Variable Deferred Compilation.

Part V, “Beyond Relational Data,” is dedicated to the


following nonrelational topics: JSON, spatial and
temporal data, and the newly added support for graph
data. The following chapters are included in this part:

• Chapter 29, “JSON Integration in the Database


Engine,” discusses first JSON integration in SQL
Server and Microsoft’s set of data types and
functions that supports storing JSON documents

NEWOUTLOOK.IT
||||||||||||||||||||
||||||||||||||||||||

in the Database Engine, bridging the gap between


JSON and relational data. The next part of the
chapter explains how to present JSON documents
as relational data, and vice versa, and how to query
JSON documents. The last part, new to this
edition, explains how JSON documents can be
modified in the relational environment.
• Chapter 30, “Spatial and Temporal Data,” discusses
two special data forms: spatial data and temporal
data. First, it describes the spatial data types,
GEOMETRY and GEOGRAPHY, and presents
several different standardized functions in relation
to spatial data. The last part of the chapter explains
temporal data. It introduces temporal tables, which
are used to store temporal data, and explains some
special properties of temporal data.
• Chapter 31, “SQL Server Graph Databases,”
discusses all extensions in the Database Engine to
support graph data. It begins with a general
introduction to graphs and graph databases. After
that, it explains in detail the creation of node tables
and edge tables. The bulk of the chapter then
demonstrates how to query graph data, including
how to do so using relational queries, and how to
modify and edit data in graph databases.

Part VI, “Machine Learning,” is dedicated to native


support for the R and Python languages on SQL Server.
R and Python integration includes base open source

NEWOUTLOOK.IT
Technet24
||||||||||||||||||||
||||||||||||||||||||

distributions, plus Microsoft-specific libraries for high-


performance analytics. The following chapters are
included in this part:

• Chapter 32, “SQL Server Machine Learning


Services: R Support,” covers the integration of the
R language into the Database Engine. The first
major section introduces the R language, explains
generally how the R language is embedded in the
SQL Server system, and defines the concept of a
data frame in relation to R. The second major
section shows you how to visualize data using data
frames. The chapter wraps up with an exploration
of predictive modeling with R and presents an
example of solving linear regression problems with
R.
• Chapter 33, “SQL Server Machine Learning
Services: Python Support,” discusses the
integration of the Python language into the
Database Engine. The first part of the chapter
introduces the Python language and explains how
the language is embedded in the SQL Server
system. The second part shows you how to
visualize data using data frames. The final part
shows how predictive modeling with Python can be
done, using an example of solving linear regression
problems.

Almost all chapters include at their end numerous


exercises that you can use to improve your knowledge

NEWOUTLOOK.IT
||||||||||||||||||||
||||||||||||||||||||

concerning the chapter’s content. All solutions to the


given exercises can be found in the appendix of the book.

Changes from the Previous Edition


If you are familiar with the previous edition of this book,
Microsoft SQL Server 2016: A Beginner’s Guide, you
should be aware that I have made significant changes in
this edition. The following table gives you an outline of
significant structural changes in the book (minor
changes aren’t listed).
Note that Chapter 30, “SQL Server Full-Text Search,”
from the previous edition of this book has been omitted
in this edition. Also, the first part of Chapter 28
concerning XML has been omitted. First, the significance
of Full-Text Search has diminished in the last few years.
Second, there are two formats supported by SQL Server:
XML and JSON. From my point of view, JSON is the
format that is used to store and transport data. (All new
features in SQL Server 2017 and 2019 that need
transport of data from one source to the other are
implemented to use JSON, and not XML.)

NEWOUTLOOK.IT
Technet24
||||||||||||||||||||
||||||||||||||||||||

NEWOUTLOOK.IT
||||||||||||||||||||
||||||||||||||||||||

Differences Between SQL and


Transact-SQL Syntax
Transact-SQL, SQL Server’s relational database
language, has several nonstandardized properties that
generally are not known to people who are familiar with
SQL only:

• Whereas the semicolon (;) is used in SQL to


separate two SQL statements in a statement group
(and you will generally get an error message if you
do not include the semicolon), in Transact-SQL,
use of semicolons is strongly recommended but
can be omitted.
• Transact-SQL uses the GO statement. This
nonstandardized statement is generally used to
separate statement groups from each other,
whereas some Transact-SQL statements (such as
CREATE TABLE, CREATE INDEX, and so on)
must be the only statement in the group.
• The USE statement, which is used very often in this
book, changes the database context to the specified
database. For example, the statement USE sample
means that the statements that follow will be
executed in the context of the sample database.

Downloading and Working with the


Sample Databases

NEWOUTLOOK.IT
Technet24
||||||||||||||||||||

You might also like