Datameer Blog

Tag: SQL FAQs

SQL FAQ Feat

How to use IF condition in SQL SELECT statement?

In SQL Server, we have below two options to implement IF condition in SQL SELECT statement. CASE WHEN… THEN IIF Let us consider the following ‘student’ table. CREATE TABLE student ( student_name VARCHAR(50), grade CHAR(1) ) INSERT INTO student SELECT ‘Jack’, ‘A’ UNION ALL SELECT ‘Rose’, ‘B’ UNION ALL SELECT ‘John’, ‘C’ UNION ALL SELECT […]

  • SQL FAQs
  • February 1, 2019
SQL FAQ Feat

How to initialize an AUTO_INCREMENT column in MySQL?

The value of AUTO_INCREMENT can be reinitialized using the below methods. ALTER TABLE… AUTO_INCREMENT TRUNCATE TABLE Let us consider the table below. CREATE TABLE student (     student_id INT PRIMARY KEY AUTO_INCREMENT,     student_name VARCHAR(50) ); INSERT INTO student(student_name) VALUES (‘Jack’); INSERT INTO student( student_name) VALUES (‘Rose’); 1. ALTER TABLE… AUTO_INCREMENT We can […]

  • SQL FAQs
  • February 1, 2019
SQL FAQ Feat

How to add an IDENTITY to an existing column in SQL?

There is no straightforward way to add IDENTITY to an existing column. We need to follow a series of steps to achieve this. There are two ways to do this. Creating New Table Creating New Column We need to convert the ‘student_id’ column of the table below to an IDENTITY column. CREATE TABLE student ( […]

  • SQL FAQs
  • February 1, 2019
SQL FAQ Feat

How to get only the DATE part from the DATETIME in SQL Server?

In SQL Server 2008 and above, we can either use the CONVERT or CAST function to return the DATE part from the DATETIME datatype. — using CONVERT function SELECT CONVERT(DATE, ‘2010-12-20 22:52:43.133’) DateOnly — using CAST function SELECT CAST(‘2010-12-20 22:52:43.133’ AS DATE) DateOnly — Output DateOnly ————— 2010-12-20 In the older version of SQL Server, […]

  • SQL FAQs
  • February 1, 2019
SQL FAQ Feat

How to escape a single quote in SQL Server?

The most simple way to escape a single quote in SQL Server is to pair it with another single quote. Below are some examples: — For selecting: [My name’s Jack.] SELECT ‘My name”s Jack.’ escaping_quote — Output escaping_quote ——————– My name’s Jack. — For selecting: [‘My name’s Jack.’] SELECT ”’My name”s Jack.”’ escaping_quote — Output […]

  • SQL FAQs
  • February 1, 2019
SQL FAQ Feat

How to create an AUTO_INCREMENT column in a table on Oracle DB using SQL?

Before Oracle 12c, we don’t have a direct method of generating an AUTO_INCREMENT column in a table. We need to use the combination of Sequences and Triggers. Now, we have two different ways to implement it. Using IDENTITY column There are three options on IDENTITY COLUMN BY DEFAULT AS IDENTITY ALWAYS AS IDENTITY BY DEFAULT […]

  • SQL FAQs
  • February 1, 2019

Subscribe for the Latest Posts

Search

Download our Ebook on Data Collaboration

A primer on analytics collaboration book cover

Featured Blog Posts

The Role of Chief Data Officers (CDOs) in 2020
The Role of Chief Data Officers (CDOs) in 2021

The Chief Data Officers role (CDOs) in 2021 is evolving as CDOs are having quite possibly their m...

  • John Morrell
  • April 3, 2021
Spectrum ETL
Disrupting the no-code cloud ELT market: Datame...

More than just loading Data: Datameer launches Datameer Spectrum ETL++ to disrupt the no-code clo...

  • Press Release
  • February 9, 2021
Google Partners with Datameer
Datameer Partners with Google Cloud to Deliver ...

Datameer is now a Google Cloud migration partner The partnership will help customers build secure...

  • Press Release
  • December 2, 2020
READ ALL