MySQLi Articles

Found 3,404 articles

Count the number of columns in a MySQL table with Java

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Jul-2025 489 Views

In this article, we will learn how to count the number of columns in a MySQL table using JDBC. We will be using the ResultSetMetaData to get details of the table by using simple examples. What is ResultSetMetaData? The ResultSetMetaData is an interface that is present in the java.sql package. Using ResultSetMetaData, we can get information about the table, for example, what are the column names of each and every table, and how many columns are there?. To create the object for ResultSet: ResultSet rs=st.executeQuery("Select * from Student"); The executeQuery method writes the records, which are then stored in the ...

Read More

What is the difference between CHAR and NCHAR in MySQL?

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 19-Feb-2025 907 Views

In MySQL, both CHAR and NCHAR are ASCII character data types used for storing text data, but they differ significantly in terms of storage, data representation, and performance. CHAR and NCHAR columns can have different collations, determining how strings are compared and sorted. The CHAR type typically uses the collation associated with its specified character set. On the other hand, NCHAR is intended for Unicode data and typically uses a collation that can handle Unicode characters, ensuring proper sorting and comparison. Understanding 'CHAR' in MySQL The CHAR data type is primarily used to store ASCII character data. It is a ...

Read More

What MySQL returns if I insert invalid value into ENUM?

Venu Madhavi
Venu Madhavi
Updated on 12-Feb-2025 947 Views

If strict SQL mode is disabled and we insert an invalid value (which is not in the list of permitted enumeration values) into ENUM, MySQL will insert an empty string instead of throwing an error. If strict SQL mode is enabled, MySQL throws an error when inserting invalid value. Invalid values without strict SQL mode Strict SQL mode is disabled by default. When it is disabled, if we enter an invalid value that is not in the ENUM list, it returns an empty string. Let us understand this by using the example below. Example In the below example we have ...

Read More

Use a trigger to stop an insert or update in MySQL?

Venu Madhavi
Venu Madhavi
Updated on 12-Feb-2025 6K+ Views

The MySQL trigger can be used to automatically terminate an INSERT or UPDATE operation if specific conditions are not met. This is achieved by adding logic to the trigger to detect incorrect data or violations of a rule. If the condition is satisfied, the SIGNAL statement is used to show a customized error message and terminate the procedure. Thus, it ensures that the database has valid, clean, and consistent data. For instance, if a value is being updated or inserted in the column beyond the allowed range, the trigger can stop the action and give a customized error message. ...

Read More

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

Venu Madhavi
Venu Madhavi
Updated on 12-Feb-2025 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

Why should we not store a number into a MySQL ENUM column?

Venu Madhavi
Venu Madhavi
Updated on 12-Feb-2025 1K+ Views

MySQL stores ENUM values internally as integer keys (index numbers) to reference ENUM members. The main reason for not storing the integer values in the ENUM column is that it is very obvious that MySQL ends up referencing the index instead of the value and vice-versa. These indexes begin at 1, not 0, and map to the order of the values defined during table creation. If a number is inserted directly into an ENUM column, MySQL interprets it as the corresponding index, leading to unexpected behavior. Example Let us create a table named Enmtest ...

Read More

Select records with ACTIVE status in MySQL set with ENUM

Venu Madhavi
Venu Madhavi
Updated on 04-Feb-2025 1K+ Views

MySQL's ENUM data type is used to define a specific set of values in a column making it easier to manage and maintain data consistency. GROUP BY and WHERE() function In MySQL WHERE clause is used to filter the rows based on a condition before grouping them. The GROUP BY clause groups rows with identical values in specified columns, and can be used with functions like SUM, COUNT, and AVG. Together they enable focused data analysis by filtering and grouping efficiently. Syntax Following is the syntax to filter the data on certain conditions and to eliminate duplicate records. SELECT column1, ...

Read More

MySQL query to select ENUM(\\\'M\\\', \\\'F\\\') as \\\'Male\\\' or \\\'Female\\\'?

Venu Madhavi
Venu Madhavi
Updated on 04-Feb-2025 2K+ Views

In MySQL, the ENUM data type is used to limit column values to a specified set of options which is useful for categories like colors, status, and gender. Sometimes, it is helpful to display these ENUM values as more descriptive like converting 'P' to "pass" and 'F' to "Fail". The IF() function in MySQL makes this easy by allowing conditional logic within SQL queries. The example below will demonstrate how to use the IF() function to convert ENUM values into user-friendly. Example To understand first let us create a table, DemoTable, which contains an ENUM column UserGender to store ...

Read More

In which order MySQL will invoke the triggers if we created multiple triggers of same event and action time?

Venu Madhavi
Venu Madhavi
Updated on 04-Feb-2025 616 Views

In MySQL, triggers allow automatic execution of specified actions in response to INSERT, UPDATE or DELETE events on a table. Often, multiple triggers may be created for the same event and action time (e.g.; multiple BEFORE INSERT triggers on the same table). By default, MySQL invokes these triggers in the order they have created. However, the FOLLOWS and PRECEDES option allows control over the sequence of execution which can be critical in complex data handling. In this article, we will explore how to set the order of multiple triggers for the same event and action ...

Read More

How to show that each MySQL enumeration has an index value?

Venu Madhavi
Venu Madhavi
Updated on 04-Feb-2025 614 Views

In MySQL, the ENUM data type enables you to define a column using only a collection of predetermined values. Each value in the ENUM list is assigned a position number known as an index (which begins with 1). These index numbers represent the positions of the values in the list, not the actual data. For example, if the ENUM list is ('Male', 'Female', 'Other'), Male has an index of 1 while Female has an index of 2 and Other will have an index of 3. This further enables MySQL to store and compare the values more effectively, though actual ...

Read More
Showing 1–10 of 3,404 articles
« Prev 1 2 3 4 5 341 Next »
Advertisements