February 27, 2005 at 3:36 pm
Now that my database is in SQL Server, it seems it is very hard to add or modify a table.
I don't have SQL Server Enterprise Manager, so I guess I need to use stored procedures?
I need to add a field to a table, a numeric integer field but I haven't been able to find any examples that work.
Can someone point me in the right direction?
February 27, 2005 at 5:09 pm
Even if you had Enterprise Manager, it is more efficient to add the field using code:
alter table myTable add myNewColumn int null
Aunt Kathi Data Platform MVP
Author of Expert T-SQL Window Functions
Simple-Talk Editor
February 28, 2005 at 8:08 am
I usually use vb6's data view window(from view menu) for that case.
Rgds,
Myint Thu
February 28, 2005 at 8:26 am
Try this:
--NOTE: Change TableName and ColumnName to respective values.
IF NOT (SELECT object_id('dbo.TableName') as idnum)IS NULL
BEGIN
IF NOT exists(SELECTt o.* from dbo.sysobjects o JOIN syscolumns c ON c.Id = o.Id WHERE o.id = object_id(N'[TableName]') and OBJECTPROPERTY(o.id, N'IsUserTable') = 1 BEGIN
ALTER TABLE TableName ADD
[ColumnName] integer NULL
ALTER TABLE dbo.TableName ADD CONSTRAINT
/* Uncomment the following statment if you wish to add a constraint
DF_TableName_ColumnName DEFAULT 0 FOR ColumnName
*/
END
END
GO
March 24, 2005 at 3:03 pm
Should these 2 lines work by themselves?
ALTER TABLE tblAccount ADD
[MailServer] varchar(50)
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply