Found 4381 Articles for MySQL

How can we use MySQL REPLACE statement to prevent of insertion of duplicate data?

varun
Updated on 22-Jun-2020 13:26:43

454 Views

We can use the REPLACE statement while inserting the data to prevent the insertion of duplicate data. If we will use the REPLACE command rather than the INSERT command then if the record is new, it is inserted just as with INSERT else if it is a duplicate, the new record replaces the old one.SyntaxREPLACE INTO table_name(…)Here,  table_name is the name of the table in which we want to insert the values.ExampleIn this example we will insert the data with the help of REPLACE statement as follows −mysql> REPLACE INTO person_tbl (last_name, first_name)     -> VALUES( 'Ajay', 'Kumar'); Query OK, ... Read More

How can we get the total number of rows affected by MySQL query?

Prabhas
Updated on 22-Jun-2020 13:27:10

4K+ Views

MySQL ROW_COUNT() can be used to get the total number of rows affected by MySQL query. To illustrate it we are creating a procedure with the help of which we can insert records in a table and it will show us how many rows have been affected.Examplemysql> Delimiter // mysql> CREATE PROCEDURE `query`.`row_cnt` (IN command VarChar(60000))     -> BEGIN     ->    SET @query = command;     ->    PREPARE stmt FROM @query;     ->    EXECUTE stmt;     ->    SELECT ROW_COUNT() AS 'Affected rows';     -> END // Query OK, 0 rows ... Read More

How can I delete MySQL temporary table?

V Jyothi
Updated on 22-Jun-2020 13:07:23

634 Views

As we know that MySQL temporary table would be deleted if the current session is terminated. But of still in between the session we want to delete the temporary table than with the help of the DROP statement we can delete the temporary table. It can be understood with the help of the following example −ExampleIn this example, we are deleting the temporary table named ‘SalesSummary’ −mysql> DROP TABLE SalesSummary; Query OK, 0 rows affected (0.00 sec)The above query will delete the table and it can be confirmed from the query below −mysql> Select * from SalesSummary; ERROR 1146 (42S02): ... Read More

What happens to MySQL temporary tables if MySQL session is ended?

seetha
Updated on 30-Jul-2019 22:30:21

159 Views

Temporary table would be deleted if MySQL session terminates. After login again, on issuing the SELECT command we will find no data available in the database. Even our temporary table will not exist.

How can we create MySQL views with column list?

Anjana
Updated on 22-Jun-2020 13:06:25

261 Views

As we know that while creating a view, providing the list of columns is optional. But if we are providing the name of the columns while creating the view then the number of names in the list of columns must be the same as the number of columns retrieved by the SELECT statement.ExampleThe following example will illustrate by creating the views with column list −mysql> Select * from student_detail; +-----------+-------------+------------+ | Studentid | StudentName | address    | +-----------+-------------+------------+ | 100       | Gaurav      | Delhi      | | 101       | Raman ... Read More

How can we create a MySQL view based on another existing view?

George John
Updated on 22-Jun-2020 13:07:56

475 Views

In MySQL, we can create a view that is based on another existing view. To make it understand we are having the view ‘Info’ with the following data −mysql> Create view info AS Select Id, Name, Subject FROM student_info; Query OK, 0 rows affected (0.11 sec) mysql> Select * from Info; +------+---------+------------+ | Id | Name | Subject | +------+---------+------------+ | 101 | YashPal | History | | 105 | Gaurav | Literature | | 125 | Raman | Computers | | NULL | Ram | Computers | +------+---------+------------+ 4 rows in set (0.00 sec)Now, with the help of ... Read More

How can we see MySQL temporary tables in the list of tables?

Priya Pallavi
Updated on 22-Jun-2020 13:10:17

295 Views

As we know that we can see the list of tables in a database with the help of SHOW TABLES statement. But MySQL temporary tables are not stored in this list or in other words we can say that we cannot see the temporary tables with the help of SHOW TABLES statement. To illustrate it we are using the following example −ExampleIn this example, we are trying to get the temporary table named ‘SalesSummary’ from SHOW TABLES statement as follows −mysql> SHOW TABLES LIKE '%Sales%'; Empty set (0.00 sec) mysql> SHOW TABLES LIKE '%SalesSummary%'; Empty set (0.00 sec)The above ... Read More

How can we create MySQL views without any column list?

Samual Sam
Updated on 22-Jun-2020 13:09:29

182 Views

While creating a view, providing the list of columns is optional. The following example will illustrate by creating the views without any column list −mysql> Select * from student_detail; +-----------+-------------+------------+ | Studentid | StudentName | address    | +-----------+-------------+------------+ |       100 | Gaurav      | Delhi      | |       101 | Raman       | Shimla     | |       103 | Rahul       | Jaipur     | |       104 | Ram         | Chandigarh | |     ... Read More

What are the different privileges required for using views?

Lakshmi Srinivas
Updated on 22-Jun-2020 13:20:14

179 Views

Following privileges are required for a different kind of CREATE, REPLACE, DROP, ACCESS, UPDATE etc. of usage of views − CREATE VIEW Privilege − CREATE VIEW privilege is required to create a view. Along with this we must have sufficient privileges, like SELECT, INSERT or UPDATE, for accessing the tables to which the view definition refers. DROP VIEW Privilege − We require DROP VIEW privileges for using OR REPLACE clause, DROP VIEW statement and also for using ALTER VIEW statement. SELECT Privilege − We must have SELECT privileges for selecting from a view. INSERT, DELETE or UPDATE Privileges − Actually for an updateable view ... Read More

What are the prerequisites before starting writing and using MySQL views?

Arjun Thakur
Updated on 22-Jun-2020 12:56:03

242 Views

MySQL VersionAs we know that MySQL 5 introduced views, hence, first of all, we need to check for the version of MySQL before starting writing and using stored procedures. It can be done with the following query −mysql> Select VERSION(); +-----------+ | VERSION() | +-----------+ | 5.7.20    | +-----------+ 1 row in set (0.10 sec)Privileges for current userActually CREATE VIEW statement requires the CREATE VIEW privilege. Privileges for the current user can be checked with the following query −mysql> SHOW PRIVILEGESSelecting a databaseBefore creating a view we must have to select a database from the available databases. It can ... Read More

Advertisements