3 回答

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超2個(gè)贊
我同意每個(gè)人.。但如果我要做這樣的事,我可能會這樣做:
/* Get the data into a temp table */
SELECT * INTO #TempTable
FROM YourTable
/* Drop the columns that are not needed */
ALTER TABLE #TempTable
DROP COLUMN ColumnToDrop
/* Get results and drop temp table */
SELECT * FROM #TempTable
DROP TABLE #TempTable

TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超13個(gè)贊
這使得客戶端和數(shù)據(jù)庫之間的合同穩(wěn)定。每次都是同樣的數(shù)據(jù) 性能、覆蓋指標(biāo)
Columns

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超4個(gè)贊
declare @cols varchar(max), @query varchar(max);SELECT @cols = STUFF ( ( SELECT DISTINCT '], [' + name FROM sys.columns where object_id = ( select top 1 object_id from sys.objects where name = 'MyTable' ) and name not in ('ColumnIDontWant1', 'ColumnIDontWant2') FOR XML PATH('') ), 1, 2, '' ) + ']';SELECT @query = 'select ' + @cols + ' from MyTable'; EXEC (@query);
添加回答
舉報(bào)