CRUD Statements  «Prev  Next»
Lesson 7 Punctuation
Objective Describe how to use punctuation in your statements.

SQL Server Statement Punctuation

When using literal values with your queries, you will receive fewer errors if you adhere to SQL Server’s punctuation rules.

Quotations

SQL Server requires quotation marks with some datatypes, but not for others. The Slideshow below shows examples of both kinds of datatypes.


Issue Insert Information

Apostrophes

You may be wondering what happens if your character string contains an apostrophe, which is also a single quote. Does this throw off SQL Server? The answer is yes.
Any literal value that contains an apostrophe must have another apostrophe directly next to it. For example, this Transact-SQL statement will fail:

INSERT INTO Employees(FirstName, LastName, Salary)  
VALUES ('Johnny','D'Angelo', 20000)
The above statement attempts to 'D'Angelo' into the LastName column of the Employees table. However, this makes a total of five single quotes in the Transact-SQL statement. Therefore, SQL Server does not know how to parse the Transact-SQL statement into distinct values and an error results. The correct Transact-SQL statement is the following:

INSERT INTO Employees(FirstName, LastName, Salary)  
VALUES ('Johnny','D''Angelo', 20000)
Simply adding another apostrophe after the first one makes the syntax correct.
In the next lesson, you will learn how to insert data using values from another table.