![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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)
5K+ Views
For dropping UNIQUE constraint from a MySQL table, first of all, we must have to check the name of the index created by the UNIQUE constraint on the table. As we know that SHOW INDEX statement is used for this purpose. The ‘key_name’ in the result set of SHOW INDEX statement contains the name of the index. Now either with the help of DROP INDEX statement or ALTER TABLE statement, we can drop the UNIQUE constraint. The syntax for both the statements is as follows −SyntaxDROP INDEX index_name ON table_name; OR ALTER TABLE table_name DROP INDEX index_name;ExampleSuppose we have the ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
407 Views
SHOW INDEX statement is used to check the indexes created by a UNIQUE constraint on a MySQL table.SyntaxSHOW INDEX from table_name;ExampleSuppose we have the table ‘empl’ which have a UNIQUE constraint on column ‘empno’.mysql> describe empl; +--------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+-------+ | empno | int(11) | YES | UNI | NULL | | | F_name | varchar(20) | YES | | NULL | | +--------+-------------+------+-----+---------+-------+ 2 rows in set (0.23 sec)Now as we know that ... Read More
![Rishi Raj](https://www.tutorialspoint.com/assets/profiles/13777/profile/60_73169-1512647303.jpg)
83 Views
CREATE UNIQUE INDEX statement can also be used to apply the UNIQUE constraint to the field of an existing MySQL table. The syntax of it is as follows −CREATE UNIQUE INDEX index_name ON table_name(Column_name);ExampleSuppose we have the following table named ‘Test5’ and we want to add UNIQUE constraint to the column ‘ID’ then it can be done with the help of CREATE UNIQUE INDEX command as follows −mysql> DESCRIBE TEST5; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | ID | int(11) | YES | ... Read More
![Swarali Sree](https://www.tutorialspoint.com/assets/profiles/13515/profile/60_84115-1512649510.jpg)
395 Views
We can apply the UNIQUE constraint to a column of an existing MySQL table with the help of ALTER TABLE statement.SyntaxALTER TABLE table_name MODIFY colum_name datatype UNIQUE; OR ALTER TABLE table_name ADD UNIQUE (colum_name);ExampleSuppose we have the following table named ‘Test4’ and we want to add UNIQUE constraint to the column ‘Name’ then it can be done with the help of ALTER TABLE command as follows −mysql> DESCRIBE test4; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | ID ... Read More
![Kumar Varma](https://www.tutorialspoint.com/assets/profiles/13883/profile/60_73481-1512711460.jpg)
147 Views
It is quite possible to insert the NULL keyword as a value in a character type column having NOT NULL constraint because NULL is a value in itself. Following example will exhibit it −ExampleSuppose we have a table test2 having character type column ‘Name’ along with NOT NULL constraint on it. It can be checked from the DESCRIBE statement as follows −mysql> Describe test2\G *************************** 1. row *************************** Field: id Type: int(11) Null: NO Key: Default: NULL Extra: *************************** 2. row *************************** Field: NAME Type: varchar(20) Null: NO Key: ... Read More
![Lakshmi Srinivas](https://www.tutorialspoint.com/assets/profiles/13528/profile/60_91717-1512651120.jpg)
6K+ Views
We can remove a NOT NULL constraint from a column of an existing table by using the ALTER TABLE statement.ExampleSuppose we have a table ‘test123’ having a NOT NULL constraint on column ‘ID’ as follows −mysql> DESCRIBE test123; +-------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | ID | int(11) | NO | | NULL | | | Date | date | YES | | NULL | | +-------+---------+------+-----+---------+-------+ 2 rows in set (0.04 sec)Now if we ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
171 Views
In this case, MySQL will return an error message regarding data truncated for the column. Following is an example of demonstrating it −ExampleSuppose we have a table ‘test2’ which contains a NULL value in column ‘ID’ at 2nd row. Now, if we will try to declare the column ID to NOT NULL then MySQL will return the error as follows −mysql> Select * from test2; +------+--------+ | ID | Name | +------+--------+ | 1 | Gaurav | | NULL | Rahul | +------+--------+ 2 rows in set (0.00 sec) mysql> ALTER TABLE TEST2 MODIFY ID INT NOT NULL; ERROR 1265 (01000): Data truncated for column 'ID' at row 2
![Jai Janardhan](https://www.tutorialspoint.com/assets/profiles/13513/profile/60_63529-1512538711.jpg)
308 Views
We can apply the NOT NULL constraint to a column of an existing MySQL table with the help of ALTER TABLE statement. SyntaxALTER TABLE table_name MODIFY colum_name datatype NOT NULL; Examplemysql> Create table test123(ID INT, Date DATE); Query OK, 0 rows affected (0.19 sec) mysql> Describe test123; +-------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | ID | int(11) | YES | | NULL | | | Date | date | YES | | NULL | | +-------+---------+------+-----+---------+-------+ ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
298 Views
Actually, MySQL NOT NULL constraint restricts a column of the table from having a NULL value. Once we applied NOT NULL constraint to a column, then we cannot pass a null value to that column. It cannot be declared on the whole table i.e., in other words, we can say that NOT NULL is a column level constraint.For declaring a field NOT NULL, we have to use NOT NULL keyword while defining the column in CREATE TABLE statement.Examplemysql> Create table Employee(ID Int NOT NULL, First_Name Varchar(20), Last_name Varchar(20), Designation Varchar(15)); Query OK, 0 rows affected (0.59 sec)In the query above, ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/32020/profile/60_153038-1524898298.jpg)
871 Views
suppose you want to login into you account using Python CGi script, below is the details login.html email: password: login.py #!C:\Python27\python.exe import MySQLdb import cgi import Cookie # Open database connection db = MySQLdb.connect("localhost", "root", "", "student" ) # prepare a ... Read More