This is actually notoriously tricky. It works fine with UDFs, since they have stronger metadata - but a stored procedure can do lots of nasty things:
- branches (
IF
etc), returning completely different shapes
- execute another stored procedure
- execute dynamic sql
So very, very tricky. There are two common approaches:
- attempt to parse the TSQL; painful
- execute it with default (null, etc) values and check the result
The SET FMTONLY ON
option is often used for the second (to avoid updates etc), but note that system stored procedures are still executed (perhaps xp_sendmail
?), so you risk doing unwanted things...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…