Data AccessCore JavaApp FrameworksViewTestingBuildingDeploymentDev ToolsSecurityOpinions

Tuesday, April 28, 2009

ALTER TABLE SQL - ADD COLUMN and Foreign Key Constraint

In this short tutorial, we will alter a table in a MySQL database by adding a column to the table along with a new foreign key constraint.

First we will alter the table user and add a column called zipcodeId, which is an integer.

ALTER TABLE user ADD COLUMN zipcodeId INT


The zipcodeId field references a field in another table called zipcode. Next, we'll define the foreign key constraint.

ALTER TABLE User ADD CONSTRAINT FK_User_1 FOREIGN KEY (zipcodeId) REFERENCES Zipcode (id) 


That was quick and easy. Note, all of this information is readily available in the MySQL online documentation at: http://dev.mysql.com/doc/refman/5.1/en/alter-table.html

3 comments:

  1. This helps ensure that the general population who give this administration are reliable and fair. This administration is valuable to the clients and additionally the monetary foundations.check cashing san diego

    ReplyDelete
  2. The sum you can acquire will rely upon the estimation of your vehicle, which depends on its discount cost. Before you approach a loan specialist, you have to survey the estimation of your auto. usacheckcashingstore.com/costa-mesa

    ReplyDelete
  3. The figure looks cool. Thank you for sharing the collection.AndroVid live nettv CShare

    ReplyDelete