T SQL
T SQL
SQL Server database, regardless of which application or tool you use. SQL Server 2019
T-SQL is based on standards created by the American National Standards Institute
(ANSI), but Microsoft has added several functionality enhancements.
T-SQL consists of
Data Definition Language (DDL),
Data Manipulation Language (DML),
Data Control Language (DCL),
Transaction Control Language (TCL), and
control-of-flow statements.
Alte prescurtari:
Azure Data Studio (ADS)
SQL Server Management Studio (SSMS)
but ADS is the new kid on the block which runs on Linux and macOS, not just on Windows. ADS is
missing some of the functionality, especially for database administration that SSMS has, but
Microsoft adds new features to ADS frequently.
Windows authentication mode means that you can connect to the SQL Server instance with your
Windows account without supplying a password.
You should also click “Add Current User” to set up your account as an administrator in your SQL
Server instance.
Microsoft makes updates available on a regular basis for supported versions of SQL Server. Earlier
versions received Service Packs (SPs) and Cumulative Updates (CUs). The SPs were large updates
that contained bug fixes and security updates and sometimes contained new features. CUs were small
incremental updates. Microsoft has since gone to a CU-only update strategy for new versions of SQL
Server.
ADS is especially useful for writing queries, and, despite the name, the database does not need to be
hosted in Azure, Microsoft’s cloud platform.
To get started, you will need to learn how to connect to your instance. The pattern is ComputerName\
InstanceName.
If your SQL Server is running on your own local computer, you can refer to it by its name or replace
the name with localhost, (local), or a period (.).
Note If you installed SQL Server in a container, refer to Appendix A to learn how to
connect to it. If you are using a SQL Server supplied by your organization, check with
the administrator on how to connect.
Page 2 of 8
• You can save your work from each query window as a SQL file.
• Run queries by pressing F5 or clicking the Run button.
• Change to a different database from the drop-down box above the query.
• If a query window has multiple statements, you can highlight and run just the text you want to
run instead of the entire script.
When you open ADS later, the connection will be saved for you. Just double-click the server
name to connect again.
Azure Data Studio also has an interesting feature called SQL Notebooks.
There are several ways to open a new notebook. You can right-click your instance and select New
Notebook or click New Notebook on the server manager view shown in Figure C-2.
Once you have the notebook created, make sure that the Kernel is set to SQL and it’s connected to
your SQL Server instance.
Page 3 of 8
To add a code section to the notebook, just click the + Cell button. Now you can type in T-SQL code
just as if you had a query window open instead. You even get IntelliSense to help you write it as
shown in Figure C-4.
To run the query, click the arrow. Note that you will run the entire cell even if you have some of
the code selected. To add another cell after the current one, click the + icon and select Code cell as
shown in Figure C-5.
The connection to the database is set to the default which is probably the master database and not
AdventureWorks2019. In this case, I added a USE statement, but you can also create a separate
connection that points to the database you intend to use.
Note that you have several built-in formatting options such as lists and bolding, but
you can also use markdown language (see www.markdownguide.org) for headings.
Figure C-7 shows two headings.
Page 4 of 8
Organizing Your Notebooks
If you save all your notebook files in the same folder, you can take advantage of the Notebooks pane
shown in Figure C-9.
Page 5 of 8
CHAPTER 2
Exploring Database Concepts
You will learn how data is stored in a database, and you’ll learn about objects, called indexes.
The relational model is beyond the scope of this book, but you can learn more about it by reading Pro
SQL Server Relational Database Design and Implementation: Best Practices for Scalability and
Performance by Louis Davidson (Apress 2020).
Express Edition can be distributed with applications, but it has many limitations such as the size of the
database allowed and performance. Developer Edition is full-featured and may be used for learning or
development work only.
Full-featured editions (Standard and Enterprise Editions) are used to store terabytes
of data in the most demanding enterprises.
Page 6 of 8
Service vs. Application
SQL Server is a service, not just an application.
SQL Server is feature rich, providing a complete business intelligence suite, impressive management
tools, sophisticated data replication features, and much more.
These features are well beyond the scope of this book, but I invite you to visit www.apress.com to
find books to help you learn about these other topics if you are interested.
SQL Server doesn’t come with a data-entry interface for regular users or even a
way to create a website or a Windows application. To do that, you will most likely use
a programming language such as C# or Java.
Calls to the SQL Server via T-SQL can be made within your application code or through a middle tier
such as a web service.
Database as Container
A database in SQL Server is basically a container that holds several types of objects and
data in an organized fashion.
For example, some systems, typically called ERP (enterprise resource planning) systems, have one
database for all the enterprise applications required to run a business. On the other hand, one
application could access more than one database.
Page 7 of 8
SQL SERVER FILES
Page 8 of 8