Database Articles

Found 5,456 articles

How to display 3 random values from MySQL table?

AmitDiwan
AmitDiwan
Updated on 12-Mar-2026 243 Views

To display random values from a MySQL table, use the RAND() function in the ORDER BY clause to shuffle the rows randomly, and LIMIT to restrict the number of results. The general syntax is − SELECT yourColumnName FROM yourTableName ORDER BY RAND() LIMIT 3; Creating the Demo Table Let us first create a table and insert some records − CREATE TABLE DemoTable646 ( Id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName VARCHAR(100) ); INSERT INTO DemoTable646 (FirstName) VALUES ('John'); INSERT INTO DemoTable646 (FirstName) VALUES ('Bob'); INSERT INTO DemoTable646 (FirstName) VALUES ...

Read More

Searching multiple columns for a row match in MySQL

AmitDiwan
AmitDiwan
Updated on 12-Mar-2026 499 Views

To search multiple columns for a row match in MySQL, you can use the UNION operator. UNION combines the result sets of two or more SELECT statements into a single result, automatically removing duplicate rows. This is useful when you want to search different columns for different criteria and merge the results together. Creating the Demo Table Let us first create a table and insert some records − CREATE TABLE DemoTable645 ( Id INT, FirstName VARCHAR(100) ); INSERT INTO DemoTable645 VALUES (100, 'Chris'); INSERT INTO DemoTable645 VALUES (101, 'Robert'); INSERT INTO DemoTable645 ...

Read More

How to convert JS date time to MySQL datetime?

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 1K+ Views

We can convert JS date time to MySQL datetime with the help of toISOString() function.Let us see an example of JavaScript.Example           Web Page Design                document.writeln(new Date().toISOString().slice(0, 19).replace('T', ' '));              Current Date is displayed above... OutputThe following is the output.2018-11-23 11:14:38 Current Date is displayed above...

Read More

Count the number of columns in a MySQL table with Java

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Jul-2025 497 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 914 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

Different Types of Database Users

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 14-Feb-2025 40K+ Views

Database users interact with data to update, read, and modify the given information daily. There are various types of database users and we will learn in detail about them. Database users can be divided into the following types − Naive users / Parametric users Sophisticated users End Users Application Programmer or Specialized users or Back-End Developer System Analyst Database Administrator (DBA) Temporary Users or Casual Users These users can access the database and recover the data using various applications. Let’s have a quick understanding of all the types in detail − End Users/Parametric Users These users access the ...

Read More

What MySQL returns if I insert invalid value into ENUM?

Venu Madhavi
Venu Madhavi
Updated on 12-Feb-2025 954 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
Showing 1–10 of 5,456 articles
« Prev 1 2 3 4 5 546 Next »
Advertisements