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)
|SELECT||Retrieves data from one or more tables.|
|INSERT||Adds one or more new rows to a table.|
|UPDATE||Changes one or more existing rows in a table.|
|DELETE||Deletes one or more existing rows from a table.|
SQL statements used to work with database objects (DDL)
|CREATE DATABASE||Creates a new database.|
|CREATE TABLE||Creates a new table in a database.|
|CREATE INDEX||Creates a new index for a table.|
|ALTER TABLE||Changes the structure of an existing table.|
|ALTER INDEX||Changes the structure of an existing index.|
|DROP DATABASE||Deletes an existing database.|
|DROP TABLE||Deletes an existing table.|
|DROP INDEX||Deletes an existing index|
Figure 1-10 An introduction to the SQL statements
- 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.