Search posterous

Search all posts and users. Type a name, type a favorite song title, whatever! See what comes up.
  

More posterous blogs











More recommended blogs »

Here are posterous posts filed under sqlserver...

Currently, I'm working on a large application that involves a Flex UI backed by ColdFusion 8 and SQL Server 2008. The ColdFusion code consists of a large base of CFCs that run many queries (via cfquery) for all database interaction/communication (CRUD, advanced searchers, etc.). The CFCs are invoked as Remote Objects from the Flex UI. In most cases, the CFCs return large arrays of objects for Flex to use in the UI. 

Since ColdFusion 8 is particularly slow at object instantiation, my concerns about the application's performance under load are great. While getting acquainted with the existing code base and project, I was tasked to create a routine that enabled an application user to rate objects in the UI and compute an aggregate ranking for these objects based on rankings from all application users. As I worked through what steps I needed to take to accomplish this, I realized that a triggers was just what I needed (it helped that I was scanning a SQL Server book at the time!). 

It turns out that triggers are not difficult to write and implement and, ultimately, can really help boost ColdFusion's performance in the right situations. Thus, this exciting blog entry :). 

Triggers
Many already know this but, since I didn't fully 'get' triggers, I thought a brief introduction or definition would be good. Triggers are routines that run once a specified event occurs in the database. They're great for enforcing referential integrity (i.e., ensuring you don't delete a row from a table without also deleting related foreign key entries) and minimizing work on the application server by running a range of tasks in the DB itself; rather than your web application server. 

There are a two main types of triggers in SQL Server (AFTER and INSTEAD OF) but, thus far, I've only gotten into the standard trigger (AFTER). Essentially, an AFTER trigger is an event listener that, when fired, tells SQL Server to run the compiled code of your trigger. 

But when does it fire? Well, you get to tell it when to fire. Typically, an AFTER trigger is fired immediately following a successful insert, update or delete on the watched table 

The Problem
As I mentioned above, the current application on which I'm working has a feature that enables application users to rank objects from 0 to 10. The ranking is handled in the UI (quite nicely -- we have awesome designers and interactive folks) and, when the user has finished, s/he saves their rankings and the data is submitted to a ColdFusion via a remote object in Flex. 

Where it gets 'tricky' is that with each set of rankings saved, we need to immediately update our aggregated ranking data and return those to the UI.

If I were to do this in ColdFusion alone (using CFC methods with CFQUERY tags), the workflow might be something along the lines of the following:
  • Save the object's rankings/ratings to the database
  • Grab all previous (plus the current) rankings for the current object
  • Insert the updated aggregated ranking data in the database
  • Query the database for the aggregated rankings for all objects and return to the UI
Even though this isn't a complex, uncommon, or intensive operation, it still takes up to 4 database queries. 

The Solution
My solution incorporated a stored procedure and the trigger and only 1 step for ColdFusion. Here's the flow as far as ColdFusion is concerned:
  • Save the object rankings/ratings to the database (CFC method invokes a stored procedure on the DB server) 
  • Stored procedure inserts, updates, or deletes some ranking data and my trigger is then fired
  • Aggregated rankings for all objects returned from the stored procedure and are then sent back to the UI
The Trigger
Below, the trigger I created is listening for a product_sales table to be affected in some manner (insert, update, or delete). When one of these events occur, I need to update the aggregate rank for the product that was just sold. 

Our aggregate rank is calculated quite simply: add the total customer rankings for a product and divide by the number of times it has been ranked. Once calculated, we need to update another table that holds the aggregate product rankings

*Note: I had to alter my actual trigger, so the tables referenced in the example were just pulled together for the example itself (and not intended to represent an ideal or good DB design). 

Following is the T-SQL for the trigger:
 CREATE TRIGGER tr_my_trigger  ON  [dbo].[product_sales]
 -- we're listening for any changes to the table noted above 
 AFTER INSERT,UPDATE
 AS 
 BEGIN
 -- Insert statements for trigger here
 declare @prodid nvarchar(50), @aggregate_ranking numeric(18,0)
 select @prodid = prod_id from inserted
 select @aggregate_ranking = (sum(rank) / count(prod_id)) from product_customer_rankings where prod_id = @prodid
 
 update product_ranks
 set aggregate_ranking = @aggregate_ranking
 where prod_id = @prodid
 END
 

First, we declare a trigger on the table we want to watch. We specifically created an 'AFTER' trigger for an INSERT or UPDATE event occurs on the product_sales table.

Second, we declare two local variables that the trigger needs (@prodid and @aggregate_ranking). 

Third, we set the value for our first local variable, @prodid. I think this is where the trigger gets cool. 

In order to successfully update the aggregated ranking data, we need to get the id of the product that was just sold. Notice the line "select @prod_id = prod_id from inserted". 

We can access the modified data from a special table called 'inserted' (if your routine did a delete, you would select from 'deleted' and not inserted). So, this table holds the details of the product that was just sold and whose sales data was added to the product_sales table milliseconds earlier. With that simple select statement, I now have the product id I need to do my real work.

Fourth, we set the value for our second local variable, @aggregate_ranking. The value of @aggregate_ranking is set to the result of the SQL statement that follows (using our local @prodid variable to get the right data).

Finally, we update the aggregate ranking for this product in the product ranks table. 

Perhaps I'm overly excited about what potential this holds ... I've (clearly) only scratched the surface of what you can do with triggers to keep some of the workload away from your application server (be it ColdFusion, .NET, PHP, whatever) but the possibilities seem vast.

Filed under: SQL Server

John says...

via tweetie

Filed under: SQL Server

Article By Paul Mah at FierceCIO TechWatch 

Microsoft will be going on a mega security update spree next Tuesday, with 13 security bulletins all lined up. What is significant about this update is that a large percentage--eight of them--were rated as "critical," as well as the sheer number of bulletins.

To understand the significance here, the 13 bulletins for next week's Patch Tuesday will trump previous records achieved in February 2007, and again in October 2008. According to reports, the upcoming update is inclusive of two previously known critical Windows bulletins--including a serious flaw in Microsoft's Server Message Block (SMB) protocol. An older problem with the FTP service in Microsoft IIS will also be rectified.

A total of 34 vulnerabilities will be addressed in all, for products such as Microsoft Windows, Internet Explorer, Office, and SQL Server, among others.

One point to note for security administrators and IT managers for the upcoming Patch Tuesday will be the need to perform a restart, an important fact to know where servers are concerned. In a blog entry, Jerry Bryant of the Microsoft Security Response Center team wrote, "Most of these updates require a restart so please factor that into your deployment planning."

Filed under: SQL Server

eduso says...

Despues de haber realizado esta presentación de manera presencial, la repetiremos en formato Webcasts para quienes no pudieron asistir por alguna razón.

Este webcast va orientado a entender las capacidades y funcionalidades provistas por la extensión SQL Server Driver for PHP para mejorar la experiencia de conexion entre PHP y Microsoft SQL Server

Este webcast se llevará a cabo el martes 8 de Septiembre de 2009 a las 3:00pm (hora de Venezuela). Para registrarse al webcast: http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032425123&Culture=es-AR

Nos vemos en el webcast :)

Filed under: SQL Server

v-edsojo says...

Hola, les dejo publicado acá la presentación que estuve dando en esta actividad y los demos que trabajamos. El martes 8 de septiembre de 2009 se estará llevando a cabo un webcast donde se tocará este tema para aquellas personas que no pudieron asistir a esta presentación, puedes registrarte para el webcast haciendo clic AQUI.

Click here to download:
demos.zip (1 KB)

Saludos,

 

Filed under: SQL Server

Hi Toby - try this:
 
SELECT COUNT (city)
FROM contact1
WHERE key3 IS NOT NULL
 
Hope this helps - text us if you need further assistance. 

~ Support Team ~

Filed under: SQL Server

v-edsojo says...

Tengo el honor de invitarlos al Workshop de interoperabilidad “Escenarios reales de interoperabilidad: Usando SQL Server en aplicaciones PHP”. Este evento tiene como finalidad mostrar las capacidades de uso del manejador de bases de datos SQL Server 2008 desde aplicaciones desarrolladas con PHP, ampliando las posibilidades de manejo de repositorios de datos desde esta tecnología de desarrollo web.

Este evento es gratuito y puedes participar usando la siguiente información:

Fecha: Martes 1 de Septiembre de 2009

Hora: 6:30 p.m. – 9:00 p.m.

Lugar: Microsoft Venezuela

Dirección: Av. Principal de la Castellana Centro Letonia, torre ING Bank, Piso 10, Caracas.

Los espero.

Saludos,

Filed under: SQL Server

Eddie says...

  • The industry standard for databases is Oracle. Therefore, SQL Server is probably not the right choice for those who have the right stuff
  • Oracle is not any more expensive than Microsoft SQL Server. Therefore, Microsoft’s cost pitch is not exactly accurate.
  • Oracle scales. SQL Server scales but it is more work, more expensive, etc. Therefore, for big jobs, use Oracle.
  • Filed under: sql server

    用力呼吸 says...

    SQL Dumper 提供了 Table / View / T-SQL 的資料倒出.
    讓你可以輕鬆把資料倒出成 .sql
    轉成SQL執行碼.

    當然, 這個功能跟SSMS (SQL Server Management Studio)"匯出資料"的精神是一樣的.
    只不過匯入匯出精靈在執行效能上比較龜(預掃瞄相當耗時)

    如果只是簡單的要快速倒出某些資料, SQL Dumper倒是不錯的輕巧小工具!
    下載: http://www.ruizata.com/

    ps. 當然拉, 這個工具在SQL神人面前只是班門弄斧, 兩三條cmd就能解決這個需要.

    Filed under: SQLServer

    easy2die says...

    The installation of SSMSE uses the same installer used for the full SQL Server 2008 product. To kick things off, you will want to:

    1. Follow the prerequisite downloads noted on the Download page for for Microsoft .Net Framework 3.5 SP1, Windows Installer 4.5, and Windows PowerShell 1.0
    2. Go to the Installation page in the SQL Server Installation Center. Then, click on the top link for “New SQL Server stand-alone installation or add features to an existing installation”.
    3. Click OK for the Setup Support Rules dialog.
    4. Choose to Install for the Setup Support Files.
    5. If you did step 1 ok, you will go into the full setup wizard where you will check Next for the “Setup Support Rules” step.
    6. For the Installation Type page, if you happen to have an instance of the SQL Server 2008 engine installed, don’t select to add features to it. Instead, select “Perform a new installation of SQL Server 2008” and click next.
    7. Click next for the Product Key page.
    8. Read the license terms, check that you accept the terms and then Next.
    9. For the Feature Selection page – click ON the check box for “Management Tools – Basic” and click Next.
    10. Click Next for the Disk Space Requirements if all checks out.
    11. Click Next for Error and Usage Reporting.
    12. If all goes well – click Next for Installation Rules.
    13. Then, click Install for the Ready to Install page.
    14. Complete the wizard and life is good.

    Filed under: SQL Server