Menampilkan postingan dengan label SQLTunjukkan semua

A Better way to write SQL queries

Writing code is art and same applies to SQL queries. The way you structure your query, the way you write it goes a long way to communicate …


Running SQL Queries on Production/live Databases - 5 Things to Remember

Did you ever face a situation where some of your innocuous looking action has cause production issue and that too big time? Well, I hope yo…


How to check for NULL values in SQL Query? The Right way Example

One of the most common SQL Interview question on Programming interview is to select some rows from a table which also contains null values…


How to Compare Date in SQL Server Query? Finding All Rows Between Two Dates

It's tricky to use dates in SQL server query, especially if you don't have good knowledge of how DateTime type works in SQL server.…


How to get just DATE or TIME from GETDATE() in SQL Sever

The GETDATE is one of the most popular built-in methods of Microsoft SQL Server, but unlike its name suggest, it doesn't return just …


Difference between row_number(), rank() and dense_rank() in SQL Server, Oracle.

Though all three are ranking functions in SQL, also known as window function in Microsoft SQL Server, the difference between rank() , dense…


How to remove duplicate rows from a table in SQL

There are a couple of ways to remove duplicate rows from a table in SQL e.g. you can use a temp tables or a window function like row_number…


How to add Primary key into a new or existing table in SQL Server

Since a primary key is nothing but a constraint you can use ALTER clause of SQL to add a primary key into existing table. Though it's …


Difference between close and deallocate cursor in SQL

Cursor in a database is used to retrieve data from the result set, mostly one row at a time. You can use Cursor to update records and perfo…


How to Convert Result of SELECT Command to Comma Separated String in SQL Server

Sometimes, you need the result of SQL SELECT clause as a comma separated String e.g. if you are outputting ids of white-listed products. By…


How to increase length of existing VARCHAR column in SQL Server

You can increase the length of a VARCHAR column without losing existing data in SQL Server. All you need to do is that execute following …


How to delete from table using JOIN in SQL Server

It's a little bit tricky to delete from a table while using any type of JOIN in SQL e.g. Inner Join, Left Outer Join , or Right Outer J…


How to create and call stored procedure in MySQL with IN and OUT parameters

It's hard to remember exact syntax of, how to create stored procedure in MySQL, until you are creating and working on stored procedure …


Top 10 Oracle Interview Question and Answer - Database and SQL

These are some interview question and answer asked during my recent interview. Oracle interview questions are very important during any pro…


Difference between Primary key vs Foreign key in table � SQL database tutorial

The main difference between Primary key and Foreign key in a table is that it�s the same column which behaves as primary key in the parent …


What is Referential Integrity in Database or SQL - MySQL Example Tutorial

Referential Integrity is set of constraints applied to foreign key which prevents entering a row in child table (where you have foreign key…


Oracle 10g Pagination Query - SQL Example for Java Programmer

Many time we need SQL query which return data page by page i.e. 30 or 40 records at a time, which can be specified as page size. In fact Da…


How to add, modify and drop column with default value, NOT NULL constraint - MySQL database Example

How to add column in existing table with default value is another popular SQL interview question asked for Junior level programming job i…


How to create auto incremented identity column in SQL Server, MySQL, Sybase and Oracle ?

Automatic incremented ID, Sequence or Identity columns are those columns in any table whose value is automatically incremented by database …


How to Split String in SQL Server and Sybase

Some time we need to split a long comma separated String in Stored procedure e.g. Sybase or SQL Server stored procedures. Its quite common…