Found 4378 Articles for MySQL

What is the difference between SQL and MySQL?

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

469 Views

SQLSQL is a type of language that can be used to utilize your database. It is a base language for databases like MySQL, SQL Server, Oracle etc. SQL stands for Structure Query Language and it can be used to utilize the relational database management system.This can also be used for accessing, manipulating and updating data in the database using some commands. The SQL commands are as follows −SELECTUPDATE, etc.SQL can also be used in the creation of schema as well as controlling the data access.MySQLMySQL is a relational database management system that utilizes the SQL command. MySQL provides the tools ... Read More

What is the difference between MySQL TINYINT(2) vs TINYINT(1)?

George John
Updated on 30-Jul-2019 22:30:24

1K+ Views

The number 2 and 1 in TINYINT(2) vs TINYINT(1) indicate the display width. There is no difference between tinyint(1) and tinyint(2) except the width.If you use tinyint(2) or even tinyint(1), the difference is the same. You can understand the above concept using zerofill option.tinyint(1) zerofilltinyint(2) zerofillLet us create a table. The query to create a table is as follows −mysql> create table tinyIntDemo    -> (    -> Number1 tinyint(1) zerofill,    -> Number2 tinyint(2) zerofill    -> ); Query OK, 0 rows affected (0.62 sec)Insert record in the table using insert command. The query is as follows −mysql> insert ... Read More

Update MySQL date and increment by one Year?

Chandu yadav
Updated on 30-Jul-2019 22:30:24

914 Views

You can use in-built function date_add() from MySQL. The syntax is as follows −UPDATE yourTableName SET yourDateColumnName=DATE_ADD(yourDateColumnName, interval 1 year);To understand the above syntax, let us first create a table. The query to create a table is as follows −mysql> create table UpdateDate -> ( -> Id int, -> DueDate datetime -> ); Query OK, 0 rows affected (0.76 sec)Insert some records in the table using insert command. The query to insert record is as follows −mysql> insert into UpdateDate values(1001, '2012-5-21'); Query OK, 1 row affected (0.17 ... Read More

Set user variable from result of query in MySQL?

Arjun Thakur
Updated on 30-Jul-2019 22:30:24

901 Views

To set user variable from result of query in MySQL, you need to move that variable into the assignment.To understand the above concept, let us first create a table. The query to create a table is as follows −mysql> create table UserVariable -> ( -> Id int, -> Name varchar(100) -> ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into UserVariable values(101, 'John'); Query OK, 1 row affected (0.17 sec) mysql> insert ... Read More

How do I add more members to my ENUM - type column in MySQL?

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

367 Views

You can use alter command. The syntax is as follows −ALTER TABLE yourTableName MODIFY COLUMN yourColumNam enum(yourOldValue1, yourOldValue2, ....N, yourNewValue1, yourNewValue2, ....N);To understand the above syntax, let us first create a table. The query to create a table is as follows −mysql> create table EnumDemo -> ( -> AllColors enum('RED', 'GREEN') -> ); Query OK, 0 rows affected (0.66 sec)Now you have two members in AllColors of enum type. If you want to add more members to your enum type, use the following query −mysql> alter table EnumDemo -> modify column ... Read More

MySQL command for displaying current configuration variables?

George John
Updated on 30-Jul-2019 22:30:24

1K+ Views

To display current configuration variables, you can use show command. The syntax is as follows −show variables;You can further rewrite the above syntax with LIKE operator. The syntax is as follows −show variables like ‘%anyStringValue%’;The query is as follows displaying an example to fetch some of the configuration variables −mysql> show variables like '%max%';Output+------------------------------------------------------+----------------------+ | Variable_name                                        | Value                | +------------------------------------------------------+----------------------+ | binlog_max_flush_queue_time                         ... Read More

BOOLEAN or TINYINT to store values in MySQL?

Chandu yadav
Updated on 30-Jul-2019 22:30:24

493 Views

The MySQL BOOLEAN and BOOL both are equivalent to TINYINT(1). Whenever you create a column using BOOLEAN and BOOL data type, MySQL implicitly convert the BOOLEAN and BOOL to TINYINT(1). The BOOLEAN and BOOL are equivalents of TINYINT(1), since they are synonyms.Create a table using BOOLEAN data type. The query to create a table.mysql> create table BooleanDemo    -> (    -> IsOn BOOLEAN    -> ); Query OK, 0 rows affected (0.58 sec)Now check internal structure of the above table. The query is as follows −mysql> show create table BooleanDemo;Output+-------------+----------------------------------------------------------------------------------------------------------------------------------+ | Table       | Create Table   ... Read More

How to form a MySQL Conditional Insert?

George John
Updated on 30-Jul-2019 22:30:24

2K+ Views

For this, you can insert using MySQL dual table. Let us create a table to understand the concept conditional insert. The query to create a table is as follows −mysql> create table ConditionalInsertDemo    -> (    -> UserId int,    -> TotalUser int,    -> NumberOfItems int    -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into ConditionalInsertDemo values(101, 560, 780); Query OK, 1 row affected (0.19 sec) mysql> insert into ConditionalInsertDemo values(102, 660, 890); Query OK, 1 row affected (0.20 sec) ... Read More

What is the difference between MySQL BOOL and BOOLEAN column data types?

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

951 Views

BOOL and BOOLEAN both acts like TINYINT(1). You can say that both are synonyms for TINYINT(1).BOOLEANHere is an example of BOOLEAN. The query to create a table with column boolean type.mysql> create table Demo -> ( -> isVaidUser boolean -> ); Query OK, 0 rows affected (1.08 sec)The query to insert records in the table using insert command is as follows −mysql> insert into Demo values(true); Query OK, 1 row affected (0.19 sec) mysql> insert into Demo values(0); Query OK, 1 row affected (0.17 sec)Display all values from the table ... Read More

How to format number to 2 decimal places in MySQL?

George John
Updated on 19-Mar-2023 12:06:46

3K+ Views

You can use TRUNCATE() function from MySQL to format number to 2 decimal places. The syntax is as follows −SELECT TRUNCATE(yourColumnName, 2) as anyVariableName from yourTableName;To understand the above syntax, let us first create a table. The query to create a table is as follows −mysql> create table FormatNumberTwoDecimalPlace    -> (    -> Number float    -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into FormatNumberTwoDecimalPlace values(123.456); Query OK, 1 row affected (0.13 sec) mysql> insert into FormatNumberTwoDecimalPlace values(1.6789); Query OK, 1 ... Read More

Advertisements