Found 4219 Articles for MySQLi

How Can MySQL virtual GENERATED COLUMNS work with built-in functions?

Ayyan
Updated on 21-Feb-2020 11:39:09

202 Views

It can be illustrated with the help of an example in which we are creating a virtual generated column in the table named ‘employee_data’. As we know that virtual generated column can be generated with or without using the keyword ‘virtual’.Examplemysql> Create table employee_data(ID INT AUTO_INCREMENT PRIMARY KEY,        First_name VARCHAR(50) NOT NULL, Last_name VARCHAR(50) NOT NULL,        FULL_NAME VARCHAR(90) GENERATED ALWAYS AS(CONCAT(First_name, '', Last_name))); Query OK, 0 rows affected (0.55 sec) mysql> DESCRIBE employee_data; +------------+-------------+------+-----+---------+-------------------+ | Field      | Type        | Null | Key | Default | Extra     ... Read More

What are the different types of MySQL GENERATED COLUMNS?

Kumar Varma
Updated on 22-Jun-2020 14:29:07

79 Views

We have two types of MYSQL generated columns as follows −VIRTUAL GENERATED COLUMNAs the name suggests, this kind of generated column will not take any disk space. It can be generated with or without using the keyword ‘virtual’. To understand we are illustrating it in the following example −Examplemysql> Create table triangle(SideA DOUBLE, SideB DOUBLE, SideC DOUBLE AS (SQRT(SideA * SideB + SideB * SideB))); Query OK, 0 rows affected (0.44 sec) mysql> Describe Triangle; +-------+--------+------+-----+---------+-------------------+ | Field | Type   | Null | Key | Default | Extra             | +-------+--------+------+-----+---------+-------------------+ | SideA ... Read More

What is MySQL GENERATED COLUMN and how to use it while creating a table?

Lakshmi Srinivas
Updated on 22-Jun-2020 14:30:09

1K+ Views

Basically generated columns are a feature that can be used in CREATE TABLE or ALTER TABLE statements and is a way of storing the data without actually sending it through the INSERT or UPDATE clause in SQL. This feature has been added in MySQL 5.7. A generated column works within the table domain. Its syntax would be as follows −Syntaxcolumn_name data_type [GENERATED ALWAYS] AS (expression) [VIRTUAL | STORED] [UNIQUE [KEY]]Here, first of all, specify the column name and its data type.Then add the GENERATED ALWAYS clause to indicate that the column is a generated column.Then, indicate whether the type of ... Read More

How can we write PHP script to get the list of MySQL database?

Priya Pallavi
Updated on 22-Jun-2020 14:31:14

1K+ Views

We can write the following PHP script to get the list of available MySQL databases −Example

How can we write PHP script to count the affected rows by MySQL query?

vanithasree
Updated on 22-Jun-2020 14:30:45

269 Views

PHP uses mysql_affected_rows( ) function to find out how many rows a query changed. To illustrate it we are having the following example −Example           Rows affected by query                  

Which PHP function is used to give the number of rows affected by MySQL query?

Nikitha N
Updated on 22-Jun-2020 14:08:04

161 Views

PHP uses mysql_affected_rows( ) function to find out how many rows a query changed. This function basically returns the number of affected rows in the previous SELECT, INSERT, UPDATE, REPLACE, or DELETE query. Return of an integer > 0 indicates the number of rows affected, 0 indicates that no records were affected and -1 indicates that the query returned an error. Its syntax is as follows −Syntaxmysql_affected_rows( connection );Followings are the parameters used in this function −S. No.Parameter & Description1.ConnectionRequired – Specifies the MySQL connection to use

How can we create a MySQL view by using data from multiple tables?

Sharon Christine
Updated on 04-Mar-2020 06:29:22

1K+ Views

MySQL UNION operator can combine two or more result sets hence we can use UNION operator to create a view having data from multiple tables. To understand this concept we are using the base tables ‘Student_info’ and ‘Student_detail’ having the following data −mysql> Select * from Student_info; +------+---------+------------+------------+ | id   | Name    | Address    | Subject    | +------+---------+------------+------------+ | 101  | YashPal | Amritsar   | History    | | 105  | Gaurav  | Chandigarh | Literature | | 125  | Raman   | Shimla     | Computers  | | 130  | Ram     ... Read More

How can we create a MySQL temporary table by using PHP script?

radhakrishna
Updated on 22-Jun-2020 14:08:57

1K+ Views

As we know that PHP provides us the function named mysql_query() to create a MySQL table. Similarly, we can use mysql_query() function to create MySQL temporary table. To illustrate this, we are using the following example −ExampleIn this example, we are creating a temporary table named ‘SalesSummary’ with the help of PHP script in the following example −           Creating MySQL Temporary Tables              

How VIEWS can be used to emulate CHECK CONSTRAINT?

Fendadis John
Updated on 22-Jun-2020 14:16:24

63 Views

As we know that MySQL supports foreign key for referential integrity but it does not support CHECK constraint. But we can emulate them by using triggers. It can be illustrated with the help of an example given below −ExampleSuppose we have a table named ‘car1’ which can have the fix syntax registration number like two letters, a dash, three digits, a dash, two letters as follows −mysql> Create table car1 (number char(9)); Query OK, 0 rows affected (0.32 sec) mysql> Insert into car1 values('AB-235-YZ'); Query OK, 1 row affected (0.10 sec)The above value is a valid one but what ... Read More

How can I generate days from the range of dates with the help of MySQL views?

karthikeya Boyini
Updated on 22-Jun-2020 14:11:56

227 Views

To illustrate it we are creating the following views −mysql> CREATE VIEW digits AS     -> SELECT 0 AS digit UNION ALL     -> SELECT 1 UNION ALL     -> SELECT 2 UNION ALL     -> SELECT 3 UNION ALL     -> SELECT 4 UNION ALL     -> SELECT 5 UNION ALL     -> SELECT 6 UNION ALL     -> SELECT 7 UNION ALL     -> SELECT 8 UNION ALL     -> SELECT 9; Query OK, 0 rows affected (0.08 sec) mysql> CREATE VIEW numbers AS SELECT ones.digit + ... Read More

Advertisements