Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • To add a primary key using ALTER command

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 247
    Comment on it

    Adding a primary key using ALTER Command:

    Alter command is generally used to modify table . It can be used to add columns or to remove columns. Using Alter command we can also add or remove a key from a table.

    Syntax:

    ALTER TABLE tablename ADD CONSTRAINT constraintname PRIMARY KEY (columnname);
    

    Example:

    ALTER TABLE Employee 
    ADD CONSTRAINT EmployeePK PRIMARY KEY (EmpID);
    

    Above query will make EmpID a primary key for Employee table.

    ALTER TABLE Employee 
    ADD CONSTRAINT EmployeePK  PRIMARY KEY (EmpID, Name);
    

    Above query will make EmpID and Name a primary key for Employee table. As combining EmpID and Name it work as a primary key for Employee table.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: