[sql-server] Programmatically retrieve SQL Server stored procedure source that is identical to the source returned by the SQL Server Management Studio gui?

I saw a article via link. There are four methods, I just did a short summary here for helping other programmers.

  1. EXEC sp_helptext 'sp_name';

  2. SELECT OBJECT_ID('sp_name')

  3. SELECT OBJECT_DEFINITION( OBJECT_ID('sp_name') ) AS [Definition];

  4. SELECT * FROM sys.sql_modules WHERE object_id = object_id('sp_name');