Category: Database Systems

Virtualization in Cloud Computing

What is Virtualization? A virtual machine is an isolated runtime environment which consists from a guest operating system and applications. Virtualization enables a single computing system to look like many computers where multiple virtual machines can run on a single physical machine. The size and power of individual virtual machines is variable and configurable. Each

Perl DBI Connect Example

Here is a sample code snippet to connect and access an informix database using Perl DBI #!/usr/bin/perl # DBI moduleuse DBI ; # Database handler$dbh = DBI->connect("DBI:Informix:$db_name"); # Statement handler$sth = $dbh->prepare("$sql"); # Execute statement$sth->execute(); # For each row in the tablewhile (@row = $sth->fetchrow_array()){ # Push the row into the output table push(@table, [@row]);} # Finish statement$sth->finish(); # Disconnect from database$dbh->disconnect(); #

Select Latest Data from Table

Problem Given the following database table: DATA (id, data_date, data_value). The id field is not unique. Write an SQL statement to select the latest value for each id Solution Group rows by id then select rows with maximum date Code Here is the code Select id, max(data_date) data_date, data_value from DATA group by id

How to Find Duplicates in a Table using SQL

Problem Write an SQL statement to find rows with duplicate column values in a database table Solution You need to group by the column containing the duplicate values then select only the groups with count greater than 1 Code Here is the code in SQL Select field, count(field) from table group by field having count(field)

Delete Table vs Truncate Table

Question What is the difference between delete table and truncate table operation Answer Delete table operation deletes all rows in the table. The deletion of rows is logged in the transaction log. On the other hand truncate table operation similarly deletes all rows in the table but it does not log the deletion of rows

Sql Query Optimization

Question Suggest few areas to inspect to improve the performance of a slow query Answer Here are few areas to check: Tables have no indexes. Database indexes improve query performance dramatically on the expense of slow writes and extra space Tables are scanned in full. Scanning huge tables degrades performance Table statistics are not updated.

Creating Indexes on Multiple Columns

Question What happens if you create an index on each column of a database table Answer Query optimizer can choose from all existing indexes and come up with an efficient execution plan which in turn improves performance. On the other hand data modification operations such as insert, update and delete will become slow because indexes

Clustered vs Nonclustered Index

Question What is the difference between clustered and non clustered database index Answer A database index is a special data structure (tree, hash, etc) that improves the performance of data retrieval. There is nothing free so the performance gain comes with slower writes and increased storage space. Database index architecture can be classified into clustered

Where vs Having SQL

Question What is the difference between WHERE and HAVING clauses. Answer The WHERE clause restricts which rows are returned while the HAVING clause operates on groups of rows. HAVING is always used with GROUP BY and must have a function it restricts. The rule says if a condition refers to an aggregate function put that

Sql Views Advantages

Question What is a database view. Mention few database sql views advantages Answer A view is a virtual table (not part of the physical schema) composed from the result set of a stored query. Views contain dynamic content. This means if you modify the physical tables from which the view is constructed then the data shown in subsequent invocations of the