Commit c3ad7b45 authored by dwentzel's avatar dwentzel

added SampleDataContract.sql

parent cff0578a
SQLScripts
============
This is a repository for publicly available SQL Scripts I've created and moved from my website into a proper VCS. This repo contains a myriad of scripts.
This is a repository for publicly available SQL Scripts I've created and moved from my website into a proper VCS.
This repo contains a myriad of scripts.
DBA-in-a-Box
-------------
......@@ -18,20 +19,29 @@ DatabaseBuildProcess
---------------------
This is my old database build process. I have since migrated my new customers to the MD3 process which also resides in my git repo. MD3 uses PoSH so it's a little more modern. It also has a ton of usability improvements. There is still some code in here that I occasionally borrow however. MD3 can be found here: http://git.davewentzel.com/dwentzel/md3
CreateSnapshot.sql
------------------
http://www.davewentzel.com/content/automatic-database-snapshot-creation-script. Quickly creates a database snapshot and provides you with the commands to restore the db back to the snapshot. This is great when testing some code (not in prod) where transaction control may not be possible (such as testing service broker features or replication). This will allow you to quickly "roll back" any changes.
sysjobhistoryPurge
-------------------
http://www.davewentzel.com/content/blocking-and-contention-sysjobhistory. A utility that customizes what gets purged via sysjobhistory. Allows far more flexibility than what Microsoft provides natively. Also, the purge is "smart" and will not cause blocking and concurrency problems on instances with many, frequent SQL Agent jobs. Includes tsqlt unit tests.
http://www.davewentzel.com/content/blocking-and-contention-sysjobhistory. A utility that customizes what gets
purged via sysjobhistory. Allows far more flexibility than what Microsoft provides natively. Also, the purge
is "smart" and will not cause blocking and concurrency problems on instances with many, frequent SQL Agent
jobs. Includes tsqlt unit tests.
`CreateSnapshot.sql` : http://www.davewentzel.com/content/automatic-database-snapshot-creation-script.
Quickly creates a database snapshot and provides you with the commands to restore the db back to the snapshot.
This is great when testing some code (not in prod) where transaction control may not be possible (such as testing
service broker features or replication). This will allow you to quickly "roll back" any changes.
`PostRestoreSteps.sql` : http://www.davewentzel.com/content/post-restore-process. Train your staff to always
run this proc as part of their environment build and db restore process and you'll ensure your environment
(database at least) is always configured properly.
`SampleDataContract.sql` shows how to use data contracts in your stored procs to eliminate errors from SSIS,
SSRS, etc.
`UntrustedForeignKeys.sql` : http://www.davewentzel.com/content/find-and-fix-untrusted-foreign-keys. Finds and
optionally fixes (if it can) untrusted foreign keys in your database.
Please see my other public repos at http://git.davewentzel.com
PostRestoreSteps.sql
---------------------
http://www.davewentzel.com/content/post-restore-process. Train your staff to always run this proc as part of their environment build and db restore process and you'll ensure your environment (database at least) is always configured properly.
UntrustedForeignKeys.sql
------------------------
http://www.davewentzel.com/content/find-and-fix-untrusted-foreign-keys. Finds and optionally fixes (if it can) untrusted foreign keys in your database.
Please see my other public repos at http://git.davewentzel.com
\ No newline at end of file
USE tempdb
GO
IF OBJECT_ID('dbo.SampleDataContract') IS NOT NULL
DROP PROCEDURE dbo.SampleDataContract;
GO
/*
This code demonstrates how using a "data contract" in your procedure will
prevent "metadata" errors when you use temp tables.
See also:
http://www.davewentzel.com/content/ssis-and-data-contracts
*/
CREATE PROCEDURE dbo.SampleDataContract
AS
BEGIN
SET NOCOUNT ON
--uncomment this block to declare a "data contract" that will eliminate
--errors with tools that attempt to read the metadata of the output and fail
--because temp tables do not exist. Data contracts need to be near the top of the
--procedure
--remove this block to see the error in SSIS
IF 1 = 0
BEGIN
--declared data contract. Keep this code block in sync with the actual
--result set of the procedure
SELECT
CONVERT(BIGINT, 123) AS ID,
CONVERT(varchar(500),'test') AS Foo,
CONVERT(varchar(200),'test') AS Bar
END
CREATE TABLE #MyTempTable (
ID BIGINT NOT NULL IDENTITY(1,1) ,
Foo varchar(500) NOT NULL,
Bar varchar(200) NOT NULL
);
INSERT INTO #MyTempTable
SELECT name, type_desc
FROM sys.objects
SELECT ID,Foo,Bar FROM #MyTempTable;
END
GO
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment