Found 4381 Articles for MySQL

What is unsigned in MySQL?

George John
Updated on 25-Jun-2020 07:49:07

2K+ Views

Unsigned allows us to enter positive value; you cannot give any negative number. Let us create a table to understand unsigned in MySQL. To create a table, we will use the CREATE command.Let us create a table −mysql> CREATE table UnsignedDemo -> ( -> id int unsigned -> ); Query OK, 0 rows affected (0.61 sec)After that I will insert only positive values. Let us insert some records −mysql> INSERT into UnsignedDemo values(124); Query OK, 1 row affected (0.09 sec) mysql> INSERT into UnsignedDemo values(78967); Query OK, 1 row affected (0.14 sec)I am displaying all the records with the ... Read More

How do I get the current AUTO_INCREMENT value for a table in MySQL?

Chandu yadav
Updated on 25-Jun-2020 07:50:02

7K+ Views

To know the current auto_increment value, we can use the last_insert_id() function. Firstly, we will create a table with the help of INSERT command.Creating a table −mysql> CREATE table AutoIncrement -> ( -> IdAuto int auto_increment, -> primary key(IdAuto) -> ); Query OK, 0 rows affected (0.59 sec)After creating a table, we will insert the records with the help of INSERT command. Inserting records −mysql> INSERT into AutoIncrement values(); Query OK, 1 row affected (0.48 sec) mysql> INSERT into AutoIncrement values(); Query OK, 1 row affected (0.17 sec) mysql> INSERT into AutoIncrement values(); Query OK, 1 row affected ... Read More

How do I set the timezone of MySQL?

Ankith Reddy
Updated on 25-Jun-2020 07:50:31

705 Views

To know the current time, we can use the now() function with SELECT statement. The query is as follows −mysql> SELECT now();After executing the above query, we will get the current time. The following is the output −+---------------------+ | now() | +---------------------+ | 2018-10-06 12:57:25 | +---------------------+ 1 row in set (0.02 sec)To set the time zone, we can use the command SET. The syntax is as follows −mysql> SET time_zone = "Some value"; Now I am applying the above query to set the time zone. ... Read More

How to use NULL in MySQL SELECT statement?

Arjun Thakur
Updated on 25-Jun-2020 07:51:12

1K+ Views

In MySQL, the length of NULL is 0. Here, we will see how NULL can be used with SELECT statement. Let us create a table with the help of CREATE command −Creating a table −mysql> CREATE table NullWIthSelect -> ( -> Name varchar(100) -> ); Query OK, 0 rows affected (0.62 sec)Above, I have created a table successfully. Now I will insert some records with the help of INSERT command −Inserting records −mysql> INSERT into NullWIthSelect values('John'); Query OK, 1 row affected (0.16 sec) mysql> INSERT into NullWIthSelect values('Bob'); Query OK, 1 row affected (0.12 sec) mysql> INSERT ... Read More

Difference between Schema and Database in MySQL?

George John
Updated on 24-Jun-2020 14:07:57

5K+ Views

In MySQL, schema is synonymous with database. As the query is written to create the database, similarly the query can be written to create the schema.Logical structure can be used by the schema to store data while memory component can be used by the database to store data. Also, a schema is collection of tables while a database is a collection of schema.To clarify this concept, a database and a schema are created. The steps for this are as follows −First, a database is created with the following syntax −create database yourDatabaseName;The above syntax is used in a query as ... Read More

How can I stop running a MySQL query?

Chandu yadav
Updated on 24-Jun-2020 14:09:41

1K+ Views

Before stopping a running query of MySQL, first we need to see how many processes are running with the help of show command.The query for that is given as follows −mysql> show processlist;After executing the above query, we will get the output with some id’s. This is given as follows −+----+-----------------+-----------------+----------+---------+-------+------------------------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+-----------------+-----------------+----------+---------+-------+------------------------+------------------+ | 4 | event_scheduler | localhost | NULL | Daemon | 71034 | Waiting on empty queue | NULL | | 8 | Manish | localhost:53496 | business | Query | ... Read More

How can I find non-ASCII characters in MySQL?

Ankith Reddy
Updated on 24-Jun-2020 14:10:12

2K+ Views

Non ASCII characters are characters such as the pound symbol(£), trademark symbol, plusminus symbol etc. To find the non-ASCII characters from the table, the following steps are required −First a table is created with the help of the create command which is given as follows −mysql> CREATE table NonASciiDemo -> ( -> NonAScii varchar(100) -> ); Query OK, 0 rows affected (0.61 sec)After that the records are inserted into the table with the help of the insert command which is as follows −mysql> INSERT into NonASciiDemo values('-, -'); Query OK, 1 row affected (0.18 sec) mysql> INSERT into NonASciiDemo ... Read More

Which one is better to insert NULL or empty string in MySQL?

Arjun Thakur
Updated on 24-Jun-2020 14:10:49

2K+ Views

In innoDB, NULL occupies less space as compared to empty string. Also, the NULL length is null while length of the empty string is 0.To understand this, a table is created with the help of create command which is given as follows −mysql> CREATE table DemoEmptyAndNULL -> ( -> Message varchar(100) -> ); Query OK, 0 rows affected (0.49 sec)After creating the table successfully, an empty record is inserted into the table with the help of insert command which is as follows −mysql> INSERT into DemoEmptyAndNULL values(' '); Query OK, 1 row affected (0.17 sec)After inserting the record, we can ... Read More

How do I check if a column is empty or null in MySQL?

George John
Updated on 02-Sep-2023 15:49:47

48K+ Views

To check if a column is empty or null , we can use the WHERE clause with IS NULL and for empty we can use the condition ' ' i.e., empty space. The steps required for this are as folllows: First a table is created with the help of CREATE command as follows −mysql> CREATE table ColumnValueNullDemo -> ( -> ColumnName varchar(100) -> ); Query OK, 0 rows affected (0.61 sec)An empty value is inserted into the table using INSERT command. This is given below −mysql> INSERT into ColumnValueNullDemo values(' '); Query OK, 1 row affected (0.14 sec)After that, the ... Read More

Find records from one MySQL table which don't exist in another?

Chandu yadav
Updated on 24-Jun-2020 14:12:31

782 Views

To find the records from one MySQL table which don’t exist in another table we can use the subquery for the table which does not have the records. This can be better understood using the given steps −First a table is created using the create command. The table name is ‘PresentHistory’ and it has two columns. This is given as follows −mysql> CREATE table PresentHistory -> ( -> HisID int, -> HisName varchar(100) -> ); Query OK, 0 rows affected (0.54 sec)After creating the table, some records are inserted that will be present in the second table as well. This ... Read More

Advertisements