Wednesday, April 15, 2009

Query To Alter ALL Tables in a specified Database

--Query To Alter all Tables in @db_NAME to include 5 new Columns, Status, Create_Date, modify_Date, Creator_ID, Modifier
declare @db_NAME varchar(100); select @db_NAME = 'test_indicator'
declare @tbl_TYPE varchar(100); select @tbl_TYPE = 'base table'
declare @tbl_NAME varchar(100);
declare @tbl int;
declare @tbl_MAX int;
declare @sql varchar(1000)
IF object_id('tempdb..#Temp') IS NOT NULL
BEGIN
DROP TABLE #temp
END
CREATE TABLE #Temp(
id int IDENTITY(1,1),
table_catalog varchar(255),
table_name varchar(255)
)

insert into #Temp
select table_catalog, table_name from INFORMATION_SCHEMA.TABLES where table_catalog=@db_NAME and table_type = @tbl_TYPE and table_name <> 'dtproperties'
select @tbl=min(id),@tbl_MAX = count(id) from #Temp


WHILE @tbl <= @tbl_MAX
BEGIN
select @tbl_NAME = table_name from #temp where id = @tbl
print @tbl_NAME
set @sql = 'ALTER TABLE ' + @tbl_NAME + ' ADD status bit, create_date datetime, modify_date datetime, creator_id int, modifier_id int'
--exec (@sql)
print @sql
set @tbl = @tbl +1
END

Get All Columns of a Table - MSSQL

As You can tell an iteration of INFORMATION_SCHEMA.COLUMNS is required, and I felt this should be created as an object of type function for best extensibility. Infact the post after this uses the same to achieve a more complex objective.

CREATE FUNCTION GetColumns (@tbl varchar(100))
RETURNS varchar(1000)
AS
BEGIN

declare @i int; select @i=min(ordinal_position) from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = @tbl
declare @MAX int; select @MAX = count(ordinal_position) from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = @tbl
declare @col varchar(100);declare @data varchar(100);
declare @TEMP varchar(1000); set @TEMP = ''
WHILE @i <= @MAX
BEGIN
select @col=Column_name from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = @tbl and ordinal_position= @i
select @data=data_type from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = @tbl and ordinal_position= @i
if @i =1
set @TEMP = @col
else
set @TEMP = @TEMP + ',' + @col
set @i = @i +1

END
set @TEMP = @TEMP + ' '
return @TEMP
END

Wednesday, April 1, 2009

Edit and Continue (Cannot currently modify this text in the editor. It is read only)

In Visual Studio 20080 SP 1, Edit and Continue Does not work for code behind files in ASP.NET applications .NET framework 3.5. Code files get automatically locked on building the application and remain locked for the duration of the build, returning a "Cannot currently modify this text in the editor. It is read only" error message as indicated below.

I have tried all the following suggestions in the below methods to fix it.
http://msdn.microsoft.com/en-us/library/ba77s56w.aspx
http://social.msdn.microsoft.com/forums/en-US/vbide/thread/b65225e3-5b6a-4ac6-a902-6b1427c694aa/

I am running this on a Windows XP SP2 32 Bit computer, in DEBUG mode. I am also attaching snapshots of the current settings in my computer.




Thanks
Kanhar Munshi