Posts

Showing posts with the label SQL

Heuristic Optimization of SQL Queries

Image
In general, relational algebra expressions and query trees could be equivalent; that is, they may correspond to the same query. But, the performance or cost of query may vary depending on the query technique that we apply. An optimization technique helps reduce the query execution time as well as the cost by re-formatting the query. We applied heuristic optimization in our queries and could reduce the execution time to a greater extent and thus reduced the cost quite a bit. Figure 1: Initial Query If we write this query in SQL we get: Select Name from E, J, P where E.EID=J.EID and PCode=Code and P.Name='GreenLife' and E.BDate>'31-12-1967' Which is basically the cross product of E, J and P Outline of a Heuristic Algebraic Optimization Algorithm: Break up any select operations with conjunctive conditions into a cascade of select operations. Move each select operation as far down the query tree as is permitted by the attributes involved in the select condition. Rearrang...

How to Create & Deploy Stored Procedure from C# [CLR 3.5]

Image
It was really tough to go back and forth between Visual Studio and SQL management Studio to create and reference back stored procedures. And, you have to have the SQL skill set to create SQL scripts at the Back End. But, it has become simpler now a days. Microsoft came up with a new project type to create SQL database projects right inside Visual Studio 2008. Follow the same .NET syntaxes while creating a Data Connection/Data Commands/Data Readers etc. I will briefly walk through the process: 1. Create a SQL Server Project in C# 2. Select the Database Reference 3. Add a Stored Procedure Class 4. Write the Stored Procedure Like This: using System; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using Microsoft.SqlServer.Server; public partial class StoredProcedures { [Microsoft.SqlServer.Server.SqlProcedure] public static void MySP1(string _UNID) { try { SqlConnection conn = new SqlConnection(); conn.Connect...