Transact-SQL – Introduction to the SQL Statements

In the topics that follow, you’ll learn about some of the SQL statements provided by SQL Server. As you’ll see, you can use some of these statements to manipulate the data in a database, and you can use others to work with database objects. Although you may not be able to code these statements after reading these topics, you should have a good idea of how they work. Then, you’ll be better prepared to learn the details of coding these statements when they’re presented in sections later section of this tutorial.

Figure 1-10 summarizes some of the most common SQL statements. As you can see, these statements can be divided into two categories. The statements that work with the data in a database are called the data manipulation language (DML). These four statements are the ones that application programmers use the most. You’ll see how these statements work later in this chapter, and you’ll learn the details of using them in a section later in this tutorial.

The statements that work with the objects in a database are called the data definition language (DDL). On large systems, these statements are used exclusively by database administrators, or DBAs. It’s the DBA’s job to maintain existing databases, tune them for faster performance, and create new databases. On smaller systems, though, the SQL programmer may also be the DBA. You’ll see examples of some of these statements in the next figure, and you’ll learn how to use them in chapter “How to create and maintain databases, tables, and sequences with SQL statements”.

SQL statements used to work with data (DML)

StatementDescription
SELECTRetrieves data from one or more tables.
INSERTAdds one or more new rows to a table.
UPDATEChanges one or more existing rows in a table.
DELETEDeletes one or more existing rows from a table.

SQL statements used to work with database objects (DDL)

StatementDescription
CREATE DATABASECreates a new database.
CREATE TABLECreates a new table in a database.
CREATE INDEXCreates a new index for a table.
ALTER TABLEChanges the structure of an existing table.
ALTER INDEXChanges the structure of an existing index.
DROP DATABASEDeletes an existing database.
DROP TABLEDeletes an existing table.
DROP INDEXDeletes an existing index

Figure 1-10 An introduction to the SQL statements

Description

  • The SQL statements can be divided into two categories: the data manipulation language (DML) that lets you work with the data in the database and the data definition language (DDL) that lets you work with the objects in the database.
  • SQL programmers typically work with the DML statements, while database administrators (DBAs) use the DDL statements.

Chapter: Introduction to Relational Databases & SQL