
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 4381 Articles for MySQL

298 Views
MySQL LAST_INSERT_ID() function is used to obtain the most recent generated sequence number by AUTO_INCREMENT.ExampleIn this example, we are creating a table named ‘Student’ having an AUTO_INCREMENT column. We insert two values in the column ‘Name’ and when we use INSERT_LAST_ID() function then it returns the most recent generated sequence number i.e. 2.mysql> Create table Student(Id INT PRIMARY KEY NOT NULL AUTO_INCREMENT, Name Varchar(5)); Query OK, 0 rows affected (0.13 sec) mysql> Insert into student(Name) Values('Raman'); Query OK, 1 row affected (0.06 sec) mysql> Insert into student(Name) Values('Rahul'); Query OK, 1 row affected (0.07 sec) mysql> Select* ... Read More

1K+ Views
With the help of INSERT INTO command, a new row can be inserted into a table.SyntaxINSERT INTO table_name values(value1, value2, …)ExampleSuppose we have a table named ‘Employee’ with three columns ‘Emp_id’, ‘Emp_name’ and ‘Emp_Sal’ then with the help of following query we can add new rows to the table −mysql> INSERT INTO Employee values(110, 'Aarav', 50000); Query OK, 1 row affected (0.07 sec) mysql> INSERT INTO Employee values(200, 'Raman', 28000); Query OK, 1 row affected (0.10 sec) mysql> Select * from Employee; +---------+-------------+-----------+ | Emp_id | Emp_name | Emp_sal | +---------+-------------+-----------+ | 110 |Aarav ... Read More

473 Views
For inserting data into a MySQL table we need to use INSERT INTO command. We must have to specify values for all the columns of the table in INSERT INTO command.SyntaxINSERT INTO table_name values(value1, value2, …)ExampleSuppose we have a table named ‘Student’ with three columns ‘RollNo’, ‘Name’ and ‘Class’ then with the help of following query we can add new rows to the table −mysql> INSERT INTO Student values(50, 'Harshit', ’B.tech’); Query OK, 1 row affected (0.07 sec) mysql> INSERT INTO Student values(56, 'Amit', ’M.tech’); Query OK, 1 row affected (0.05 sec) mysql> Select * from Student; +---------+-------------+-----------+ ... Read More

1K+ Views
We can use either TRUNCATE statement or DROP statement to delete all the rows from the table. It can also be done with the help of DELETE statement but in that case WHERE clause must identify all the rows of the table. As we know that both TRUNCATE and DELETE statement will not delete the structure of the table but still it is better to use TRUNCATE statement rather than DELETE statement. DROP statement will delete table’s structure also. Syntax TRUNCATE statement TRUNCATE table table_name: Syntax DROP statement DROP table table_name:

475 Views
MySQL will automatically assign sequence numbers to the AUTO_INCREMENT column even if we insert NULL, 0 or No Value to the column in a table.Examplemysql> create table test123(id INT PRIMARY KEY NOT NULL AUTO_INCREMENT, Name Varchar(10)); Query OK, 0 rows affected (0.15 sec)The query above created a MySQL table named ‘test123’ with columns named ‘id’ and ‘Name’. The column ‘id’ is declared AUTO_INCREMENT. Now, if we insert ‘No Value’, ‘0’ or ‘NULL’ in the ‘Name’ column, MySQL will assign the sequence numbers to column ‘id’. It can be seen from the result queries below −mysql> Insert Into test123(Name) values(''), ('0'), ... Read More

953 Views
MySQL defines NCHAR as a way to indicate that a CHAR column should use predefined character set. Utf8 is used by MySQL as its predefined character set.ExampleIn the example below, we are creating a table named ‘Student1’. In this table, we are declaring the data types of three columns with three different declaration styles which are rather equivalent of each other. It is all due to NCHAR.mysql> Create table Student1(Name Char(10) character set utf8, Address NATIONAL CHARACTER(10), FatherName NCHAR(10)); Query OK, 0 rows affected (0.25 sec)Now on checking the status of table, with the help of query below, we ... Read More

210 Views
On specifying a CHARACTER SET binary attribute for a character string data type, MySQL creates that column as its subsequent binary string type. The conversions for CHAR, VARCHAR and BLOB data types take place as follows −CHAR would become BINARYVARCHAR would become VARBINARYTEXT would become BLOBThe above kind of conversion does not occur for ENUM and SET data type and they both are created as declared while creating the table.ExampleIn the example below we have created a table named ‘EMP’ with four columns all specified as CHARACTER SET binary as follows −mysql> Create table Emp(Name varchar(10) CHARACTER SET binary, Address ... Read More

171 Views
With the help of the following MySQL query we can check the character sets of all the tables in a particular database −mysql> Select Column_name, TABLE_NAME, CHARACTER_SET_NAME FROM INFORMATION_SCHEMA.Columns Where TABLE_SCHEMA = 'db_name';ExampleFor example, the query below returns the character sets of all the tables along with the column names in a database named ‘Alpha’.mysql> Select Column_name 'Column', TABLE_NAME, CHARACTER_SET_NAME FROM INFORMATION_SCHEMA.Columns Where TABLE_SCHEMA = 'Alpha'; +---------+------------+--------------------+ | Column | TABLE_NAME | CHARACTER_SET_NAME | +---------+------------+--------------------+ | Name | employee | latin1 | | email | employee ... Read More

2K+ Views
With the help of the following MySQL query we can check the character sets of all the tables in a particular database −mysql> Select TABLE_NAME, CHARACTER_SET_NAME FROM INFORMATION_SCHEMA.Columns Where TABLE_SCHEMA = 'db_name';ExampleFor example, the query below returns the character sets of all the tables in a database named ‘Alpha’.mysql> Select TABLE_NAME, CHARACTER_SET_NAME FROM INFORMATION_SCHEMA.Columns Where TABLE_SCHEMA = 'Alpha'; +------------+--------------------+ | TABLE_NAME | CHARACTER_SET_NAME | +------------+--------------------+ | employee | latin1 | | employee | latin1 | | student | latin1 ... Read More

7K+ Views
We can use DELETE statement along with a WHERE clause, which identifies those multiple rows, to delete multiple rows from MySQL table.Examplemysql> Select * from names; +------+-----------+ | id | name | +------+-----------+ | 1 | Rahul | | 2 | Gaurav | | 3 | Raman | | 5 | Ram | +------+-----------+ 4 rows in set (0.00 sec) mysql> DELETE from names WHERE id > 2; Query OK, 2 rows affected (0.04 sec)The query above will delete multiple rows because WHERE clause identify two rows having id > 2 from table ‘names’.mysql> Select * from names; +------+-----------+ | id | name | +------+-----------+ | 1 | Rahul | | 2 | Gaurav | +------+-----------+ 2 rows in set (0.00 sec)