SQL Server 2005: SELECT, INSERT, UPDATE, DELETE

The parts of a SELECT statement are:

SELECT 
FROM 
WHERE 
GROUP BY 
HAVING 
ORDER BY 
FOR XML
OPTION

By default, ALL is assumed in SELECT, thus including every row.  Using SELECT DISTINCT excludes duplicate rows.  Note that you can also use DISTINCT in aggregate functions, like below:

SELECT COUNT (DISTINCT Column)
FROM Table

You can use ORDER BY on any column on the table even if it is not returned or not part of the SELECT list.  The FOR XML clause is used for outputting XML data while the OPTION clause is for making query hints.

 

The INSERT statement can take either of the two following forms:

INSERT INTO Table (Column1, Column2)
VALUES (Value1, Value2)

INSERT INTO Table (Column1, Column2)
SELECT ...

Note that the column list are optional on both forms.

 

The parts of an UPDATE statement are:

UPDATE
SET
FROM
WHERE

An UPDATE can be created from multiple tables but only one table is affected, meaning only one table can be the subject of an update action.

 

The DELETE statement has the shortest syntax.  Just provide the table name and optionally a WHERE clause.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s