- 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 6702 Articles for Database
![Rishi Rathor](https://www.tutorialspoint.com/assets/profiles/13563/profile/60_89283-1512714754.jpg)
590 Views
Use DATEDIFF() function from MySQL to get the difference between two timestamps in days.The syntax is as follows −select datediff(yourColumnName1, yourColumnName2) as anyVariableName from yourTableName;To understand the above syntax, let us create a table. The following is the query to create a table −mysql> create table DifferenceTimestamp −> ( −> IssueTime timestamp, −> DueTime timestamp −> ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table with the help of insert command. We are setting dates here. The query is as follows −mysql> insert into ... Read More
![Jennifer Nicholas](https://www.tutorialspoint.com/assets/profiles/13569/profile/60_88876-1512715262.jpg)
441 Views
Increase the varchar size of an existing column in a database with the help of CHANGE command. The syntax is as follows −alter table yourTableName change yourColumnName yourColumnName dataType;Here, we are creating a table with a single column and varchar size 200 −mysql> create table IncreaseVarcharDemo −> ( −> StudentId varchar(200) −> ); Query OK, 0 rows affected (0.60 sec)Now insert record in the table. The query is as follows −mysql> insert into IncreaseVarcharDemo values('John123'); Query OK, 1 row affected (0.16 sec)Displaying all records from the table with the help of the following query −mysql> select *from ... Read More
How to resolve the error that occurs while using a reserved word as a table or column name in MySQL?
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
995 Views
This error occurs when you try to use a reserved word as a table or column name. It can occur due to −Case 1: Whenever you use reserved word as a table name −mysql> create table insert −> ( −> Id int −> );The error is as follows −ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'insert ( Id int )' at line 1The above error occurred because the word ‘insert’ is a keyword in MySQL.Case 2 − Whenever you ... Read More
![Vrundesha Joshi](https://www.tutorialspoint.com/assets/profiles/13566/profile/60_88163-1512715024.jpg)
2K+ Views
To extract last word from a field, use in-built SUBSTRING_INDEX() function. The syntax is as follows −SELECT SUBSTRING_INDEX(yourColumnName, ’ ‘, -1) as anyVariableName from yourTableName;To understand the above concept, let us create a table. The following is the query to create a table −mysql> create table FirstWordDemo −> ( −> AllWords longtext −> ); Query OK, 0 rows affected (0.83 sec)Now insert some words in the table using insert command. The query is as follows −mysql> insert into FirstWordDemo values('This is the first MySQL Query'); Query OK, 1 row affected (0.11 ... Read More
![Rishi Rathor](https://www.tutorialspoint.com/assets/profiles/13563/profile/60_89283-1512714754.jpg)
20K+ Views
The best type for price column should be DECIMAL. The type DECIMAL stores the value precisely.For Example - DECIMAL(10, 2) can be used to store price value. It means the total digit will be 10 and two digits will be after decimal point.To understand the type DECIMAL, let us create a table.mysql> create table PriceDemo −> ( −> ProductPrice DECIMAL(10, 2) −> ); Query OK, 0 rows affected (0.60 sec)Now insert some records in the table in the form of price. The query to insert records is as follows −mysql> insert into PriceDemo values(12345.67); Query OK, 1 row ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
2K+ Views
You can strip last two characters with the help of SUBSTRING() and CHAR_LENGTH() methods. The syntax is as follows −select yourColumnName, SUBSTRING(yourColumnName, 1, CHAR_LENGTH(yourColumnName) - 2) AS anyVariableName from yourTableName;To understand the above syntax, let us create a table −mysql> create table LastTwoCharacters −> ( −> Words varchar(200) −> ); Query OK, 0 rows affected (0.71 sec)Now you can insert some records in the table with the help of select statement. The query to insert records is as follows −mysql> insert into LastTwoCharacters values('Hellooo'); Query OK, 1 row affected (0.23 sec) ... Read More
![Vrundesha Joshi](https://www.tutorialspoint.com/assets/profiles/13566/profile/60_88163-1512715024.jpg)
440 Views
To rearrange the MySQL columns, check the column arrangement with the help of show create command. The syntax is as follows −show create table yourTableName;The syntax to rearrange the MySQL columns is as follows −alter table yourTableName change column yourColumnName yourColumnName dataType firstFor the same purpose, you can use the after keyword. The syntax is as follows −alter table yourTableName change column yourColumnName yourColumnName dataType after yourSpecificColumnName;Let us first check the column arrangement for the already created table “AddColumn” −mysql> show create table AddColumn; The following is the output −+-----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table ... Read More
![Rishi Rathor](https://www.tutorialspoint.com/assets/profiles/13563/profile/60_89283-1512714754.jpg)
78 Views
To add more than 1 column with ALTER table command, you can use MODIFY column command. The syntax is as follows −alter table yourTableName modify column yourColumnName1 dataType, modify column yourColumnName2 dataType, . . . modify column yourColumnNameN dataTypeTo understand the above syntax, let us create a table. The following is the query −mysql> create table AddColumn −> ( −> StudentID int, −> StudentName varchar(200) −> ); Query OK, 0 rows affected (0.49 sec)Above we have two columns in the table “AddColumn”. In this we will see how to modify more than one column datatype −mysql> ... Read More
![Jennifer Nicholas](https://www.tutorialspoint.com/assets/profiles/13569/profile/60_88876-1512715262.jpg)
181 Views
To alter a MySQL table column defaults, you can use the CHANGE command. The syntax is as follows −alter table yourTableName change yourCoumnName youColumnName datatype not null default Value;To understand the above syntax, let us create a table. The following is the query −mysql> create table DefaultDemo −> ( −> ArrivalTime timestamp −> ); Query OK, 0 rows affected (0.65 sec)Here is the query that describes the table with default column −mysql> desc DefaultDemo;The following is the output −+-------------+-----------+------+-----+---------+-------+ | Field | Type ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
3K+ Views
To create a cumulative sum column in MySQL, you need to create a variable and set to value to 0. Cumulative sum increments the next value step by step with current value.Firstly, you need to create a variable with the help of SET. The syntax is as follows −set @anyVariableName:= 0;The syntax to create a cumulative sum column in MySQL is as follows −select yourColumnName1, yourColumnName2, ........N, (@anyVariableName := @anyVariableName + yourColumnName2) as anyVariableName from yourTableName order by yourColumnName1;To understand the above concept, let us create a table. The following is the query to create a table −mysql> create table ... Read More