---
title: "Add non-nullable columns to an existing table in sql server?"  
description: "Add non-nullable columns to an existing table in sql server?"  
author: "Manoj Bhatt"  
published: 2013-05-06  
updated: 2013-05-06  
canonical: https://www.mindstick.com/forum/816/add-non-nullable-columns-to-an-existing-table-in-sql-server  
category: "mssql server"  
tags: ["mssql server"]  
reading_time: 1 minute  

---

# Add non-nullable columns to an existing table in sql server?

Hi Everyone!\
I [already](https://yourviews.mindstick.com/view/88453/the-hidden-ways-ai-is-already-controlling-your-daily-life) have a table which consists of data. I need to [alter table](https://www.mindstick.com/forum/811/alter-table-with-a-default-sql-server-vs-oracle) to [add two](https://www.mindstick.com/forum/480/add-two-number) new columns which are [not null](https://www.mindstick.com/interview/1933/what-is-not-null-constraint). How can I do that without losing any existing data?\
Here's what I tried (via right-clicking the table and selecting [Design](https://www.mindstick.com/articles/12279/interior-design-and-furniture-store-wordpress-theme)):\
Added new columns 'EmpFlag' (bit, null), 'CreatedDate' ([datetime](https://www.mindstick.com/forum/12949/how-to-validate-if-a-datetime-field-is-not-null-empty), null)\
Updated 'EmpFlag' column in the table, to have some valid values. (Just wanted to work on one field, so I didn't update 'CreatedDate' field)\
Now right clicked table, design, and made it not null.\
When I [tried to save](https://answers.mindstick.com/qa/45247/what-do-you-think-of-sacking-of-dr-kafeel-who-tried-to-save-children-in-gorakhpur-by-buying-oxygen-himself), this [error message](https://www.mindstick.com/forum/23174/error-message-the-page-you-are-requesting-cannot-be-served-because-of-the-extension-configuration) appeared:\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by AVADHESH PATEL

Hi Manoj!\
You just set a default value in the new columns and that will allow you to add them.\
alter table table_name add column_name datetime not null constraint DF_Default_Object_Name default (getdate())or this one for a varchar field.\
alter table table_name add column_name varchar(10) not null constraint DF_Default_Object_Name default ('A')You can also drop the default if you do not need it after you added the column.\
alter table table_name drop constraint DF_Default_Object_Name\
\


---

Original Source: https://www.mindstick.com/forum/816/add-non-nullable-columns-to-an-existing-table-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
