Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

Mysql Alter Constraint

A constraint is a property in SQL assigned to a column or the set of columns in a table that prevents certain types of inconsistent data values from being placed in the column of the table.

Ads

Mysql Alter Constraint

     

A constraint is a property in SQL assigned to a column or the set of columns in a table that prevents certain types of inconsistent data values from being placed in the column of the table. Constraints in SQL  are used to enforce the data integrity. This ensures the accuracy and reliability of the data in the database.

Understand with Example

The Tutorial illustrate an example from 'Mysql Alter Constraint'. To understand the example we simply create a table 'userform' with required fieldnames and datatypes respectively

Create table "userform"  :

+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| username | varchar(100) | YES | | | |
| fname | varchar(100) | YES | | | |
| email | varchar(100) | YES | | | |
| count | bigint(20) | YES | | 100 | |

 Alter column ID using the below Query:

The Alter Table is used to modify the table 'userform' and add ID as a Primary Key constraint.

ALTER TABLE userform ADD ID INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (ID);

After alter the table "userform"

+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| ID | int(11) | NO | PRI | | auto_increment |
| username | varchar(100) | YES | | | |
| fname | varchar(100) | YES | | | |
| email | varchar(100) | YES | | | |
| count | bigint(20) | YES | | 100 | |

Advertisements

Ads
Share on Google+Share on Google+

Mysql Alter Constraint

Posted on: January 16, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Mysql Alter Constraint  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads