Sdílet prostřednictvím


Tutorial: Writing Transact-SQL Statements

Welcome to the Writing Transact-SQL Statements tutorial. This tutorial is intended for users who are new to writing SQL statements. It will help new users get started by reviewing some basic statements for creating tables and inserting data. This tutorial uses Transact-SQL, the Microsoft implementation of the SQL standard. This tutorial is intended as a brief introduction to the Transact-SQL language and not as a replacement for a Transact-SQL class. The statements in this tutorial are intentionally simple, and are not meant to represent the complexity found in a typical production database.

Note

Novice users of databases will usually find it easier to work with SQL Server by using SQL Server Management Studio, instead of writing Transact-SQL statements.

Finding More Information

To find more information about any specific statement, either search for the statement by name in SQL Server Books Online, or use the Contents to browse the 1,800 language elements listed alphabetically under Transact-SQL Reference (Database Engine). Another good strategy for finding information is to search for key words that are related to the subject matter you are interested in. For example, if you want to know how to return a part of a date (such as the month), search the index for dates [SQL Server], and then select dateparts. This takes you to the topic DATEPART (Transact-SQL). As another example, to find out how to work with strings, search for string functions. This takes you to the topic String Functions (Transact-SQL).

What You Will Learn

This tutorial shows you how to create a database, create a table in the database, insert data into the table, update the data, read the data, delete the data, and then delete the table. You will create views and stored procedures and configure a user to the database and the data.

This tutorial is divided into three lessons:

Requirements

To complete this tutorial, you do not have to know the SQL language, but you should understand basic database concepts such as tables. During this tutorial, you will create a database and create a Windows user. These tasks require a high level of permissions; therefore, you should log in to the computer as an administrator.

Your system must have the following installed:

  • Any edition of SQL Server.

  • Either SQL Server Management Studio or Management Studio Express.

  • Internet Explorer 6 or later.

Note

When you review the tutorials, we recommend that you add the Next and Previous buttons to the document viewer toolbar.