- 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
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
378 Views
To check if field of a table has NOT NULL property, you can use any of the two syntaxes. The first syntax is as follows −desc yourTableName;Following is the second syntax −select column_name, is_nullable from information_schema.columns where table_schema = ‘yourDatabaseName’ and table_name = 'yourTableName’;Let us first see an example and create a table −mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(40), StudentAge int NOT NULL, IsActiveStudent ENUM('ACTIVE", INACTIVE') NOT NULL, StudentCountryName varchar(40) ); Query OK, 0 rows affected (1.53 sec)The first syntax is as follows ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
237 Views
To prevent a combination of items from being inserted twice, alter the table and set UNIQUE for the column as shown in the below syntax −alter table yourTableName add constraint yourConstraintName unique(yourColumnName1, yourColumnName2, ....N);Let us first create a table −mysql> create table DemoTable ( Value1 int, Value2 int ); Query OK, 0 rows affected (0.47 sec)Here is the query to prevent a combination of items from being inserted twice −mysql> alter table DemoTable add constraint Value1_Value2_ConstraintKey unique(Value1, Value2); Query OK, 0 rows affected (0.80 sec) Records : 0 Duplicates : 0 Warnings : 0Insert some records in the ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
91 Views
For this, use BETWEEN -1 AND 1. Let us first create a table −mysql> create table DemoTable ( Value int ); Query OK, 0 rows affected (0.76 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(14); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(15); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(16); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(17); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(18); Query OK, 1 row affected (0.09 sec)Display all records from ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
869 Views
For this, you need to use UNIQUE KEY for the column. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(30), UNIQUE KEY(FirstName) ); Query OK, 0 rows affected (1.76 sec)Insert some records in the table using insert command. Now, we are also inserting duplicate records like “David”, but it won’t get inserted twice, since we have set the column as UNIQUE KEY −mysql> insert ignore into DemoTable(FirstName) values('Chris'); Query OK, 1 row affected (0.42 sec) mysql> insert ignore into DemoTable(FirstName) values('David'); Query OK, 1 row affected ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
Let us first create a table −mysql> create table DemoTable ( ProductAmount int, PurchaseDate datetime ); Query OK, 0 rows affected (0.94 sec)Note − Let’s say the current date is 2010-09-15.Insert some records in the table using insert command −mysql> insert into DemoTable values(567, '2019-09-10'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(1347, '2019-09-14'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(2033, '2019-09-13'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(1256, '2019-09-11'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(1000, '2019-09-16'); Query ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
98 Views
Let us first create a table −mysql> create table DemoTable ( Subject text ); Query OK, 0 rows affected (0.86 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Introduction to MySQL'); Query OK, 1 row affected (0.31 sec) mysql> insert into DemoTable values('Deep Dive using Java'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('C in Depth'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Introduction to C++'); Query OK, 1 row affected (0.48 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
54 Views
Let us first create a table −mysql> create table DemoTable ( Joiningdate date ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2010-01-01'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('2010-03-31'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('2010-11-04'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('2012-12-31'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('2019-01-03'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2016-04-05'); Query OK, 1 row affected ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
242 Views
Let us first create a table −mysql> create table DemoTable ( AdmissionDate varchar(50) ); Query OK, 0 rows affected (0.63 sec)Note − Let’s say the current date is 14-Sep-2019.Insert some records in the table using insert command. Following is the query −mysql> insert into DemoTable values('15-Sep-2019'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('14-Sep-2019'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('13-Sep-2016'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('13-Sep-2019'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('13-Sep-2020'); Query OK, 1 row affected ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
453 Views
Yes, we can implement nested insert with select in MySQL as shown in the below syntax −insert into yourTableName2(yourColumnName1, yourColumnName2, .....N) select yourColumnName1, yourColumnName2, ....N from yourTableName1 where yourCondition;Let us first see an example and create a table −mysql> create table DemoTable1 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(40) ); Query OK, 0 rows affected (0.88 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1(Name) values('Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1(Name) values('David'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1(Name) values('Bob'); Query ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
Let us first create a table −mysql> create table DemoTable ( PageId int ); Query OK, 0 rows affected (0.85 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(233); Query OK, 1 row affected (0.36 sec) mysql> insert into DemoTable values(34); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(76); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(89); Query OK, 1 row affected (0.26 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+--------+ | PageId | +--------+ ... Read More