Concatenate two columns in MySQL?

Jennifer Nicholas
Published on 10-Jan-2019 17:32:44
To concatenate two columns, use CONCAT() function in MySQL. The syntax is as follows −select CONCAT(yourColumnName1, ' ', yourColumnName2) as anyVariableName from yourTableName;To understand the above concept, let us create a table. The query to create a table is as follows −mysql> create table concatenateTwoColumnsDemo    −> (    −> ... Read More

How to front pad zip code with “0” in MySQL?

Anvi Jain
Published on 10-Jan-2019 17:30:35
To front pad zip code with 0, use LPAD() function in MySQL. The syntax is as follows −SELECT LPAD(yourColumnName, columnWidth+1, '0') as anyVariableName from yourTableName;To understand the above concept of LPAD() to add front pad zip code with 0, let us create a table. One of the columns of the ... Read More

Check if a user exists in MySQL and drop it?

Vrundesha Joshi
Published on 10-Jan-2019 17:27:44
To check how many users are present in MySQL, use MySQL.user table. The syntax is as follows to check how many users are present.mysql> SELECT User FROM mysql.user;The following output displays the users −+------------------+ | User | +------------------+ ... Read More

Do a select in MySQL based only on month and year?

Rishi Rathor
Published on 10-Jan-2019 17:25:15
To select MySQL based on month and year, use in-built function YEAR() and MONTH(). The syntax is as follows −select *from yourTableName where YEAR(yourColumnName) = YearValue AND MONTH(yourColumnName) = monthValue;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create ... Read More

Insert current date in datetime format MySQL?

Jennifer Nicholas
Published on 10-Jan-2019 17:23:35
To insert the current date (not time), then you can use in-built function CURDATE() from MySQL. The syntax is as follows −INSERT INTO yourTableName values(curdate());Or if you want to add date and time both then you can use the in-built function NOW() from MySQL. The syntax is as follows −INSERT ... Read More

MySQL command line client for Windows?

Anvi Jain
Published on 10-Jan-2019 17:22:15
In order to install MySQL command line client for Windows, you need to visit the following URL to get the download link https://dev.mysql.com/downloads/mysql/ −The snapshot is as follows −After that you need to select operating system. The snapshot is as follows −You need to choose Windows (x86, 32/64-bit) and download ... Read More

How to display the Engine of a MySQL table?

Vrundesha Joshi
Published on 10-Jan-2019 17:13:00
To know whether a MySQL table is using MyISAM or InnoDB engine then you can use below syntax.The below syntax can be used for multiple tables −show table status from yourDatabaseName;Here is the syntax that can be used for a specific table i.e. to know the engine of a table ... Read More

Update column size in MySQL and increase its size?

Rishi Rathor
Published on 10-Jan-2019 17:11:18
To update the column size, you can use alter command. The syntax is as follows −alter table yourTableName change yourColumnName yourColumnName data type;To understand the above syntax, let us create a table. The query to create a table −mysql> create table DataTruncated −> ( ... Read More

How to get primary key of a table in MySQL?

Jennifer Nicholas
Published on 10-Jan-2019 17:07:35
To get the primary key of a table, you can use the show command. The syntax is as follows −SHOW INDEX FROM yourDatebaseName.yourTableName WHERE Key_name = 'PRIMARY';Suppose, we have a table with two primary keys; one of them is “Id” and second is “RollNum". The query for a table is ... Read More

Delimiters in MySQL?

Anvi Jain
Published on 10-Jan-2019 17:05:23
Delimiters can be used when you need to define the stored procedures, function as well as to create triggers. The default delimiter is semicolon.You can change the delimiters to create procedures and so on. However, but if you are considering multiple statements, then you need to use different delimiters like ... Read More
Advertisements