Home Sql Mysql-alter Mysql Alter Constraint



Mysql Alter Constraint
Posted on: January 16, 2009 at 12:00 AM
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.

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 | |

Related Tags for Mysql Alter Constraint:
sqlceventstabledataeventtypespropertytypecolumnconstvaluecolumnsintnsisaisettabconstraintvaluestosignedssiesignpefromceinasmnttraceesproumnscolatincishaproperpreconsstrainstrrtropevassthcerstabablaluhatlumplpropprpreventonomolo


More Tutorials from this section

Ask Questions?    Discuss: Mysql Alter Constraint  

Post your Comment


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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.