0% found this document useful (0 votes)
83 views8 pages

T SQL

T-SQL is the primary language used to extract or modify data stored in a SQL Server database. It consists of several components like DDL, DML, DCL, and TCL. While based on ANSI standards, Microsoft has added additional functionality. SQL Server is typically accessed using tools like SQL Server Management Studio or the newer Azure Data Studio, though ADS is missing some administration features. A SQL Server instance contains the files, settings, and services to run SQL Server, and multiple instances can run on a single machine with separate databases.

Uploaded by

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

T SQL

T-SQL is the primary language used to extract or modify data stored in a SQL Server database. It consists of several components like DDL, DML, DCL, and TCL. While based on ANSI standards, Microsoft has added additional functionality. SQL Server is typically accessed using tools like SQL Server Management Studio or the newer Azure Data Studio, though ADS is missing some administration features. A SQL Server instance contains the files, settings, and services to run SQL Server, and multiple instances can run on a single machine with separate databases.

Uploaded by

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

T-SQL is the language that is most often used to extract or modify data stored in a

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.

Installing SQL Server Developer Edition


You may hear someone refer to “instances” of SQL Server. An instance of SQL Server consists of all
the files, settings, and services required to run SQL Server.
You can have more than one instance of SQL Server running on one machine, and each instance has
its own databases.
On the Server Configuration screen, you can assign Windows accounts to the services needed by SQL
Server. In this learning environment, just accept the defaults, but this is one of those areas
where a database administrator would set up special accounts for a production SQL Server.

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.

the documentation can be found at https://docs.microsoft.com/en-us/sql/sql-server/?view=sql-server-


ver15

Look for the AdventureWorks OLTP full database backup (AdventureWorks2019.bak)


file on this page: https://github.com/Microsoft/sql-server-samples/releases/tag/adventureworks. Look
for the WideWorldImporters OLTP full database backup (WideWorldImporters-Full.bak) file here:
https://github.com/Microsoft/sqlserver-samples/releases/tag/wide-world-importers-v1.0.

Installing Tools for SQL Server


Page 1 of 8
For over 15 years, database professionals have used SQL Server Management Studio (SSMS) when
administering SQL Server and writing queries. More recently, Microsoft introduced Azure Data
Studio (ADS), a tool that can be used on Linux and macOS as well as Windows.

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.

Using Azure Data Studio


Azure Data Studio (ADS) is the latest tool from Microsoft for working with SQL Server.
Those of you who are developers will probably recognize that it is based on Visual Studio Code.

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.

Keep these things in mind about ADS:


• Right-click the server or database and select New Query to open a blank query window.

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.

SQL Notebooks, that is based on Jupyter Notebooks.


The Notebooks found in ADS support Python, R, Scala, and PowerShell in addition to SQL.

Opening a SQL Notebook


To get started, open ADS and connect to your SQL Server instance as shown in
Figure C-1.

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.

Adding Code to the Notebook

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.

Adding a Text Cell


One of the reasons that notebooks are so popular is that you can include text and
images along with the code and results.
To add a text cell, click into a cell and then click the + icon and select Text cell. Figure C-6 shows the
cell.

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.

What Is SQL Server?


SQL Server is Microsoft’s relational database management system (RDBMS).

An RDBMS stores data in tables according to the relational model.

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.

Regardless of your application architecture, at some point, you’ll use T-SQL.


SQL Server does have a very nice reporting tool called Reporting Services that is part of the business
intelligence suite.
Otherwise, you will have to use another programming language to
create your user interface outside of the management tools.

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

You might also like