LISTING 1:

<!--- This SQL code (for MS SQL Server 7.0) will create a trigger
that will return the automatically generated primary key (Employee_ID)
any time a new record is inserted into the Employees table --->

CREATE TRIGGER [GetEmp_PK] ON [Employees]
FOR INSERT
AS
SELECT Employee_ID FROM INSERTED

<!--- This is how you would use the above trigger in your CF code
Notice that you actually name the CFQUERY tag in this case,
which you normally would not do for an insert operation --->
<CFQUERY NAME="AddEmployee" DATASOURCE="DHPCFA_SQL">
   INSERT INTO Employees (FirstName, LastName)
   Values ('Bruce','Van Horn')
</CFQUERY>
<CFOUTPUT QUERY="AddEmployee">
Employee ID generated:  #AddEmployee.Employee_ID#
</CFOUTPUT>
 

LISTING 2:

<CFQUERY NAME="GetDist" DATASOURCE="FastTrack_Lab" BLOCKFACTOR="100">
   SELECT Distributor_ID, Distributor_Name, City, State_Region, Phone, Email
   FROM Distributor
   ORDER BY Distributor_Name
</CFQUERY>
 

LISTING 3:

<CFIF NOT IsDefined("Application.GetDist")>
  <CFLOCK SCOPE="Application" TIMEOUT="30" TYPE="Exclusive">
    <CFQUERY NAME="Application.GetDist" DATASOURCE="FastTrack_Lab" BLOCKFACTOR="100">
      SELECT Distributor_ID, Distributor_Name, City, State_Region, Phone, Email
      FROM Distributor
      ORDER BY Distributor_Name
    </CFQUERY>
  </CFLOCK>
</CFIF>
 

 LISTING 4:

 
<CFQUERY NAME="GetDist" DATASOURCE="FastTrack_Lab" BLOCKFACTOR="100" CACHEDWITHIN="#CreateTimeSpan(0,0,30,0)#">
  SELECT Distributor_ID, Distributor_Name, City, State_Region, Phone, Email
  FROM Distributor
  ORDER BY Distributor_Name
</CFQUERY>