MOCKSTACKS
EN
Questions And Answers

More Tutorials









SQLServer ALTER TABLE

Add Column(s)


ALTER TABLE Employees
ADD StartingDate date NOT NULL DEFAULT GetDate(),
 DateOfBirth date NULL

The above statement would add columns named StartingDate which cannot be NULL with default value as current date and DateOfBirth which can be NULL in Employees table.

Drop Column


ALTER TABLE Employees
DROP COLUMN salary;

This will not only delete information from that column, but will drop the column salary from table employees(the column will no more exist).

Add Primary Key


ALTER TABLE EMPLOYEES ADD pk_EmployeeID PRIMARY KEY (ID)

This will add a Primary key to the table Employees on the field ID. Including more than one column name in the parentheses along with ID will create a Composite Primary Key. When adding more than one column, the column names must be separated by commas.

ALTER TABLE EMPLOYEES ADD pk_EmployeeID PRIMARY KEY (ID, FName)


Conclusion

In this page (written and validated by ) you learned about SQLServer ALTER TABLE . What's Next? If you are interested in completing SQLServer tutorial, your next topic will be learning about: SQLServer INSERT.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.