Found 4219 Articles for MySQLi

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

Rishi Rathor
Updated on 30-Jul-2019 22:30:24

1K+ Views

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 table selectDataOnYearandMonthDemo −> ( −> BookId int, −> BookName varchar(100), −> BookDueDate datetime −> ); Query OK, 0 rows affected (0.57 sec)Now you can insert some records in the table. The query is as ... Read More

Insert current date in datetime format MySQL?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:24

794 Views

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 INTO yourTableName values(now());To understand both the syntax, let us first create a table. The query to create a table is as follows −mysql> create table NowAndCurdateDemo −> ( −> YourDueDate datetime −> ); Query OK, 0 rows affected (1.75 sec)Implement both ... Read More

MySQL command line client for Windows?

Anvi Jain
Updated on 30-Jul-2019 22:30:24

3K+ Views

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 the installer.

How to display the Engine of a MySQL table?

Vrundesha Joshi
Updated on 25-Jun-2020 12:30:25

1K+ Views

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 −show table status from yourDatabaseName Like ‘yourTableName’.The following is the query to display engine of all the tables −mysql> show table status from sampleTest;The following is the output −+--------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+--------------------+----------+----------------+---------+ | Name          | Engine  | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | ... Read More

Update column size in MySQL and increase its size?

Rishi Rathor
Updated on 30-Jul-2019 22:30:24

323 Views

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 −> ( −> id int, −> Name varchar(5) −> ); Query OK, 0 rows affected (0.64 sec)Look at the column ‘Name’ above, the column size is 5. Whenever we will give the size greater than 5 then MySQL gives the following error −mysql> ... Read More

How to get primary key of a table in MySQL?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:24

4K+ Views

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 as follows −mysql> create table TwoOrMorePrimary    −> (    −> Id int,    −> Name varchar(200),    −> RollNum int    −> ,    −> Primary key(Id, Age)    −> ); Query OK, 0 rows affected (0.85 sec)Apply the above syntax to get primary key of a table. ... Read More

Delimiters in MySQL?

Anvi Jain
Updated on 30-Jul-2019 22:30:24

6K+ Views

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 $$ or //.Here we have a table “GetRecordFromNow” wherein the following are the records −+---------------------+ | YourDateTime | +---------------------+ | 2018-12-07 22:30:18 | | 2018-12-03 22:30:31 | | 2018-12-02 22:30:41 | | 2018-12-01 22:30:56 | | 2018-12-03 22:31:04 | +---------------------+ 5 rows in ... Read More

Select records from MySQL NOW() -1 Day?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:24

1K+ Views

To get records from NOW()-1 Day, you can use the following syntax −select *from yourTableName where yourColumnName >=now()-interval 1 day;To understand the above syntax, let us first create a table. The query to create a table.mysql> create table GetRecordsFromNow −> ( −> YourDateTime datetime −> ); Query OK, 0 rows affected (1.76 sec)Now insert some dates into the fields. The query to insert records are as follows −mysql> insert into GetRecordsFromNow values(date_add(now(), interval 3 day)); Query OK, 1 row affected (0.28 sec) mysql> insert into GetRecordsFromNow values(date_add(now(), interval -1 day)); ... Read More

How to change the column position of MySQL table without losing column data?

Rishi Rathor
Updated on 30-Jul-2019 22:30:24

9K+ Views

You can change the column position of MySQL table without losing data with the help of ALTER TABLE command. The syntax is as follows −ALTER TABLE yourTableName MODIFY yourColumnName1 data type AFTER yourColumnName2;To understand the above concept, let us create a table. The query to create a table with some columns is as follows −mysql> create table changeColumnPositionDemo −> ( −> StudentId int, −> StudentAddress varchar(200), −> StudentAge int, −> StudentName varchar(200) −> ); Query OK, 0 rows affected (0.72 sec)Let us insert some data in the table. The query to insert records is as follows -.mysql> insert into changeColumnPositionDemo ... Read More

Search for a string within text column in MySQL?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:24

660 Views

You can search for a string within text column in MySQL with the help of LIKE clause. The syntax is as follows −select *from yourTableName where yourColumnName like '%anyStringValue%';To use the above syntax, let us first create a table −mysql> create table SearchTextDemo    −> (    −> BookName TEXT    −> ); Query OK, 0 rows affected (0.55 sec)Insert some strings in the table. The query is as follows −mysql> insert into SearchTextDemo values('Let us C'); Query OK, 1 row affected (0.28 sec) mysql> insert into SearchTextDemo values('C in Depth'); Query OK, 1 row affected (0.14 sec) ... Read More

Advertisements