Browsed by
Tag: Updated Interview Questions Answers on MySQL

What is REGEXP?

What is REGEXP?

REGEXP is a pattern match using a regular expression. The regular expression is a powerful way of specifying a pattern for a sophisticated search. Basically, it is a special text string for describing a search pattern. To understand it better, you can think of a situation of daily life when you search for .txt files to list all text files in the file manager. The regex equivalent for .txt will be .*\.txt.

What are the differences between MySQL_fetch_array(), MySQL_fetch_object(), MySQL_fetch_row()?

What are the differences between MySQL_fetch_array(), MySQL_fetch_object(), MySQL_fetch_row()?

Mysql_fetch_object is used to retrieve the result from the database as objects, while mysql_fetch_array returns result as an array. This will allow access to the data by the field names. For example: Using mysql_fetch_object field can be accessed as $result->name. Using mysql_fetch_array field can be accessed as $result->[name]. Using mysql_fetch_row($result) where $result is the result resource returned from a successful query executed using the mysql_query() function. Example: $result = mysql_query(“SELECT * from students”); while($row = mysql_fetch_row($result)) { Some statement; }

How to returns the columns and column information pertaining to the designated table

How to returns the columns and column information pertaining to the designated table

mysql> show columns from tablename; In MySQL, you can use the DESCRIBE statement or the SHOW COLUMNS statement to retrieve information about the columns of a table. Both commands provide details about the structure of a table. DESCRIBE statement: sql DESCRIBE your_table_name; Example: sql DESCRIBE employees; SHOW COLUMNS statement: sql SHOW COLUMNS FROM your_table_name; Example: sql SHOW COLUMNS FROM employees; Both of these commands will return information about the columns, such as the column name, data type, whether it allows…

Read More Read More

How to add columns in MySQL?

How to add columns in MySQL?

A column is a series of cells in a table that stores one value for each row in a table. We can add columns in an existing table using the ALTER TABLE statement as follows: ALTER TABLE table_name ADD COLUMN column_name column_definition [FIRST|AFTER existing_column]; To add columns to an existing table in MySQL, you can use the ALTER TABLE statement. Here’s the basic syntax: ALTER TABLE table_name ADD column_name column_definition; Replace table_name with the name of the table to which…

Read More Read More

How to execute a stored procedure in MySQL?

How to execute a stored procedure in MySQL?

We can execute a stored procedure in MySQL by simply CALL query. This query takes the name of the stored procedure and any parameters we need to pass to it. The following is the basic syntax to execute a stored procedure: CALL stored_procedure_name (argument_list); Let’s understand it with this example: CALL Product_Pricing (@pricelow, @pricehigh); Here, a stored procedure named Product_Pricing calculates and returns the lowest and highest product prices.

What is BLOB and TEXT in MySQL?

What is BLOB and TEXT in MySQL?

BLOB is an acronym that stands for a large binary object. It is used to hold a variable amount of data. There are four types of the BLOB. TINYBLOB BLOB MEDIUMBLOB LONGBLOB The differences among all these are the maximum length of values they can hold. TEXT is a case-insensitive BLOB. TEXT values are non-binary strings (character string). They have a character set, and values are stored and compared based on the collation of the character set. There are four…

Read More Read More

How many columns can you create for an index?

How many columns can you create for an index?

You can a create maximum of 16 indexed columns for a standard table. In MySQL, you can create an index with up to 16 indexed columns. This means you can include up to 16 columns in a single index definition. However, keep in mind that creating an index with too many columns might not always be optimal for performance and can lead to increased storage requirements. So, it’s essential to consider your specific use case and indexing strategy when deciding…

Read More Read More

What is the use of mysql_close()?

What is the use of mysql_close()?

Mysql_close() cannot be used to close the persistent connection. However, it can be used to close a connection opened by mysql_connect(). In MySQL, the mysql_close() function is used to close the connection to the MySQL server that was previously opened with mysql_connect() or mysql_pconnect() functions. When you no longer need to access the database, it’s good practice to close the connection to free up system resources and avoid leaving connections open unnecessarily, especially in environments with a limited number of…

Read More Read More

MySQL Interview Questions – Set 01

MySQL Interview Questions – Set 01

Syntax and Queries MySQL Commands: Show databases; Create database db_name; Use dbname; Show tables; Create table tb_name(id int, name varchar(20)); Desc tb_name; Insert into tb_name values(101 , ‘name of person’); Insert into tb_name (id) values(102); Update tb_name set name=’person name’ where id=102; Select * from tb_name; Delete from tb_name where id=102; Drop table tb_name; Drop database db_name; Rename table tb_old_name to tb_new_name; Alter table customer add (remark varchar(20)); Alter table customer modify remark varchar(25); Alter table customer modify remark varchar(20);…

Read More Read More

How you will Show all records not containing the name “sonia” AND the phone number ‘9876543210’ order by the phone_number field

How you will Show all records not containing the name “sonia” AND the phone number ‘9876543210’ order by the phone_number field

mysql> SELECT * FROM tablename WHERE name != “sonia” AND phone_number = ‘9876543210’ order by phone_number; To retrieve all records not containing the name “sonia” and the phone number ‘9876543210’ from a MySQL table, and order the results by the phone_number field, you can use the following SQL query: sql SELECT * FROM your_table_name WHERE name != ‘sonia’ AND phone_number != ‘9876543210’ ORDER BY phone_number; Replace your_table_name with the actual name of your table. This query selects all columns (*)…

Read More Read More