- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 4378 Articles for MySQL
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
2K+ Views
You can use ALTER command to remove primary key and auto_increment. The syntax is as follows −ALTER TABLE yourTableName DROP PRIMARY KEY, change yourColumnName yourColumnName data type;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table removePrimaryKey -> ( -> StudentId int NOT NULL AUTO_INCREMENT, -> StudentFirstName varchar(20), -> StudentLastName varchar(20), -> PRIMARY KEY(StudentId) -> ); Query OK, 0 rows affected (0.47 sec)Check the description of table using DESC command. The syntax is as follows −desc yourTableName;Check the description of the table ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
20K+ Views
You can add a new value to a column of data type enum using ALTER MODIFY command.If you want the existing value of enum, then you need to manually write the existing enum value at the time of adding a new value to column of data type enum.The syntax is as follows −ALTER TABLE yourTableName MODIFY COLUMN yourEnumColumnName ENUM('yourExistingValue1', 'yourExistingValue2', ........N, 'yourNewValue1', ’yourNewValue2’, .....N);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table AddingNewValueToEnumColumn -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Colors ENUM('RED', ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
323 Views
You can use ENGINE = InnoDB in place of TYPE = InnoDB, since the usage of TYPE became obsolete in MySQL version 5.1.The version we are using for our example is MySQL version 8.0.12. Let us check the MySQL version. The query is as follows −mysql> select version();The following is the output −+-----------+ | version() | +-----------+ | 8.0.12 | +-----------+ 1 row in set (0.00 sec)Here is the example of TYPE = InnoDB. Error is visible in MySQL 8 −mysql> create table Product_Information -> ( -> ProductId int, -> ProductName varchar(10), -> ProductDeliveryDate datetime ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
828 Views
To grant a user permission to only view a MySQL view, use the below syntaxGRANT SELECT ON yourDatabaseName.yourViewName TO ' yourUserName@'yourLocalHost';First you need to display all the view names from a table. The syntax is as follows −SHOW FULL TABLES IN yourDatabaseName WHERE TABLE_TYPE LIKE 'VIEW';Now implement the above syntax to display all views from a database. Here I am using the database name ‘test’. The query is as follows −mysql> SHOW FULL TABLES IN test WHERE TABLE_TYPE LIKE 'VIEW';The following is the output −+-------------------------------+------------+ | Tables_in_test | Table_type | +-------------------------------+------------+ | empidandempname_view ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
5K+ Views
Select non-empty column values using NOT IS NULL and TRIM() function. The syntax is as follows.SELECT * FROM yourTableName WHERE yourColumnName IS NOT NULL AND TRIM(yourColumnName) ' ';You can select non-empty value as well as whitespace from column using the same TRIM() function.To understand the syntax we discussed above, let us create a table. The query to create a table is as follows −mysql> create table SelectNonEmptyValues -> ( -> Id int not null auto_increment, -> Name varchar(30), -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.62 sec)Insert records in the table ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
352 Views
First, determine the type of MySQL database i.e. whether its engine is InnoDB or MyISAM. To achieve this, use engine column from the information_schema.columns.tables.The syntax is as follows.SELECT ENGINE FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ’yourDatabaseName’ AND TABLE_NAME = ’yourTableName’;Here, I have a table with the name ‘StudentInformations’ −mysql> create table StudentInformations -> ( -> StudentId int not null auto_increment, -> StudentFirstName varchar(20), -> StudentLastName varchar(20), -> Primary Key(StudentId) -> ); Query OK, 0 rows affected (0.57 sec)Now you can know the table is using InnoDB or MyISAM using the implementation of above syntax. Our ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
67 Views
You can OR two like statements using the following syntax −SELECT *FROM yourTableName WHERE (yourColumnName like '%yourValue1%' OR yourColumnNamelike '%yourValue2%') AND yourColumnName = yourValue;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table ORLikeDemo -> ( -> Id int not null auto_increment, -> FirstName varchar(15), -> LastName varchar(15), -> Primary Key(Id) -> ); Query OK, 0 rows affected (1.19 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into ORLikeDemo(FirstName, LastName) values('John', 'Smith'); Query OK, ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
10K+ Views
You can remove trailing zeros using TRIM() function. The syntax is as follows.SELECT TRIM(yourColumnName)+0 FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table removeTrailingZeroInDecimal -> ( -> Id int not null auto_increment, -> Amount decimal(5, 2), -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (1.01 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into removeTrailingZeroInDecimal(Amount) values(405.50); Query OK, 1 row affected (0.22 sec) mysql> insert into removeTrailingZeroInDecimal(Amount) values(23.05); Query OK, ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
4K+ Views
To generate serial number i.e. row count in MySQL query, use the following syntax.SELECT @yourVariableName − = @yourVariableName+1 anyAliasName, yourColumnName1, yourColumnName2, yourColumnName3, ....N from yourTableName , (select @yourVariableName − = 0) as yourVariableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table tblStudentInformation -> ( -> StudentName varchar(20), -> StudentAge int, -> StudentMathMarks int -> ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into tblStudentInformation values('Carol', ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
2K+ Views
To get the table column names in alphabetical order, you need to use ORDER BY. The syntax is as follows −SELECT anyReferenceName.COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS anyReferenceName WHERE anyReferenceName.TABLE_NAME = ’yourTableName’ ORDER BY anyReferenceName.COLUMN_NAMEFirst, we need to get all the columns and then we need to use ORDER BY. In the above query, we are getting all columns using INFORMATION_SCHEMA.COLUMNS.To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table ColumnsOrder -> ( -> StudentFirstName varchar(20), -> Id int, -> StudentAge int, -> StudentLastName varchar(20) ... Read More