Tag: SQL

SQL: Get Database Name From Physical Name

Here’s a SQL Function to get name of the database from it’s physical full name. This function can be used in conjunction with RESTORE FILELISTONLY which can generate physicalname,  the parameter of this function, from a database’s backup file. You can read more about RESTORE FILELISTONLY here. create function get_db_name_from_physical_name (@physicalname varchar(500)) returns varchar as […]

Read More

SQL: Save Result From RESTORE FILELISTONLY

RESTORE FILELISTONLY is a Transact Statement in MS-SQL that returns a result set containing a list of the database and log files contained in the backup set in SQL Server. Basically it contains meta-data pertaining to the database’s: LogicalName PhysicalName Type Size MaxSize etc. This information is quite useful when performing Restore operation. For example, […]

Read More

SQL Pivot with Dynamic Column Names

Found a great solution to writing a complex PIVOT function in SQL on the web! The solution was lying on a thread at one of the ASP.NET forums where the question was: “how to display row values in columns in sql server 2008“ and the solution was provided by M. Atif Nadeem from Pakistan. He […]

Read More

SQL: String Format Function

Here’s a handy SQL function that allows to insert string(s) inside a larger string. This function is similar to String.Format() function in C#. Typical Usage: Have a string like below: “%s is a. %s and %s does %s ” with as many ” %s ” as required to dynamically insert values. Insert desired string objects […]

Read More

Are you ready to work as a SQL Developer?

A SQL Developer is responsible for managing data in a relational database. Database Providers like Microsoft, Oracle and MySql have their own IDE for managing data. For example Microsoft has SQL Server Management Studio for this purpose and Oracle has Oracle Developer Studio. A SQL Developer makes use of these IDEs for managing data. Today […]

Read More

Connecting to SQL Server using RODBC package in R

RODBC is a useful package for making SQL queries to SQL Server database for R users. To start using this package, first we need to make sure it is loaded into R studio. is.installed <- function(mypkg) is.element(mypkg, installed.packages()[,1]) if(!is.installed(‘RODBC’)) { install.packages(“RODBC”) } library(RODBC) Now that the package is installed/loaded into our environment, let’s start making […]

Read More

Uploading Unknown Format Excel File To A SQL Database

Introduction Usually it is expected from client side to upload only structured Excel sheets (sheet with defined Column Names and data types for Rows) to load to server. But sometimes you might also require to dump whatever is in the Excel directly to your database. While there is a tool that is provided by SQL […]

Read More

7 Handy SQL Scripts for SQL Developers

Finally got my article published at Tuts+ I had written this article “7 Handy SQL Scripts for SQL Developers” referencing some of the common scripts that I most frequently use @ work. Some of these scripts were collected from different sites while some were developed by myself. ———————————————————————————— “A lot of things that we do […]

Read More

Running Scripts Larger than 200 MB size in MySQL

This is a workaround for running a script from a very large file that you want to use to create/modify your database in MySQL. After searching for possible workarounds, the easiest one that I found is to use a third-party tool called dbForge Studio for MySql.  “dbForge Studio is a universal MySQL GUI tool that enables […]

Read More

SQL Improving Query Performance

1.     Use Indexes. 2.     Use All instead of UNION, OUTER UNION, EXCEPT and INTERSECT when you know there are no duplicate rows or when you know it does not matter whether duplicate rows are returned. 3.     Omit the ORDER BY clause unless necessary. 4.     Inline VIEWS or Temporary Tables?       If the query […]

Read More