Is there a way to apply an alter statement to ALL the columns in a table without having to specify the column names? This would only be used in a temp table I need to clean up the duplicate data in a report.
Here’s a sample of what I’m wondering if its possible:
select T1.Column1, T1.Column2, T1.Column3, T2.Column1, T2.Column2
into #templateTable
from Table1 T1
join Table2 T2 on T1.Column1 = T2.Column2
alter table #templateTable
alter column * null
All I really need is my #tempTable to allow null values in the columns that it originally gets data from which don’t previously allow null values.
Lastly, there are 2 reasons I don’t want to go through and edit each column:
- There are many columns (~50) being pulled from at least 10 tables.
- I don’t know which ones allow null and researching which ones do would take me the next two days.
Any help will be appreciated.
Ugly way, but it works in a SqlServer Management Studio, at least (can probably be used as “strings”)
copy result, paste and execute…