I have come across this a few times and not been able to find anything that answers my question.
So i have written some T-SQL code that looks over your table and asks if any column contains only NULL values.
This will help to decide whether you can use an existing column, instead of expanding your schema.
Note: Of course, you should always test using an existing field thoroughly in a test environment to make sure there are no adverse effects.
Firstly you need a table to store your results, so select your test SM7 database and open a new query window:
Code:
CREATE TABLE temp2 (
[columnName] [varchar](50) PRIMARY KEY NOT NULL,
[type] [varchar](50) NULL,
[length] [int] NULL)
Code:
Set nocount on
DECLARE crs CURSOR LOCAL FAST_FORWARD FOR SELECT [name], [xtype], [length] FROM syscolumns WHERE id=OBJECT_ID('dbo.CM3RM1')
OPEN crs
DECLARE @name sysname
DECLARE @xtype int
DECLARE @length int
FETCH NEXT FROM crs INTO @name, @xtype, @length
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO temp2 ([columnName],[type],[length])
EXEC('SELECT ''' + @name + ''',(select [name] from sys.systypes where xtype = ' + @xtype + '),' + @length + ' WHERE NOT EXISTS (SELECT * FROM dbo.CM3RM1 WHERE [' + @name + '] IS NOT NULL)');
FETCH NEXT FROM crs INTO @name, @xtype, @length
END
CLOSE crs
DEALLOCATE crs
Now you can review the results anytime by running:
Code:
SELECT * FROM temp2
Cheers,
Lukus


Section Widget
Recent Article Comments Widget

Reply

I have picked up a copy of the new book. (Also own a copy of the 6.2 version.) I have started...
New book by Mike Sanders: Service Manager 9 Tailoring Techniques
drjf4 on 2012-02-03