AmitDiwan has Published 10744 Articles

Set custom Auto Increment with ZEROFILL in MySQL

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 07:47:56

784 Views

Let us first create a table. Here. We have set UserId column with ZEROFILL and AUTO_INCREMENTmysql> create table DemoTable1831      (      UserId int(7) zerofill auto_increment,      PRIMARY KEY(UserId)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command ... Read More

Delete only specific rows in a table with MySQL

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 07:46:55

457 Views

To delete only specific rows, use MySQL NOT IN(). Let us first create a table −mysql> create table DemoTable1830      (      StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,      StudentName varchar(20)      )AUTO_INCREMENT=101; Query OK, 0 rows affected (0.00 sec)Insert some records in the table ... Read More

MySQL query to return the count of only NO values from corresponding column value

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 07:45:54

143 Views

Let us first create a table −mysql> create table DemoTable1829      (      Name varchar(20),      isTopper ENUM('YES', 'NO')      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1829 values('Chris', 'yes'); Query OK, 1 row ... Read More

Is it possible to add a set of elements in one cell with MySQL?

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 07:44:46

77 Views

To add a set of elements in a single cell, use the concept of JSON. Let us first create a table −mysql> create table DemoTable1828      (      EmployeeId int,      EmployeeRecords JSON      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the ... Read More

Perform mathematical operations in a MySQL Stored Procedure?

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 07:41:15

828 Views

Let us create a stored procedure. Here, we are calculating amount*quantity i.e. implementing mathematical operations −mysql> delimiter // mysql> create procedure calculation_proc(amount int, quantity int)      begin      select amount, quantity, (amount*quantity) as Total;      end      // Query OK, 0 rows affected (0.00 sec) mysql> ... Read More

How to search for ^ character in a MySQL table?

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 07:40:06

503 Views

To search for ^ character, use the LIKE operator as in the below syntax −select table_schema, table_name, column_name  from information_schema.columns  where column_name like '%^%';Let us first create a table −mysql> create table DemoTable1826      (      `^` varchar(20),      Name varchar(20),      `^Age` int     ... Read More

Display only NOT NULL values from a column with NULL and NOT NULL records in MySQL

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 07:38:49

521 Views

For this, you can use IS NOT NULL property. Let us first create a table −mysql> create table DemoTable1      (      DueDate date      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values('2019-09-10'); Query ... Read More

Implement If else in stored procedure in MySQL?

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 06:40:10

395 Views

To implement if-else, the syntax is as follows −if yourCondition then      yourStatement1;     else     yourStatement2;     end if ;To understand the above concept for if-else in a stored procedure, let us create a stored procedure −mysql> delimiter // mysql> create procedure If_else_stored_demo(value int)   ... Read More

How to increase precision with division in MySQL?

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 06:32:19

744 Views

To increase precision with division, use MySQL CAST(). Let us first create a table −mysql> create table DemoTable1823      (      Value int      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1823 values(1); Query OK, ... Read More

Update record on a specific date matching the current date in MySQL

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 06:30:57

722 Views

Let us first create a table −mysql> create table DemoTable1822      (      Amount int,      DueDate date      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1822 values(1000, '2019-10-11'); Query OK, 1 row affected ... Read More

Advertisements