...now browsing by category


Guest Lecture @ RMIT School of Business

Sunday, December 13th, 2009

I did a Guest Lecture on how we use RDBMS (SQL Server) at my work. It was aimed at first year undergrads who are doing an introduction to Relational Databases (RBDMS). I had some great time in preparing the presentation slides and delivering the content. The students were quite good and were keen to understand how databases are used in Industry. My whole lecture was focused on how we do a new database project at work right from inception phase, design phase to finally incorporating it into the whole project.

The best part is they loved the fact that we use a White-board to do all our design and planning work, which we later capture by taking photos. With the new TeamBoard system that we got recently it’s got even more fun. đŸ™‚

I concluded at the end of the lecture that all the social networks that they interact with all have massive databases behind the scenes. So in future when they are involved in designing databases, depending on the project, they can use their extensive end user experience and think of the various information that they will need to store in the database.

Written by Deepak Vasa - Visit Website

Using the field name alias in SQL Where clause

Tuesday, March 17th, 2009

Often I encounter SQL queries where I would love to use the alias names of my columns in the WHERE clause, today while trawling around the web I found a cool and easy way to do it. Here’s an example:

WITH Customer_Info AS
SELECT (Surname + ‘, ‘ + Firstname) AS FullName,
(Address_Line_1 + ‘,’ + Address_Line_2) AS Customer_Address
FROM Customers
SELECT FullName, Customer_Address
FROM Customer_Info
WHERE FullName LIKE ‘Smith%’

Written by Deepak Vasa - Visit Website

Query to get the column names/types for all tables in SQL 2005

Wednesday, February 11th, 2009

SELECT schemas.name AS [Schema],
tables.name AS [Table],
columns.name AS [Column],
WHEN columns.system_type_id = 34 THEN ‘byte[]’
WHEN columns.system_type_id = 35 THEN ‘string’
WHEN columns.system_type_id = 36 THEN ‘System.Guid’
WHEN columns.system_type_id = 48 THEN ‘byte’
WHEN columns.system_type_id = 52 THEN ‘short’
WHEN columns.system_type_id = 56 THEN ‘int’
WHEN columns.system_type_id = 58 THEN ‘System.DateTime’
WHEN columns.system_type_id = 59 THEN ‘float’
WHEN columns.system_type_id = 60 THEN ‘decimal’
WHEN columns.system_type_id = 61 THEN ‘System.DateTime’
WHEN columns.system_type_id = 62 THEN ‘double’
WHEN columns.system_type_id = 98 THEN ‘object’
WHEN columns.system_type_id = 99 THEN ‘string’
WHEN columns.system_type_id = 104 THEN ‘bool’
WHEN columns.system_type_id = 106 THEN ‘decimal’
WHEN columns.system_type_id = 108 THEN ‘decimal’
WHEN columns.system_type_id = 122 THEN ‘decimal’
WHEN columns.system_type_id = 127 THEN ‘long’
WHEN columns.system_type_id = 165 THEN ‘byte[]’
WHEN columns.system_type_id = 167 THEN ‘string’
WHEN columns.system_type_id = 173 THEN ‘byte[]’
WHEN columns.system_type_id = 175 THEN ‘string’
WHEN columns.system_type_id = 189 THEN ‘long’
WHEN columns.system_type_id = 231 THEN ‘string’
WHEN columns.system_type_id = 239 THEN ‘string’
WHEN columns.system_type_id = 241 THEN ‘string’
WHEN columns.system_type_id = 241 THEN ‘string’
END AS [Type],
columns.is_nullable AS [Nullable]

FROM sys.tables tables
INNER JOIN sys.schemas schemas ON (tables.schema_id = schemas.schema_id )
INNER JOIN sys.columns columns ON (columns.object_id = tables.object_id)

WHERE tables.name <> ‘sysdiagrams’
AND tables.name <> ‘dtproperties’

ORDER BY [Schema], [Table], [Column], [Type]

Written by Deepak Vasa - Visit Website

LINQ query to get all the column names in the DBML tables

Friday, October 31st, 2008

// LINQ query to get all the column names for every Table
var model = new AttributeMappingSource().GetModel(typeof(ReportDBMLClassesDataContext));
int i = 0;
ArrayList lblList = new ArrayList();
foreach (var mt in model.GetTables())
Label lbl = new Label();
lbl.Text = mt.TableName.ToString();
lbl.ID = “lbl” + i;
Panel1.Controls.Add(new LiteralControl(“<br>”));
int r = 0;
foreach (var dm in mt.RowType.DataMembers)
Label rlbl = new Label();
rlbl.Text = dm.MappedName.ToString();
rlbl.ID = “rlbl” + i + “” + r;
Panel1.Controls.Add(new LiteralControl(“<br>”));

Written by Deepak Vasa - Visit Website

SQL Server 2008 – my thoughts….

Tuesday, August 12th, 2008

I have been reading about SQL Server 2008 for a while and today I got a glimpse of the various features and how it can help developers at the Victoria Dot Net users group meeting. Thanks to the special presentation by Chris Hewitt – “What should developers know about SQL Server 2008?”

A few days ago, I read about the new “File Stream” data type and my initial thoughts were how would I use this new feature and where would this be more usefull, later I realised that I could use the FileStreaming data type to store all the various CSV reports that I generate from our various applications. So effectively instead of storing it on a file server and putting in the reference in SQL, I could easily store the entire CSV file in to SQL Server and let it worry about where and how it stores it. More over I can also have all the report metadata in one location (sweet :).

In the presentation Chris showed us a few examples on how we can send a Table as parameter to Stored Procedures and the new Merge Statement.  Well, frankly speaking it took me a few seconds to comprehend the huge benifits of sending in a table as a parameter to a stored procedure. The biggest benifit is the ability to insert large number of rows in one go by passing the data as a table parameter. Previously you could do that with temp tables but those tables were only specific to the stored procedure which creates them, however with this new feature we have some thing on the lines of Global Temp Tables. For more detailed explanation and examples, please refer this article

Coming to the Merge statement that’s another cool feature that has huge number of benefits. In scenarios where you need to to insert, update, or delete data based on certain conditions, programmers have to take care of the actions in the application, however with Merge statements we can do the insert, update or delete in one single statement based on the join conditions. For more information, please refer this article at BuilderAU.

Another cool feature is the Filtered Indexing. As the name suggests, all it means is that when we create Indexes for a table in SQL Server 2008 based on a particular criteria (simple where clause). I am very keen to test this on one our biggest tables (9 million rows and counting). At the moment  it takes quite a bit of time to query this table for certain criteria, I would love to do some bench marking on this table and see how efficient the Filtered Indexes are.

Finally a one more interesting feature is the ability to Debug Sql Statements in the same way as .NET code. Chris showed how we could debug any SQL statement or Stored procedure, and also the MS has finally introduced Intellisense for SQL statements. Allthough I have been told that 3rd party tools have been providing SQL intellisense for quite some time now.

For those of you who are interested in other features like Sparse, new DateTime formats, new Convert functionality etc, please refer SQL Server 2008 @ Microsoft.

Written by Deepak Vasa - Visit Website