Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_help

  No additional text.


Syntax
create procedure sys.sp_help
	@objname nvarchar(776) = NULL		-- object name we're after
as
	-- PRELIMINARY
	set nocount on
	declare	@dbname	sysname
		,@no varchar(35), @yes varchar(35), @none varchar(35)
	select @no = 'no', @yes = 'yes', @none = 'none'

	-- If no @objname given, give a little info about all objects.
	if @objname is null
	begin
		-- DISPLAY ALL SYSOBJECTS 
        select
            'Name'          = o.name,
            'Owner'         = user_name(ObjectProperty( object_id, 'ownerid')),
            'Object_type'   = substring(v.name,5,31)
        from sys.all_objects o, master.dbo.spt_values v
        where o.type = substring(v.name,1,2) collate database_default and v.type = 'O9T'
        order by [Owner] asc, Object_type desc, Name asc

		print ' '

		-- DISPLAY ALL USER TYPES
		select
			'User_type'	= name,
			'Storage_type'	= type_name(system_type_id),
			'Length'		= max_length,
			'Prec'		= Convert(int,TypePropertyEx(user_type_id, 'precision')),
			'Scale'		= Convert(int,TypePropertyEx(user_type_id, 'scale')),
			'Nullable'		= case when is_nullable = 1 then @yes else @no end,
			'Default_name'	= isnull(object_name(default_object_id), @none),
			'Rule_name'		= isnull(object_name(rule_object_id), @none),
			'Collation'		= collation_name
		from sys.types
		where user_type_id > 256
		order by name

		return(0)
	end

	-- Make sure the @objname is local to the current database.
	select @dbname = parsename(@objname,3)
	if @dbname is null
		select @dbname = db_name()
	else if @dbname <> db_name()
		begin
			raiserror(15250,-1,-1)
			return(1)
		end

	-- @objname must be either sysobjects or systypes: first look in sysobjects
	declare @objid int
	declare @sysobj_type char(2)
	select @objid = object_id, @sysobj_type = type from sys.all_objects where object_id = object_id(@objname)

	-- IF NOT IN SYSOBJECTS, TRY SYSTYPES 
	if @objid is null
	begin
		-- UNDONE: SHOULD CHECK FOR AND DISALLOW MULTI-PART NAME
		select @objid = type_id(@objname)

		-- IF NOT IN SYSTYPES, GIVE UP
		if @objid is null
		begin
			raiserror(15009,-1,-1,@objname,@dbname)
			return(1)
		end

		-- DATA TYPE HELP (prec/scale only valid for numerics)
		select
			'Type_name'	= name,
			'Storage_type'	= type_name(system_type_id),
			'Length'		= max_length,
			'Prec'			= Convert(int,TypePropertyEx(user_type_id, 'precision')),
			'Scale'			= Convert(int,TypePropertyEx(user_type_id, 'scale')),
			'Nullable'			= case when is_nullable=1 then @yes else @no end,
			'Default_name'	= isnull(object_name(default_object_id), @none),
			'Rule_name'		= isnull(object_name(rule_object_id), @none),
			'Collation'		= collation_name
		from sys.types
		where user_type_id = @objid

		return(0)
	end

	-- FOUND IT IN SYSOBJECT, SO GIVE OBJECT INFO
	select
		'Name'				= o.name,
		'Owner'				= user_name(ObjectProperty( object_id, 'ownerid')),
        'Type'              = substring(v.name,5,31),
		'Created_datetime'	= o.create_date
	from sys.all_objects o, master.dbo.spt_values v
	where o.object_id = @objid and o.type = substring(v.name,1,2) collate database_default and v.type = 'O9T'

	print ' '

	-- DISPLAY COLUMN IF TABLE / VIEW
	if exists (select * from sys.all_columns where object_id = @objid)
	begin

		-- SET UP NUMERIC TYPES: THESE WILL HAVE NON-BLANK PREC/SCALE
		-- There must be a ',' immediately after each type name (including last one),
		-- because that's what we'll search for in charindex later.
		declare @precscaletypes nvarchar(150)
		select @precscaletypes = N'tinyint,smallint,decimal,int,real,money,float,numeric,smallmoney,date,time,datetime2,datetimeoffset,'

		-- INFO FOR EACH COLUMN
		print ' '
		select
			'Column_name'			= name,
			'Type'					= type_name(user_type_id),
			'Computed'				= case when ColumnProperty(object_id, name, 'IsComputed') = 0 then @no else @yes end,
			'Length'					= convert(int, max_length),
			-- for prec/scale, only show for those types that have valid precision/scale
			-- Search for type name + ',', because 'datetime' is actually a substring of 'datetime2' and 'datetimeoffset'
			'Prec'					= case when charindex(type_name(system_type_id) + ',', @precscaletypes) > 0
										then convert(char(5),ColumnProperty(object_id, name, 'precision'))
										else '     ' end,
			'Scale'					= case when charindex(type_name(system_type_id) + ',', @precscaletypes) > 0
										then convert(char(5),OdbcScale(system_type_id,scale))
										else '     ' end,
			'Nullable'				= case when is_nullable = 0 then @no else @yes end,
			'TrimTrailingBlanks'	= case ColumnProperty(object_id, name, 'UsesAnsiTrim')
										when 1 then @no
										when 0 then @yes
										else '(n/a)' end,
			'FixedLenNullInSource'	= case
						when type_name(system_type_id) not in ('varbinary','varchar','binary','char')
							then '(n/a)'
						when is_nullable = 0 then @no else @yes end,
			'Collation'		= collation_name
		from sys.all_columns where object_id = @objid

		-- IDENTITY COLUMN?
		if @sysobj_type in ('S ','U ','V ','TF') and @objid > 0
		begin
			print ' '
			declare @colname sysname
			select @colname = col_name(@objid, column_id) from sys.identity_columns where object_id = @objid
			select
				'Identity'				= isnull(@colname,'No identity column defined.'),
				'Seed'				= ident_seed(@objname),
				'Increment'			= ident_incr(@objname),
				'Not For Replication'	= ColumnProperty(@objid, @colname, 'IsIDNotForRepl')
			-- ROWGUIDCOL?
			print ' '
			select @colname = null
			select @colname = name from sys.columns where object_id = @objid and is_rowguidcol = 1
			select 'RowGuidCol' = isnull(@colname,'No rowguidcol column defined.')
		end
	end

	-- DISPLAY ANY PARAMS
	if exists (select * from sys.all_parameters where object_id = @objid)
	begin
		-- INFO ON PROC PARAMS
		print ' '
		select
			'Parameter_name'	= name,
			'Type'			= type_name(user_type_id),
			'Length'			= max_length,
			'Prec'			= case when type_name(system_type_id) = 'uniqueidentifier' then precision
								else OdbcPrec(system_type_id, max_length, precision) end,
			'Scale'			= OdbcScale(system_type_id, scale),
			'Param_order'		= parameter_id,
			'Collation'			= convert(sysname, case when system_type_id in (35, 99, 167, 175, 231, 239)
						then ServerProperty('collation') end)

		from sys.all_parameters where object_id = @objid
	end

	-- DISPLAY TABLE INDEXES & CONSTRAINTS
	if @sysobj_type in ('S ','U ')
	begin
		print ' '
		EXEC sys.sp_objectfilegroup @objid
		print ' '
		EXEC sys.sp_helpindex @objname
		print ' '
		EXEC sys.sp_helpconstraint @objname,'nomsg'
		if (select count(*) from sysdepends where depid = @objid and deptype = 1) = 0
		begin
			raiserror(15647,-1,-1,@objname) -- No views with schemabinding reference table '%ls'.
		end
		else
		begin
            select distinct 'Table is referenced by views' = obj.name from sys.objects obj, sysdepends deps
				where obj.type ='V' and obj.object_id = deps.id and deps.depid = @objid
					and deps.deptype = 1 group by obj.name

		end
	end
	else if @sysobj_type in ('V ') and @objid > 0
	begin
		-- VIEWS DONT HAVE CONSTRAINTS, BUT PRINT THESE MESSAGES BECAUSE 6.5 DID
		print ' '
		raiserror(15469,-1,-1,@objname) -- No constraints defined
		print ' '
		raiserror(15470,-1,-1,@objname) -- No foreign keys reference table '%ls'.
		EXEC sys.sp_helpindex @objname
	end

	return (0) -- sp_help

 
Last revision 2008RTM
See also

  sp_adddistributor (Procedure)
sp_addmergepublication (Procedure)
sp_addmergepushsubscription_agent (Procedure)
sp_addmergesubscription (Procedure)
sp_changemergepublication (Procedure)
sp_changemergesubscription (Procedure)
sp_deletetracertokenhistory (Procedure)
sp_dropdistributiondb (Procedure)
sp_dropdistributor (Procedure)
sp_dropmergepublication (Procedure)
sp_dropmergesubscription (Procedure)
sp_enumcustomresolvers (Procedure)
sp_get_composite_job_info (Procedure)
sp_helpallowmerge_publication (Procedure)
sp_helparticle (Procedure)
sp_helparticlecolumns (Procedure)
sp_helparticledts (Procedure)
sp_helpconstraint (Procedure)
sp_helpdatatypemap (Procedure)
sp_helpdb (Procedure)
sp_helpdbfixedrole (Procedure)
sp_helpdevice (Procedure)
sp_helpdistpublisher (Procedure)
sp_helpdistributiondb (Procedure)
sp_helpdistributor (Procedure)
sp_helpdistributor_properties (Procedure)
sp_helpdynamicsnapshot_job (Procedure)
sp_helpextendedproc (Procedure)
sp_helpfile (Procedure)
sp_helpfilegroup (Procedure)
sp_helpgroup (Procedure)
sp_helpindex (Procedure)
sp_helplanguage (Procedure)
sp_helplinkedsrvlogin (Procedure)
sp_helplogins (Procedure)
sp_helplogreader_agent (Procedure)
sp_helpmergealternatepublisher (Procedure)
sp_helpmergearticle (Procedure)
sp_helpmergearticlecolumn (Procedure)
sp_helpmergearticleconflicts (Procedure)
sp_helpmergeconflictrows (Procedure)
sp_helpmergedeleteconflictrows (Procedure)
sp_helpmergefilter (Procedure)
sp_helpmergelogfiles (Procedure)
sp_helpmergelogfileswithdata (Procedure)
sp_helpmergelogsettings (Procedure)
sp_helpmergepartition (Procedure)
sp_helpmergepublication (Procedure)
sp_helpmergepullsubscription (Procedure)
sp_helpmergesubscription (Procedure)
sp_helpntgroup (Procedure)
sp_helppeerrequests (Procedure)
sp_helppeerresponses (Procedure)
sp_helppublication (Procedure)
sp_helppublicationsync (Procedure)
sp_helppublication_snapshot (Procedure)
sp_helppullsubscription (Procedure)
sp_helpqreader_agent (Procedure)
sp_helpremotelogin (Procedure)
sp_helpreplfailovermode (Procedure)
sp_helpreplicationdb (Procedure)
sp_helpreplicationdboption (Procedure)
sp_helpreplicationoption (Procedure)
sp_helprole (Procedure)
sp_helprolemember (Procedure)
sp_helprotect (Procedure)
sp_helpserver (Procedure)
sp_helpsort (Procedure)
sp_helpsrvrole (Procedure)
sp_helpsrvrolemember (Procedure)
sp_helpstats (Procedure)
sp_helpsubscriberinfo (Procedure)
sp_helpsubscription (Procedure)
sp_helpsubscriptionerrors (Procedure)
sp_helpsubscription_properties (Procedure)
sp_helptext (Procedure)
sp_helptracertokenhistory (Procedure)
sp_helptracertokens (Procedure)
sp_helptrigger (Procedure)
sp_helpuser (Procedure)
sp_helpxactsetjob (Procedure)
sp_help_agent_default (Procedure)
sp_help_agent_parameter (Procedure)
sp_help_agent_profile (Procedure)
sp_help_alert (Procedure)
sp_help_category (Procedure)
sp_help_datatype_mapping (Procedure)
sp_help_downloadlist (Procedure)
sp_help_fulltext_catalogs (Procedure)
sp_help_fulltext_catalogs_cursor (Procedure)
sp_help_fulltext_catalog_components (Procedure)
sp_help_fulltext_columns (Procedure)
sp_help_fulltext_columns_cursor (Procedure)
sp_help_fulltext_system_components (Procedure)
sp_help_fulltext_tables (Procedure)
sp_help_fulltext_tables_cursor (Procedure)
sp_help_job (Procedure)
sp_help_jobactivity (Procedure)
sp_help_jobcount (Procedure)
sp_help_jobhistory (Procedure)
sp_help_jobhistory_full (Procedure)
sp_help_jobhistory_sem (Procedure)
sp_help_jobhistory_summary (Procedure)
sp_help_jobschedule (Procedure)
sp_help_jobserver (Procedure)
sp_help_jobstep (Procedure)
sp_help_jobsteplog (Procedure)
sp_help_jobs_in_schedule (Procedure)
sp_help_log_shipping_alert_job (Procedure)
sp_help_log_shipping_monitor (Procedure)
sp_help_log_shipping_monitor_primary (Procedure)
sp_help_log_shipping_monitor_secondary (Procedure)
sp_help_log_shipping_primary_database (Procedure)
sp_help_log_shipping_primary_secondary (Procedure)
sp_help_log_shipping_secondary_database (Procedure)
sp_help_log_shipping_secondary_primary (Procedure)
sp_help_maintenance_plan (Procedure)
sp_help_notification (Procedure)
sp_help_operator (Procedure)
sp_help_operator_jobs (Procedure)
sp_help_peerconflictdetection (Procedure)
sp_help_proxy (Procedure)
sp_help_publication_access (Procedure)
sp_help_schedule (Procedure)
sp_help_spatial_geography_index (Procedure)
sp_help_spatial_geography_index_helper (Procedure)
sp_help_spatial_geography_index_xml (Procedure)
sp_help_spatial_geometry_index (Procedure)
sp_help_spatial_geometry_index_helper (Procedure)
sp_help_spatial_geometry_index_xml (Procedure)
sp_help_spatial_index_internal (Procedure)
sp_help_targetserver (Procedure)
sp_help_targetservergroup (Procedure)
sp_IHhelparticle (Procedure)
sp_lookupcustomresolver (Procedure)
sp_mergesubscriptionsummary (Procedure)
sp_MSaddmergepub_snapshot (Procedure)
sp_MSaddpub_snapshot (Procedure)
sp_MSchangerepllinkedsrvrpassword (Procedure)
sp_MSclear_dynamic_snapshot_location (Procedure)
sp_MScopyscriptfile (Procedure)
sp_MScopyscriptfile_merge (Procedure)
sp_MScreatemergedynamicsnapshot (Procedure)
sp_MSdetect_nonlogged_shutdown (Procedure)
sp_MSdropmergedynamicsnapshotjob (Procedure)
sp_MSdropmergepub_snapshot (Procedure)
sp_MSdrop_replcom (Procedure)
sp_MSdrop_repltran (Procedure)
sp_MSdrop_rladmin (Procedure)
sp_MSgetisvalidwindowsloginfromdistributor (Procedure)
sp_MSgetpartitionsnapshotfolder (Procedure)
sp_MSget_max_used_identity_from_distributor (Procedure)
sp_MShelpcolumns (Procedure)
sp_MShelpmergepub_withoutrownumbers (Procedure)
sp_MShelpmergepub_withrownumbers (Procedure)
sp_MSmergepublishdb (Procedure)
sp_MSmergepushsubscriptionagentjobcontrol (Procedure)
sp_MSmerge_log_idrange_alloc_on_distributor (Procedure)
sp_MSpeersendtopologyinfo (Procedure)
sp_MSproxylogshippingmonitorhelpprimary (Procedure)
sp_MSproxylogshippingmonitorhelpsecondary (Procedure)
sp_MSremovedbreplication (Procedure)
sp_MSreplhelp_jobhistory (Procedure)
sp_MSrepl_addlogreader_agent (Procedure)
sp_MSrepl_addpublication (Procedure)
sp_MSrepl_addpushsubscription_agent (Procedure)
sp_MSrepl_changelogreader_agent (Procedure)
sp_MSrepl_changepublication_snapshot (Procedure)
sp_MSrepl_changesubscription (Procedure)
sp_MSrepl_dropsubscriber (Procedure)
sp_MSrepl_getdistributorinfo (Procedure)
sp_MSrepl_gettype_mappings (Procedure)
sp_MSrepl_helplogreader_agent (Procedure)
sp_MSrepl_helppublication_snapshot (Procedure)
sp_MSrepl_helpreplicationdboptionex (Procedure)
sp_MSrepl_subscriptionagentjobcontrol (Procedure)
sp_MSrepl_subscriptionsummary (Procedure)
sp_MSscriptsubscriberprocs (Procedure)
sp_MSscript_update_statement (Procedure)
sp_MSsetupnosyncsubscriptionwithlsn (Procedure)
sp_MStablechecks (Procedure)
sp_ORAhelparticle (Procedure)
sp_reinitmergesubscription (Procedure)
sp_subscription_cleanup (Procedure)
sp_verify_job (Procedure)
sp_verify_jobstep (Procedure)
sp_vupgrade_registry_custom_resolver_katmai (Procedure)
       



News

  Query a named instance
Sybase+ASE+silent+install
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash