April 25, 2012

sp_getdefaultdatatypemapping (Transact-SQL MetaData) Definition

Please note: that the following source code is provided and copyrighted by Microsoft and is for educational purpose only.
The meta data is from an SQL 2012 Server.

I have posted alot more, find the whole list here.

Goto Definition or MetaData

Definition:

sys.sp_getdefaultdatatypemapping(nvarchar @source_dbms
, varchar @source_version
, nvarchar @source_type
, bigint @source_length
, int @source_precision
, int @source_scale
, bit @source_nullable
, nvarchar @destination_dbms
, varchar @destination_version)

MetaData:

   
--
-- Name:
-- sp_getdefaultdatatypemapping
--
-- Description:
-- Retrieve default data type for specified parameters
--
-- Returns:
-- 0 if successful
-- 1 if failed
--
-- Security:
-- Public
--
-- Notes:
--
--

create procedure sys.sp_getdefaultdatatypemapping
(
@source_dbms sysname,
@source_version varchar(10) = NULL,
@source_type sysname,
@source_length bigint = NULL,
@source_precision int = NULL,
@source_scale int = NULL,
@source_nullable bit = 1,
@destination_dbms sysname,
@destination_version varchar(10) = NULL,
@destination_type sysname OUTPUT,
@destination_length bigint OUTPUT,
@destination_precision int OUTPUT,
@destination_scale int OUTPUT,
@destination_nullable bit OUTPUT,
@dataloss bit OUTPUT
)
as
BEGIN
DECLARE @retcode int
SET @retcode = 0

--
-- Security Check: require sysadmin
--
IF (ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) = 0)
BEGIN
RAISERROR(21089,16,-1)
RETURN (1)
END


-- Check if type even exists
IF (sys.fn_MSrepl_checktype(@source_type, @source_dbms, @source_version) = 0)
BEGIN
RAISERROR(21654, 16, -1, @source_type)
RETURN (1)
END

SELECT @destination_type = destination_type,
@destination_length = destination_length,
@destination_precision = destination_precision,
@destination_scale = destination_scale,
@destination_nullable = destination_nullable,
@dataloss = dataloss
FROM sys.fn_MSrepl_getdatatypemappings
(
@source_dbms,
@source_version,
@source_type,
@source_length,
@source_precision,
@source_scale,
@source_nullable,
@destination_dbms,
@destination_version,
1,
NULL
)

IF @@ROWCOUNT = 0
BEGIN
RAISERROR (21656, 16, -1, @source_type)
RETURN (1)
END

RETURN (0)
END

No comments:

Post a Comment

Total Pageviews