Found 4219 Articles for MySQLi

How to update data in a MySQL database with Java?

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

2K+ Views

To update data into a MySQL database table, use UPDATE command. The syntax is as follows −update yourTableName set yourColumnName1 = value1, ....N where condition;First, we need to create a table. The query is as follows −mysql> create table UpdateDemo    -> (    -> id int,    -> Name varchar(200) -> ); Query OK, 0 rows affected (0.67 sec)Let us insert records into the table. The following is the query −mysql> insert into UpdateDemo values(101, 'John'); Query OK, 1 row affected (0.19 sec) mysql> truncate table UpdateDemo; Query OK, 0 rows affected (0.86 sec) mysql> insert ... Read More

How to delete data in a MySQL database with Java?

Arjun Thakur
Updated on 26-Jun-2020 16:58:25

4K+ Views

Delete data from a MySQL database with the help of DELETE command. The syntax is as follows.delete from yourTableName where condition;I will delete data from a MySQL database with the help of JAVA programming language. First, create a table and insert some records. The following is the query to create a table.mysql> create table DeleteTableDemo    -> (    -> id int,    -> Name varchar(200)    -> ); Query OK, 0 rows affected (0.94 sec)Insert records in the above table. The query to insert records is as follows.mysql> insert into DeleteTableDemo values(101, 'Smith'); Query OK, 1 row affected (0.21 ... Read More

How to get the size of the tables of a MySQL database?

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

280 Views

To get the size of the tables of a MySQL database, you can use the “information_schema.tables”. Here is the syntax to know the size of all tables. SELECT TABLE_NAME AS `ALLTABLESNAME`, ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `TABLESIZEIN(MB)` FROM information_schema.TABLES WHERE TABLE_SCHEMA = "yourDatabaseName" ORDER BY (DATA_LENGTH + INDEX_LENGTH) ASC; Let us apply the above syntax to get the size of the tables. mysql> SELECT TABLE_NAME AS `ALLTABLESNAME`, ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `TABLESIZEIN(MB)` -> FROM information_schema.TABLES WHERE TABLE_SCHEMA = "business" ... Read More

How to get a list of MySQL indexes?

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

375 Views

Let us first see how we can display an index from MySQL. For that, use the SHOW command. The query to show an index is as follows − mysql> SHOW INDEX FROM indexingdemo; Here is the output. +--------------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | +--------------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+ | indexingdemo | 1 | indexName | ... Read More

What is the benefit of zerofill in MySQL?

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

2K+ Views

ZEROFILL pads the displayed value of the field with zeros up to the display width set in the column definition. Let us understand the role of zero fill in MySQL using an example. Creating a table with two columns, one has zerofill and the second one does not. The query to create a table. mysql> create table ZeroFillDemo -> ( -> First int(18) zerofill, -> Second int(18) -> ); Query OK, 0 rows affected (0.63 sec) We can insert records in the table with the help ... Read More

Remove Primary Key in MySQL?

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

6K+ Views

To remove primary key in MySQL, use tje drop primary key command. To understand the concept, let us create a table with column as primary key. mysql> create table PrimaryKeyDemo -> ( -> id int not null, -> Primary key(id) -> ); Query OK, 0 rows affected (0.60 sec) Let us check the description of the table with the help of DESC command. The query is as follows. mysql> desc PrimaryKeyDemo; The following is the output. +-------+---------+------+-----+---------+-------+ | Field | Type ... Read More

How do I modify a MySQL column to allow NULL?

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

4K+ Views

For our example, let us create a table with NOT NULL constraint. After that, we will modify a column to allow NULL. The following is the query to create a table with NOT NULL constraint. mysql> create table AllowNullDemo -> ( -> id int not null -> ); Query OK, 0 rows affected (0.48 sec)= Insert records with the help of INSERT command. The query is as follows. mysql> insert into AllowNullDemo values(); Query OK, 1 row affected, 1 warning (0.19 sec) mysql> insert into AllowNullDemo values(); ... Read More

How to disable ONLY_FULL_GROUP_BY in MySQL?

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

1K+ Views

You can enable ONLY_FULL_GROUP_BY in MySQL as shown in the following query − mysql> SET sql_mode = 'ONLY_FULL_GROUP_BY'; Query OK, 0 rows affected (0.01 sec) As shown above, we can enable ONLY_FULL_GROUP_BY with the help of SET command. To disable ONLY_FULL_GROUP_BY with the help of the following query − mysql> SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); Query OK, 0 rows affected (0.04 sec) We have disabled ONLY_FULL_GROUP_BY successfully.

MySQL's DESCRIBE command?

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

8K+ Views

The MySQL’s DESCRIBE or DESC both are equivalent. The DESC is the short form of DESCRIBE command and used to dipslay the information about a table like column names and constraints on column name. The DESCRIBE command is equivalent to the following command − SHOW columns from yourTableName command. The following is the query that display information about a table with the help of DESCRIBE command. The query is as follows. mysql> DESCRIBE Student; Above, Student is the table name in my database. The above query generates the following output. +-------+--------------+------+-----+---------+-------+ | Field | Type ... Read More

How to get a list of MySQL user accounts?

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

114 Views

To get the list of MySQL user accounts, we can use “SELECT USER”. The following is the query to display the list. SELECT User FROM mysql.user; Here is the output. +------------------+ | User | +------------------+ | John | | Mac | | Manish | | mysql.infoschema | | mysql.session ... Read More

Advertisements