Tuesday, April 21, 2026

Confused Between SQL, T-SQL, and PL/SQL? Here’s the Clear Difference"

 Hello guys, if you are preparing for SQL and Database Interviews or any Software engineering interview and looking for difference between T-SQL, SQL, and PL/SQL then you have come to the right place. Earlier, I have shared 50 SQL Interview questions and 12 SQL query Examples from interviews and today, we are going to see another common and interesting SQL interview question, what is the difference between SQL, T-SQL, and PL/SQL? It is also one of the most common doubts among SQL beginners. It's common for programmers to think that why there are many types of SQL languages, why not just single SQL across DB? etc. Well, let's first understand the difference between SQL, T-SQL, and PL/SQL, and then we will understand the need for these dialects.

SQL is standard for querying, inserting, and modifying data in a relational database. It is categorized into DDL and DML and is powerful enough to create database objects e.g. table, view, stored procedure, and can perform CRUD operation (SELECT, INSERT, UPDATE, and DELETE) query.

On the other hand, T-SQL (Transact-SQL) is a dialect used by Microsoft SQL Server and Sybase. It is an extension of SQL and provides more functionality than SQL but at the same time confirming ANSI SQL standard as well. For example, you can use conditionals and loops in T-SQL to create a more sophisticated stored procedure that is not available in standard SQL.

Similarly, PL/SQL (Procedural language SEQUEL) is a dialect for Oracle database, which provides T-SQL like functionality e.g. conditionals, loops, and other elements for procedural programming. Both T-SQL and PL/SQL are the supersets of SQL because they not just confirm ANSI SQL standard but also provide additional functionality that is not available in the ANSI standard but helps a lot in database programming.

In this article, you will learn  a couple of more differences between SQL, T-SQL, and PL/SQL to understand them better.




Why do you need T-SQL or PL/SQL?

Though standard SQL is enough for inserting, retrieving, and modifying data from the database, they only provide set-based operations, which means there are a lot of tasks that you cannot do using plain SQL.

In order to make SQL more powerful and to expand its usage from simple querying to create complex stored procedures for report generation, XSLT transformation, and many other functionalities, various database vendors started adding proprietary features on SQL supported by their platform. 

These efforts created different SQL dialects e.g. T-SQL, which is a SQL dialect for Microsoft SQL Server, and Sybase, PL/SQL which is a SQL dialect for Oracle.

In fact, every database has its own SQL dialect, which comprises features and keywords only supported in their database e.g. MySQL has the LIMIT keyword which can be used for pagination or solving problems like second highest salary, but it will not work on Oracle or Microsoft SQL Server database. Similarly, PostgreSQL has some features which are not available to other databases.

It's always recommended to use standard ANSI SQL if it serves your purpose because query written in ANSI SQL is portable across different database vendors but if you use a proprietary keyword e.g. TOP in Microsoft SQL Server, LIMIT in MySQL then you need to change your query when your application migrate from one database to another.



Differences between SQL, T-SQL and PL/SQL

Here are a couple of more differences between SQL, PL/SQL, and T-SQL for interviews:

1. Full form
SQL stands for Structured Query language, T-SQL stands for Transact-SQL and PL/SQL stands for Procedural Language/SQL.

2. Supported Database
SQL is supported across all database vendors like Oracle, SQL Server, MySQL, PostgreSQL, IBM DB2, and even lightweight databases like SQLLite, but T-SQL is only supported in Microsoft SQL Server and Sybase, and PL/SQL is supported only in Oracle.


3. Performance
Another key difference between SQL and PL/SQL, T-SQL is the performance improvement by saving database roundtrip. Both PL/SQL and T-SQL allow grouping of SQL statements which means if your code has 4 SELECT SQL queries then instead of making four round trips to the database, they can be sent as one single unit to the database and their result will also come back as one unit. 

I suggest joining these best Oracle and PL/SQL online courses to learn more about PL/SQL programming. It covers versions through Oracle Database 12c.

difference between SQL vs T-SQL vs PL/SQL?

4. SQL Query Requirement
There is an interesting difference between SQL and T-SQL in terms of minimum SELECT query requirements. According to standard SQL, a SELECT query must have at minimum FROM and SELECT clauses, but you can create a SELECT query in T-SQL with just a SELECT clause, without FROM clause. 

For example, the following SQL query is invalid according to SQL standard but it works fine in T-SQL supported databases like Sybase and MSSQL:

SELECT 'Java' AS Language, 1 AS RANK;

The output of the query is a single row with attributes resulting from the expression with names assigned using the aliases e.g.

Language Rank
Java     1

If you want to learn more about T-SQL, I suggest joining these Microsoft SQL Server and T-SQL Fundamentals courses, a great reference to T-SQL but at the same time a very readable and clear explanation of key SQL concepts.


5. Data Types and Keyword
There are some data types which are supported only by PL/SQL and T-SQL e.g. TINYINT data type is only available in T-SQL and VARCHAR2 and NUMBER is only available in PL/SQL or Oracle database. Similarly, there are keywords which are only available in a particular SQL dialect like the LIMIT keyword which is only available in MySQL.

If you want to learn more about features, keyword, and data types supported by different vendors I strongly suggest joining these best SQL courses, it provides a great cross-platform syntax for SQL. Absolutely must-read for those programmers who work with multiple databases


That's all on the difference between SQL, T-SQL, and PL/SQL. Just remember that both T-SQL and PL/SQL are dialects of SQL, which is the standard specified by ANSI for managing data in relational databases. T-SQL is only supported in Sybase and SQL Server, while PL/SQL is only supported in the Oracle database. Though both T-SQL and PL/SQL are more powerful than SQL and provide several languages construct to do more with database e.g. conditionals, loops, branching, etc.


Other Database and SQL Interview Questions you may like
  • Difference between Primary key and Foreign key in SQL? (answer)
  • Difference between row_number, rank, and dense_rank in SQL? (answer)
  • Difference between Primary key and Unique key in SQL? (answer)
  • When to use truncate vs delete command in SQL? (answer)
  • Difference between LEFT and RIGHT Outer Join in SQL? (answer)
  • Difference between Clustered and Non-Clustered index in SQL? (answer)
  • Top 6 SQL Query Interview Questions for Programmers (list)
  • Difference between WHERE and HAVING clause in SQL? (answer)
  • Difference between UNION and UNION ALL in SQL? (answer)
  • Difference between View and Materialized view in SQL? (answer)
  • Difference between Primary key and Candidate key in SQL? (answer)
  • Difference between Correlated and Regular Subquery in SQL? (answer)
  • Difference between IsNull() and Coalesce() in T-SQL? (answer)
  • Difference between GETDATE, SYSDATETIME, and GETUTCDATE in T-SQL? (answer)
  • Difference between Self Join and Equi Join in SQL? (answer)
  • Difference between close and deallocate cursor in SQL? (answer)
  • Difference between CHAR and VARCHAR data type in SQL? (answer)
  • 5 SQL Books Every Programmer Should Read (books)

Thank you for reading this article, if you like this tutorial then please share with your friends and colleagues. If you have any feedback or suggestion then please drop a comment. 

P.S. - If you are new SQL and Database world and looking for some free resources to start your journey then you can also take a look at this list of Free SQL Courses for Beginners to start your SQL and Database journey for FREE. 

Monday, April 20, 2026

How to Join Two or More Tables in a SQL query? Left Join Example Leetcode Solution

Hello friends, when it comes to combining two tables in SQL, many programmers don't know that they can use the JOIN clause. In fact, JOIN is there to fetch data from multiple tables together. There are mainly two types of joins, INNER Join and OUTER join. On Inner join, only those records have matching values in both tables, while in Outer join, all records from one table are selected in addition to matching records from other tables. There are two kinds of Outer join in SQL, LEFT OUTER JOIN and RIGHT OUTER JOIN. Both are actually the same thing, which means you can get the same result by using either of the outer joins by changing the table's position from left to right.


This is my third article on solving LeetCode SQL problems; earlier, I have shown you how to use the existing clause to find all the customers who have never ordered and how to use the GROUP BY clause to find the duplicate emails from the table. If you need some practice, you can check those articles as well.

LeetCode also has a good collection of SQL problems that are good to improve your SQL query skills, and I suggest you take a look at those problems if you want to improve your SQL query skills. Now let's come to the LeedCode problem; there are two tables, Person and Address, as shown below :

Table: Person

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| PersonId    | int     |
| FirstName   | varchar |
| LastName    | varchar |
+-------------+---------+
PersonId is the primary key column for this table.

Table: Address

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| AddressId   | int     |
| PersonId    | int     |
| City        | varchar |
| State       | varchar |
+-------------+---------+

AddressId is the primary key column for this table.


Problem - Write a SQL query for a report that provides the following information for each person in the Person table, regardless if there is an address for each of those people:

FirstName, LastName, City, State

You can solve this problem using LEFT or RIGHT outer join because you need to combine two tables here to get both Names and Address related information. If you are not familiar with joining SQL, I strongly suggest you start with a comprehensive SQL course like The Complete SQL Bootcamp course by Jose Portilla on Udemy.

SQL Joins is one of the tricky but essential concepts to learn, and going through this course will help you learn in a more structured way, which will eventually help you solve this kind of problem quickly, both during work and in coding interviews.





How to Combine Rows from two or  more tables using LEFT JOIN in SQL?

As I told you, we can solve this problem by joining both the Person and Address table. You can use either Inner Join or Outer join to combine the table, but the key thing to note here is that you need to print records for each person in the Person table, regardless of whether there is an address.

This means you cannot solve this problem using INNER join because if you used INNER join, only persons with addresses would be printed. 

If we need to print all the persons with or without addresses, we need to use the  LEFT JOIN (Person LEFT JOIN Address) or a RIGHT JOIN (Address RIGHT JOIN Person).

We will use the LEFT JOIN in this example because that is much easier to read.

Here is the solution to this SQL problem :

# WRITE your MySQL query statement below
 
SELECT FirstName, LastName, City, State
 FROM Person p 
 LEFT JOIN Address a 
 ON p.PersonId = a.PersonId

You can also write this query as see the OUTER word; this is optional in MySQL, which means both LEFT JOIN and LEFT OUTER JOIN will work. You can see The Ultimate MySQL Bootcamp course on Udemy to learn more about how SQL works inside the MySQL database.

# WRITE your MySQL query statement below
 
SELECT FirstName, LastName, City, State 
   FROM Person p 
   LEFT OUTER JOIN Address a 
   ON p.PersonId = a.PersonId

The same query can be written using the RIGHT OUTER JOIN as well. Here is how you do it :

# WRITE your MySQL query statement below
 
SELECT FirstName, LastName, City, State 
    FROM Address a 
    RIGHT OUTER JOIN Person p
    ON a.PersonId = p.PersonId

This query will produce the same output as the above two queries. If you look carefully, we have exchanged the position of Person and Address table in this query. Earlier Person was on the left-hand side, but now because of RIGHT JOIN, it's on the right side.

Joins are trick and there are so many of them to learn, but this diagram and SQL for Data Science course on Coursera is a good way to learn them after all SQL is one of the essential skills for both Programmers and Data Scientist.

How to combine Two Tables using LEFT JOIN in SQL - LeetCode Solution


That's all about how to combine data from multiple tables in SQL using LEFT and RIGHT Outer Joins. If you need only matching records from both tables, then use INNER Join; if you need all records from one table and matching records from another table, please use OUTER JOIN in SQL.

You are free to use LEFT or RIGHT joins as per your liking, but if you use LEFT OUTER JOIN make sure you put the right table on the left side of the JOIN clause, like the table from which you need all records.


Other related SQL queries, Interview questions, and articles:
  • How to join three tables in one single SQL query (solution)
  • 10 Frequently asked SQL Query interview questions (solution)
  • Write SQL Query to find duplicate emails - LeetCode problem (solution)
  • Write a SQL query to find all table names on a database in MySQL (solution)
  • 5 Courses to learn Database and SQL Better (courses)
  • Top 5 Websites to learn SQL online for FREE? (resource)
  • What is the difference between UNION and UNION ALL in SQL? (answer)
  • Write a SQL query to copy or backup a table in MySQL (solution)
  • How do you find the duplicate rows in a table on a database? (solution)
  • The real difference between WHERE and HAVING clause in SQL? (answer)
  • 5 Free Courses to learn Database and SQL (free courses)
  • How to migrate SQL queries from Oracle to SQL Server 2008? (answer)
  • 4 Free Books to learn Microsoft SQL Server database (books)
  • Top 5 Websites to learn SQL online for FREE? (websites)
  • 5 Free Courses to learn Oracle and SQL Server? (courses)
  • Top 5 Courses to learn MySQL Database for Beginners (Courses)
  • What is the difference between View and Materialized View in Database? (answer)
  • Difference between clustered and non-clustered index in SQL? (answer)
  • 5 Advanced SQL books to level up your SQL skills (books)
  • 5 Courses to learn Oracle and Microsoft SQL Server database (courses)
  • Difference between Self and Equi Join in SQL? (answer)
  • What difference between the Primary and Candidate key in table? (answer)
  • 5 Free Courses to learn T-SQL and SQL Server for Beginners (Courses)
  • Difference between the Unique and Primary keys in the table? (answer)
  • Top 5 Courses to learn PostgreSQL in-depth (courses)
  • 5 Free Courses to learn T-SQL and SQL Server for Beginners (Courses)
  • What difference between the Primary and Foreign keys in the table? (answer)
  • Top 5 Courses to learn Microsoft SQL Server in-depth (courses)

Thanks for reading this article, if you like this SQL article, then please share with your friends and colleagues. If you have any questions or feedback, then please drop a note.

P.S. - If you are interested in learning Database and SQL and looking for some free resources to start your journey, you can also look at the Introduction to Databases and SQL Querying free course on Udemy to kick-start your learning.

Sunday, April 19, 2026

The SQL Developer's Reading List for 2026 (7 Books That Matter)

 SQL (Structured Query Language) is one of the most essential skills of a programmer. I would rate this skill similar to UNIX if you are a professional programmer because it doesn't matter whether you are Java, C++, or a .NET developer, you are bound to write SQL queries. Since a database is an integral part of any modern Java or Web application, the Interviewer always preferred candidates with excellent SQL skills. Now, the big question comes, how a programmer can learn SQL? Does just knowing how to query a table is enough? If you remember, insert, update, delete, and select, then are you a competent SQL programmer?

What about indexes, query plans, triggers, views, stored procedures, and other advanced SQL concepts? What about writing complex queries involving joins, subqueries, derived tables, etc.? Well, all those are very important to be a competent full-stack developer.

I started learning SQL from my college days, and I am hooked to it because of its simplicity and power. I also found writing SQL queries exciting and challenging, similar to solving programming puzzles, but my SQL skills don't improve a lot for a long time, Why? Because I was satisfied with the limited knowledge of insert, update, delete, and select.

 I knew how to join multiple tables, and I thought I knew the whole SQL. Well, I was wrong, and my misconception hit severely when I started working on a project involving Murex, which has a vast database in Sybase with hundreds of tables, stored procedures, and other database objects.

At that time, I started learning advanced SQL, particularly Sybase and SQL Server. My quest also results in lots of good books to learn SQL, database design, normalization, and improve your SQL query skills, and this article is a collection of such books.

Though I have a separate collection of database-specific books, like books, to learn SQL Server, Sybase, or Oracle, I am only sharing books to learn generic and standard SQL, which applies to all relational databases, also known as ANSI SQL in this article. I'll write separate articles about SQL Server and Oracle books.

If you want to learn quickly, you can also combine these books with some of the comprehensive and engaging online SQL courses like The Complete SQL Bootcamp by Jose Pottila on Udemy. It's an incredible course full of useful information and practical tips to learn and master SQL very quickly.





7 Best Books to learn SQL and Database for Beginners in 2026

It doesn't matter whether you are a beginner programmer, just started your software development career or an experienced software professional with years of experience, you will find some of the books refreshing. You will learn a lot in terms of SQL concepts, database design, and SQL query skills.

So, what are we waiting for? Let's start with this list.

1. Head First SQL

This is the best book for any SQL beginners. I like the Head First style for their innovative teaching with diagrams, fireside chats, puzzles, explanations, and highlight the most important concepts.

I have been recommending this book to beginner programmers for years, and they always thank me for that. You can use this book for theory, for example, and understanding fundamental concepts of SQL, like Joins, Subqueries, Normalization, and a little bit of database design.

If you are an active learner like me then you can also combine this book with The Complete SQL Bootcamp: Go From Zero To Hero course by Jose Portilla on Udemy which is full of hands-on SQL exercises and lectures. It's also very affordable and you can buy this course for just %9.9 on Udemy sales which happen every now and then.

The Best book to learn SQL


2. SQL All-in-One For Dummies

The third edition of "SQL All-in-One For Dummies" by Allen G. Taylor stands as a comprehensive resource with a stellar rating of 4.6 out of 5 from 920 ratings. Geared towards a wide audience, from database administrators to application programmers, this book provides clear and concise explanations of the SQL language and its diverse applications within relational databases. 

In a rapidly evolving landscape where businesses are transitioning from spreadsheets to SQL databases like Access, Microsoft SQL Server, Oracle databases, MySQL, and PostgreSQL, this edition serves as a one-stop shop for anyone involved in designing, developing, and maintaining these databases. 

The book addresses the challenges that may arise in SQL database creation and management, keeps readers informed about the latest SQL updates and capabilities, and serves as a valuable reference for querying SQL-based databases in the SQL language.

 Emphasizing the significance of relational databases in today's organizations, "SQL All-In-One For Dummies" offers timely and detailed insights for those seeking a robust understanding of SQL databases and queries. 

A newer edition is also coming which means the book remains up-to-date, reflecting the dynamic nature of SQL technology. If you need active learning, you can also combine this book with the Complete Intro to SQL & PostgreSQL by Brian Holt  course , its a nice SQL course for beginners. "Learning SQL: Generate, Manipulate, and Retrieve Data, 3rd Edition" by Alan Beaulieu has earned a commendable rating of 4.6 out of 5 from 465 ratings, making it a well-received resource in the field of SQL education. 

In this latest edition, Beaulieu guides developers through the essentials of SQL, providing a solid foundation for writing database applications, executing administrative tasks, and generating reports. As organizations grapple with the influx of data, SQL emerges as a vital tool, and this guide equips developers to harness its power effectively. 

The book covers SQL basics and delves into advanced features, including new chapters on SQL and big data, analytic functions, and working with very large databases. Each chapter is designed as a self-contained lesson, featuring numerous illustrations and annotated examples to facilitate understanding. The inclusion of exercises enables readers to practice and reinforce the skills they acquire. 

The book also emphasizes the importance of SQL knowledge for interacting with data, making it an essential resource for those looking to leverage the language's power and flexibility. 

Whether you are a beginner or seeking to enhance your SQL proficiency, "Learning SQL" provides a comprehensive and practical guide to navigating SQL concepts and techniques, and if you need a course, you can also combine this with the SQL for Newbs: Data Analysis for Beginners course on Udemy. 



4. SQL Antipatterns

To be successful, it's not just essential to do the right things, but it is also necessary to avoid mistakes that can hamper your success. This universal truth is also applicable to SQL. It's just not enough to know all the best practices in the SQL world and keep repeating silly mistakes like using SELECT * query or having duplicate columns.

This book will help you to avoid the common mistake every SQL developer makes. If you don't know about SQL mistakes, it's also an excellent book to learn about them. Again, one of the must-read SQL books for programmers who are serious about improving their SQL and database design skills.

If you are learning SQL for data science then I also suggest you check out this SQL for Data Science course on Udemy which will teach you how to understand and write large queries which you often need while working with real-world data.

Best book to learn SQL design and schema




5. SQL Puzzles and Answers by Joe Celko

I didn't know about this book until last year, but ever since I come to know about it, I just fall in love. It's a great book to improve your SQL query skills. I always like to solve SQL query-based problems because they are also an excellent exercise for your mind, and this book is full of such issues.

The book is really advanced, and some of the problems are tough even for seasoned SQL programmers. Even though you will solve the problem, a good chance is that you will also learn a new way to answer the same question by reading explanations.

In short, one of the best SQL books for experienced programmers who want to improve their SQL query skills.

Good book to learn SQL Queries





6 . Beginning SQL queries

This is another beginner book, probably for the absolute beginner who doesn't know how to write SQL queries. As the title suggests, this book will help you not only to write SQL queries but also to write correct SQL queries and help you to become a professional SQL developer. Not a must-read, but a good SQL book for beginners.

Beginners book to learn SQL queries




7. SQL Performance Explained by Markus Winand

If I say that whatever I know about SQL indexes is due to this book, then it won't be wrong. I had a lot of misconceptions about database indices and didn't know how their order can affect performance.

I didn't even know what is table scan, index scan is, and index seeks, and, in general, how does index works in SQL in detail until to learn how indexing work and how they affect query performance.

This is an excellent book from Markus Winand, and I thank him a lot for explaining such an essential topic in great detail. One of the must-read SQL books for every programmer.

Best book to learn SQL index and performance



That's all in this list about 5 great books to learn and master SQL. To be honest, it's easy to learn SQL, but it's tough to master it; that's why the last two books SQL Performance Explained and SQL Anti-Patterns are significant for both SQL developer and Java/C# developers who deal with databases and SQL.



Other Books and Courses Recommendations for Programmers
  • 10 Algorithm books for Programmers and Software engineers (see here)
  • 7 Free Courses to learn SQL and Database for Beginners (courses)
  • 5 Books to improve your Coding Skill (see here)
  • 10 Courses to learn Data Structure and algorithms (classes)
  • 10 Books Every Programmer Should Read (see here)
  • My Favorite courses to learn MySQL database (courses)
  • 10 Tips and 101 Problems to Crack Coding Interviews (tips)
  • 5 Books to learn Java 8 and Functional Programming (see here)
  • My favorite free courses to learn Java in-depth (courses)
  • 5 Books to prepare Programming/Coding Interviews (see here)
  • 10 Courses to Crack Programming Job Interviews (courses)
  • 5 Books to learn Concurrent programming and multi-threading (see here)
  • Top 5 Courses to learn Java Concurrency in-depth (courses)
  • 6 Books to learn Hibernate framework for Java developers (see here)
  • 5 books to learn Spring framework for Java developers (see here)
  • 5 of the Best courses to learn Spring Boot (courses)

Thanks for reading this article so far. If you like these best SQL and Database books, then please share them with your friends and colleagues. If you have any questions or feedback, then please drop a note.

P.S. - Along with books, online training courses on platforms like Udemy, Coursera, and Pluralsight are also useful to learn fundamentals and build skills. If you need some excellent classes to learn SQL and Database, I suggest you check this list of Top 5 SQL Courses for Programmers on HackerNoon to level up your SQL skill and learn new tricks to do well on your day-to-day job.

Friday, April 17, 2026

How to Format Date and Time in SQL Server (2026 Guide with Examples)

 How to format a date in SQL Server like in the "yyyymmdd" format? Suppose you have a date and time column in Sybase or Microsoft SQL Server,  which is displaying values in "Dec  31, 2026, 12:00 AM" and you want to display it in any particular DATE format like YYYYMMDD or DDMMYYYY, how will you do that? This is also one thing you need to keep in mind when you convert a DATE, TIME, DATETIME column into CHAR or VARCHAR values.  It's easy to format dates using the convert function in Sybase or SQL Server, but it's slightly difficult to remember the cryptic formatting style codes that go with it. For example, using style code, 112 is used to format dates in the "YYYYMMDD" format e.g. "20260329".


Similarly, the following query will format the birthday column (with value 11th Feb 1980) as 19840211 as shown below:

select convert(char(8), birthday, 112) from Employee
19840211

For quick reference, these formatting codes are listed below:


STYLE   OUTPUT
0       mon dd yyyy hh:miAM (or PM)
1       mm/dd/yy
2       yy.mm.dd
3       dd/mm/yy
4       yy.mm.dd
5       dd-mm-yy
6       dd mon yy
7       mon dd, yy
8       hh:mm:ss
9       mon dd yyyy hh:mi:ss:mmmAM (or PM)
10      mm-dd-yy
11      yy/mm/dd
12      yymmdd
100     mon dd yyyy hh:miAM (or PM)
101     mm/dd/yyyy
102     yyyy.mm.dd
103     dd/mm/yyyy
104     yyyy.mm.dd
105     dd-mm-yyyy
106     dd mon yyyy
107     mon dd, yyyy
108     hh:mm:ss
109     mon dd yyyy hh:mi:ss:mmmAM (or PM)
110     mm-dd-yyyy
111     yyyy/mm/dd
112     yyyymmdd

select convert(char(10), getdate(), 23)

By the way, if you are new to Microsoft SQL Server and T-SQL then I also suggest you join these online SQL Server courses to learn SQL Server fundamentals and how to work with T-SQL. 




Example of formatting, Date in SQL Server

Here is a couple of examples of formatting DATETIME data type in SQL Server. I have used the GETDATE function to get the current date for example purpose, this method returns a DATETIME data type.

 -- 0       mon dd yyyy hh:miAM (or PM)
 PRINT 'formatting date in mon dd yyyy hh:miAM (or PM) format'
 select convert(VARCHAR(255), getdate(), 0) 
as 'Date in mon dd yyyy hh:miAM (or PM) format'

-- 1       mm/dd/yy
select convert(char(10), getdate(), 1) as 'Date in mm/dd/yy format'

-- 2       yy.mm.dd
select convert(char(10), getdate(), 2) as 'Date in yy.mm.dd format'

-- 3       dd/mm/yy
select convert(char(10), getdate(), 3) as 'Date in  dd/mm/yy format'

-- 4       yy.mm.dd
select convert(char(10), getdate(), 4) as 'Date in yy.mm.dd format'

-- 5       dd-mm-yy
select convert(char(10), getdate(), 5) as 'Date in dd-mm-yy format'

-- 6       dd mon yy
select convert(char(10), getdate(), 6) as 'Date in dd mon yy format'

-- 7       mon dd, yy
select convert(char(10), getdate(), 7) as 'Date in mon dd, yy format'

-- 8       hh:mm:ss
select convert(char(10), getdate(), 8) as 'Date in hh:mm:ss format'

-- 9       mon dd yyyy hh:mi:ss:mmmAM (or PM)
select convert(char(10), getdate(), 9) 
as 'Date in mon dd yyyy hh:mi:ss:mmmAM (or PM)'

-- 10      mm-dd-yy
select convert(char(10), getdate(), 10) as 'Date in  mm-dd-yy format'

-- 11      yy/mm/dd
select convert(char(10), getdate(), 11) as 'Date in yy/mm/dd format'

-- 12      yymmdd
select convert(char(10), getdate(), 12) as 'Date in yymmdd format'

-- 100     mon dd yyyy hh:miAM (or PM)
select convert(char(10), getdate(), 100) 
as 'Date in mon dd yyyy hh:miAM (or PM) format'

-- 101     mm/dd/yyyy
select convert(char(10), getdate(), 101) as 'Date in  mm/dd/yyyy format'

-- 102     yyyy.mm.dd
select convert(char(10), getdate(), 102) as 'Date in yyyy.mm.dd format'

-- 103     dd/mm/yyyy
select convert(char(10), getdate(), 103) 
as 'Date in dd/mm/yyyy format in SQL'

-- 104     yyyy.mm.dd
select convert(char(10), getdate(), 104) 
as 'Date in yyyy.mm.dd format in SQL Server'

-- 105     dd-mm-yyyy
select convert(char(10), getdate(), 105) as 'Date in dd-mm-yyyy format'

-- 106     dd mon yyyy
select convert(char(10), getdate(), 106) as 'Date in  dd mon yyyy format'

-- 107     mon dd, yyyy
select convert(char(10), getdate(), 107) as 'Date in mon dd, yyyy format'

-- 108     hh:mm:ss
select convert(char(10), getdate(), 108) as 'Time in hh:mm:ss format'

-- 109     mon dd yyyy hh:mi:ss:mmmAM (or PM)
select convert(char(10), getdate(), 109) 
as 'Date time in mon dd yyyy hh:mi:ss:mmmAM (or PM) in SQL Server'

-- 110     mm-dd-yyyy
select convert(char(10), getdate(), 110) 
as 'Date in mm-dd-yyyy format in SQL Server'

-- 111     yyyy/mm/dd
select convert(char(10), getdate(), 111) 
as 'Date in yyyy/mm/dd format in SQL Server'

-- 112     yyyymmdd
select convert(char(10), getdate(), 112) as 'Date in yyyymmdd format'

and here is the output of executing all these commands in SQL Server:

How to format Date in SQL Server and Sybase Example


You can see from the output that same date value, which is today's date is formatted into a different format by using the same convert() function but by using different styles.

You can replace the GETDATE() with any column which represents date or date and time. I have just used the GETDATE for displaying output in today's date. In most of cases, you will be putting a date, time, or DateTime column there.

That's all about how to format a DATETIME in SQL Server. You can use the same technique to convert a DATETIME column to VARCHAR in SQL Server. Just remember that convert() function can be used for converting one data type to another and the same is used for formatting dates as well because formatting date and time is nothing but converting them into VARCHAR or CHAR values.

The only thing, which you need to keep in mind is the style codes. You can just print these style codes and keep a handy reference with you.



Other Microsoft SQL Server articles you may like
  • Querying Microsoft SQL SERVER 2012 Training Kit for Exam 70-461 (see here
  • Microsoft SQL SERVER 2012 T-SQL Fundamentals (check here)
  • How to check for NULL values in SQL server? (tutorial)
  • How to replace NULL with empty String in SQL Server? (example)
  • How to increase the length of existing columns in SQL Server? (tips)
  • How to compare Dates in Microsoft SQL Server? (solution
  • How to join three tables in one SQL Query? (tutorial
  • How to replace null with empty String in SQL Server? (solution
  • How to find the length of String in MSSQL? (solution
  • How to add the primary key into an existing table in SQL? (tip)
  • How to add columns on the existing table in Microsoft SQL Server? (solution
  • What is the difference between row_number(), rank(), and dense_rank() in SQL? (answer
  • The difference between ISNULL() and COALESCE() in SQL? (answer)
  • The difference between SQL queries in Oracle and Microsoft SQL Server? (answer
  • How many characters you can store in VARCHAR(2) column? (answer)
  • SQL query to find all table names in a database? (query
  • How to convert the result of a SELECT command to CSV String in SQL? (tutorial)
  • How to delete from a table using join in SQL? (tutorial
  • 5 Things to remember while running SQL Queries on Production Server? (tips)
  • What is the difference between WHERE and HAVING clause in SQL? (answer)
  • How to delete rows from a table using Join? (answer)
Thanks for reading this article, if you like this tutorial then please share with your friends and colleagues. If you have comments or suggestions or feedback then please drop a note. 

Thursday, April 16, 2026

🎁 My new book, Grokking the SQL Interview, is here!!

 Hello guys,

I am feeling proud and excited to announce the release of my new book, "Grokking the SQL Interview". Yes, it's finally available now after 2 years of waiting and you can purchase it now on Gumroad for a special price of just $10.95 (original price $21.90).

I thought about this book 2 years ago, and it took really long to work on this as I tried to make it as perfect as possible.

Here is the first tweet I made about this book 2 years ago for remember:

Now, I can proudly say that I have finally completed it and it's ready for purchase and reading, a big moment for me !!.

The book follows the same format as my previous Grokking the Java Interview and Grokking the Spring Boot Interview and tries to teach you SQL by interview questions. This is primarily for people who want to prepare for SQL questions like programmers, data scientist, IT support, BA, QA, or anyone who need to answer SQL questions in interviews.

It covers the following topics:

This book contains frequently asked Java questions from essential topics like

1. SQL and Database Phone interview questions

2. Joins in SQL

3. SQL Query Questions

4. Indexes

5. Group by and Aggregation

6. SQL Date and Time Questions

7. Stored Procedures

8. Triggers and Views

9. Transactions

10. Window Function and CTE

11. Deep Dive on popular SQL Questions

You can see that the topic has expanded since my first twee, as I tried to cover a few more things to make it complete.

For now, you can grab your copy for a big 50% discount,

Here is the link - 50% OFF on Grokking the SQL Interview

I really hope that this book helps you in your journey of cracking your next developer interview.

All the best

Javin