Selecting Data – Part 1

The SELECT reservered word is part of the Data Manipulation Language (DML) defined by Codd and is used to query data from the database as recordsets. Because of its popularity, there are many clauses and functions that can be used to construct a query to retrieve data. All reserved words that I introduce below will be in CAPS below. Today, I would like to review simple SELECT queries using the AdventureWorks Sample database supplied by Microsoft. The most basic use of the SELECT statement is to return a constant as…

Managing Files

The most basic storage unit of any operating system is a file. Files can contain anything from textual data in this article, a bitmap image of your baby daughter, a MS Excel worksheet containing your finances or a Visual Basic program you are currently working on. Therefore it is very important to know how to manipulate files after they are created. Common actions that are performed on files are copy, rename, move and delete. Each file has properties such as creation date, last date modified, and attributes such as read…

Output Clause

The OUTPUT clause was introduce with the release of SQL Server 2005. This clause returns information from, or expressions based on, each row affected by an INSERT, UPDATE, or DELETE statement. These results can be inserted into a table or variable to implement business requirements such as confirmation messages, archiving, and atomic transactions. Today, I would like to use the AdventureWorks Sample database as the basis of our discussion. The first example creates a new Country By Continent table to store all the countries in South America. The OUTPUT clause…

Deleting Data

The DELETE reservered word is part of the Data Manipulation Language (DML) defined by Codd and is used to remove existing data in one table in the database. Today, I would like to review the different ways to remove data using the AdventureWorks Sample database supplied by Microsoft. Each example has a SELECT statement to identify the number of rows affected before executing the DELETE. 1 – One way to purge data from a table is to use the DELETE statement without a where clause. Only use this syntax when…

Updating Data

The UPDATE reservered word is part of the Data Manipulation Language (DML) defined by Codd and is used to modify existing row data in one table in the database. Today, I would like to review the different ways to update data using the Adventure Works Sample database supplied by Microsoft. Each example has a SELECT statement to identify the number of rows affected before executing the UPDATE. 1 – The simplest form of the UPDATE statement modifies one column in a given table filtered by one where clause. The following…

Inserting Data

The INSERT reservered word is part of the Data Manipulation Language (DML) defined by Codd in 1970 and is used to add data to a table in the database. Today, I would like to review the different ways to insert data using the AdventureWorks Sample database supplied by Microsoft. 1 – Many times a table is defined with a surrogate key, an autoincrement column. You can specify values for this column by setting the INDENTITY INSERT property of the table. The following code adds a row to the Human Resources…