all groups > sql server programming > september 2003 >
You're in the

sql server programming

group:

Adding a field to a table programatically.


Re: Adding a field to a table programatically. Dan Guzman
9/11/2003 9:45:51 PM
sql server programming:
You can add a new column with ALTER TABLE. For a NOT NULL column,
you'll need to also specify a default constraint. For example:

-- allow null
ALTER TABLE MyTable
ADD MyNewColumn1 int NULL

-- not null
ALTER TABLE MyTable
ADD MyNewColumn2 int NOT NULL
CONSTRAINT DF_MyNewColumn2 DEFAULT 0

See the SQL Server 2000 Books Online <tsqlref.chm::/ts_aa-az_3ied.htm>
for details and examples.

--
Hope this helps.

Dan Guzman
SQL Server MVP

-----------------------
SQL FAQ links (courtesy Neil Pike):

http://www.ntfaq.com/Articles/Index.cfm?DepartmentID=800
http://www.sqlserverfaq.com
http://www.mssqlserver.com/faq
-----------------------

[quoted text, click to view]

Adding a field to a table programatically. Jim Mitchell
9/11/2003 10:41:04 PM
Can some one provide some samle SQL or VB Script to add a field to an
existing table. I did not see a Create Field Command in Transact-SQL.

Thanks in advance.

Jim

AddThis Social Bookmark Button