Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_adddatatype

  No additional text.


Syntax


-- Name:
--		sp_adddatatype

-- Description:
--		Add DBMS data type as an available type

-- Returns:
--		0 if successful
--		1 if failed

-- Security:
--		public

-- Notes:
--		Implicitly will create a DBMS if it doesn't currently exist.


CREATE PROCEDURE sys.sp_adddatatype
(
	@dbms			sysname,
	@version		sysname = NULL,
	@type			sysname,
	@createparams	int = 0
)
AS
BEGIN
	DECLARE @dbms_id int

    SET NOCOUNT ON

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

	-- Prepare dbms for case insensitive searches
	SET @dbms = UPPER(@dbms)

	BEGIN TRAN
	SAVE TRAN adddatatype
	
	-- Get DBMS id
	SELECT	@dbms_id = dbms_id
	FROM	msdb.dbo.MSdbms
	WHERE	dbms	= @dbms
	  AND	version = @version

	IF @dbms_id IS NULL OR @@ERROR <> 0
	BEGIN
		-- Add new DBMS
		INSERT INTO msdb.dbo.MSdbms (dbms, version)
		VALUES (@dbms, @version)
		
		IF @@ERROR <> 0
		BEGIN
			IF @@TRANCOUNT > 0
			BEGIN
				ROLLBACK TRANSACTION adddatatype
				COMMIT TRAN
			END
			RETURN (1)
		END
		
		SELECT @dbms_id = IDENT_CURRENT('msdb.dbo.MSdbms')
	END

	-- Verify data type doesn't already exist
	IF EXISTS
	(
		SELECT	datatype_id
		FROM	msdb.dbo.MSdbms_datatype
		WHERE	dbms_id	= @dbms_id
		  AND	UPPER(type COLLATE DATABASE_DEFAULT) =
			UPPER(@type) COLLATE DATABASE_DEFAULT
	)
	BEGIN
		RAISERROR (21655, 16, -1, @type)
		
		IF @@TRANCOUNT > 0
		BEGIN
			ROLLBACK TRANSACTION adddatatype
			COMMIT TRAN
		END
		RETURN (1)
	END
		
	-- Add data type
	INSERT INTO msdb.dbo.MSdbms_datatype (dbms_id, type, createparams)
	VALUES (@dbms_id, @type, @createparams)

	IF @@ERROR <> 0
	BEGIN
		IF @@TRANCOUNT > 0
		BEGIN
			ROLLBACK TRANSACTION adddatatype
			COMMIT TRAN
		END
		RETURN (1)
	END
	
	COMMIT TRAN
	RETURN (0)		
END

 
Last revision 2008RTM
See also

  sp_adddatatypemapping (Procedure)
sp_MSdrop_replcom (Procedure)
sp_MSrepl_DB2datatypes (Procedure)
sp_MSrepl_MSSQLdatatypes (Procedure)
sp_MSrepl_ORAdatatypes (Procedure)
sp_MSrepl_SASdatatypes (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