Found 4381 Articles for MySQL

Is there a difference in using INT(1) vs TINYINT(1) in MySQL?

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

2K+ Views

The number 1 used in parenthesis is only for width display. The INT(1) and TINYINT(1) does not influence the storage.The TINYINT takes 1 byte that means it has range -128 to +127 while int takes 4 bytes; it has range -2147483648 to +2147483647To understand the width display, let us create a table −mysql> create table intAndTinyint    −> (    −> FirstNumber int(1) zerofill,    −> SecondNumber tinyint(1) zerofill    −> ); Query OK, 0 rows affected (0.52 sec)Now you can insert records in the table. The query is as follows −mysql> insert into intAndTinyint values(1, 1); Query OK, 1 ... Read More

Get the first and last date of next month in MySQL?

Ankith Reddy
Updated on 30-Jul-2019 22:30:24

1K+ Views

You can get the first and last date of next month using date_add() function from MySQL.The syntax is as follows -select date_sub(    last_day(       date_add(now(), interval anyIntervalTime)    ),    interval day(       last_day(          date_add(now(), interval anyIntervalTime)       )    )-1 DAY ) as anyVariableName, last_day ( date_add(now(), anyIntervalTime) ) as anyVariableName;Implement the above syntax to get the first and last date of next month using interval 1 month in date_add() function. The query is as follows.mysql> select -> date_sub( ->    last_day( ->     ... Read More

MySQL Select Multiple VALUES?

Rishi Rathor
Updated on 29-Jun-2020 09:07:55

22K+ Views

To select multiple values, you can use where clause with OR and IN operator.The syntax is as follows −Case 1 − Using ORselect *from yourTablename where yourColumnName = value1 or yourColumnName = value2 or yourColumnName = value3, .........N;Case 2 − Using INselect *from yourTableName where yourColumnName IN(value1, value2, ....N);To understand the above syntax, let us create a table. The following is the query to create a table −mysql> create table selectMultipleValues −> ( −> BookId int, −> BookName varchar(200) −> ); Query OK, 0 rows affected (1.68 sec)Now you can insert some records in the table with the help of ... Read More

How to insert multiple rows with single MySQL query?

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

416 Views

You can insert multiple rows with the help of values() separated by comma(, ). The syntax is as follows −insert into yourTableName values(value1, value2, ...N), (value1, value2, ...N), (value1, value2, ...N), (value1, value2, ...N), (value1, value2, ...N), (value1, value2, ...N)................N;To insert multiple rows, let us create a table. The following is the query to create a table −mysql> create table MultipleRowsInsert    −> (    −> UserId int,    −> UserName varchar(200)    −> ); Query OK, 0 rows affected (1.21 sec)Here is the query to insert multiple rows in the table −mysql> insert into MultipleRowsInsert values(100, 'Bob'), (101, 'Smith'), ... Read More

What does DELIMITER // do in a Trigger in MySQL?

Venu Madhavi
Updated on 12-Feb-2025 12:07:51

3K+ Views

DELIMITER in MySQL Triggers In MySQL, a DELIMITER command changes the delimiter from its default value of semicolon (;) to another string like //. This is really useful when creating stored procedures or triggers that contain multiple SQL statements, which may also include semicolons. Why do we Change the Delimiter in MySQL When you declare a trigger, you have to write a few SQL statements that may also involve control flow statements like IF conditions, which include semicolons. Unless you change the delimiter, MySQL will consider the first semicolon to be the end of the declaration of the ... Read More

Setting similar value for a column in a MySQL table?

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

90 Views

You can set value for a column of all records with the help of update command.The syntax is as follows if you want set NULL value for all the records in a column −update yourTableName set yourColumnName = NULL;Or if you want to use empty string, the following is the syntax −update yourTableName set yourColumnName = ’’;To understand the above concept, let us create a table. The query to create a table.mysql> create table StudentDemo    −> (    −> Studentid int,    −> StudentName varchar(100),    −> Age int    −> ); Query OK, 0 rows affected (0.64 sec)The ... Read More

int(5) vs. int(10) in MySQL?

Vrundesha Joshi
Updated on 29-Jun-2020 09:11:10

2K+ Views

The value in the parentheses is used to display only the width and sets the zerofill. The width is 5 for int(5), whereas 10 for int(10). Let us see another example with a different width value set for int.Let us first create a table. Here, we have set the int to int(11) and int(13). The following is the query to create a table −mysql> create table intVsIntAnyThingDemo −> ( −> Number1 int(11) unsigned zerofill, −> Number int(13) unsigned zerofill −> ); Query OK, 0 rows affected (1.17 sec)Now you can insert record in the table with the help of insert ... Read More

Set the result of a query to a variable in MySQL?

Chandu yadav
Updated on 29-Jun-2020 09:10:38

403 Views

You can set the result of a query using select into command. The syntax is as follows.select yourColumnName1 into @anyVariableName from yourTableName where yourColumnName2='anyValue';Check the result is present in the variable or not using the select command. The syntax is as follows -select @anyVariableName;To understand the above syntax, let us first create a table. The query to create a table is as follows.mysql> create table StudentInformation -> ( -> StudentId int, -> StudentName varchar(100), -> StudentAge int -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command. The query is as follows.mysql> insert ... Read More

MySQL BigInt zerofill vs int zerofill?

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

289 Views

The difference between MySQL BigInt and int is that INT is a 32-bit long while BIGINT is 64-bit long.The following are some of the points −The BigInt takes 8 bytes of storage while int takes 4 bytes of storage.The int takes 4294967295 maximum values for int(10), whereas 18, 446, 744, 073, 709, 551, 615 for the bigint(20).The BigInt(20) and int(10), in this 20 and 10 can be used for width display with zerofill.Here is the demo of Bigint and int with zerofill. The following is the query to create a table.mysql> create table BigintandintDemo −> ( ... Read More

How to make MySQL's NOW() and CURDATE() functions use UTC?

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

218 Views

To make MySQL’s NOW() and CURDATE() functions use UTC, you need to write my.cnf file. Write the below instruction in my.cnf −[mysqld_safe] timezone = UTCFirstly, reach the directory with the help of the following query −mysql> select @@datadir;The following is the output −+---------------------------------------------+ | @@datadir | +---------------------------------------------+ | C:\ProgramData\MySQL\MySQL Server 8.0\Data\ | +---------------------------------------------+ 1 row in set (0.00 sec)Now reach the directory for which the link ... Read More

Advertisements