<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: mssql code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 17 May 2008 02:51:41 GMT</pubDate>
    <description>DZone Snippets: mssql code</description>
    <item>
      <title>Select DataBase Schema</title>
      <link>http://snippets.dzone.com/posts/show/4664</link>
      <description>// Select database schema.&lt;br /&gt;//This could be used to recreate or test for existence of columns/tables&lt;br /&gt;//or could also be used to create a database template system to enable the writing //of database schema into txt template file to be recreated again by reading the //txt file via an application&lt;br /&gt;//&lt;br /&gt;//You can also use SELECT * instead of defining each schema property (column)&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;SELECT TABLE_CATALOG&lt;br /&gt;, TABLE_SCHEMA&lt;br /&gt;, TABLE_NAME&lt;br /&gt;, ORDINAL_POSITION&lt;br /&gt;, COLUMN_DEFAULT&lt;br /&gt;, IS_NULLABLE&lt;br /&gt;, DATA_TYPE&lt;br /&gt;, CHARACTER_MAXIMUM_LENGTH&lt;br /&gt;, COLLATION_NAME &lt;br /&gt;FROM &lt;br /&gt;INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = (N'Persons')&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 17 Oct 2007 11:30:21 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4664</guid>
      <author>dubby (Dave)</author>
    </item>
    <item>
      <title>MSSQL 2005 - Add ID value to ID column when INSERTING </title>
      <link>http://snippets.dzone.com/posts/show/4521</link>
      <description>// @TableName is obviously the TABLE name u use&lt;br /&gt;// @ColumnName is obviously the COLUMN name u use&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;---Get next ID number&lt;br /&gt;	DECLARE &lt;br /&gt;		@ID int&lt;br /&gt;	&lt;br /&gt;	IF (SELECT count(*) FROM @TableName ) &gt; 0&lt;br /&gt;		BEGIN&lt;br /&gt;			SELECT @ID  = max(ColumnName ) from @TableName&lt;br /&gt;			SET @ID = @ID + 1 &lt;br /&gt;		END&lt;br /&gt;	ELSE&lt;br /&gt;	BEGIN&lt;br /&gt;		SET @ID  = 1&lt;br /&gt;	END&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 11 Sep 2007 07:50:29 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4521</guid>
      <author>dubby (Dave)</author>
    </item>
    <item>
      <title>SQL SERVER: Delete Duplicate Rows with Primary Id</title>
      <link>http://snippets.dzone.com/posts/show/4482</link>
      <description>Deletes duplicates (leaving one instance) where the table has a primary key. Good for tables with Id, DupColumn, DupColumn...&lt;br /&gt;&lt;br /&gt;(This is MS-SQL specific)&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;DELETE&lt;br /&gt;FROM 	TableName&lt;br /&gt;WHERE 	Id NOT IN&lt;br /&gt;	(SELECT 	MAX(Id)&lt;br /&gt;        FROM   		TableName&lt;br /&gt;        GROUP BY 	DuplicateColumName1, DuplicateColumName2)&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 31 Aug 2007 19:12:09 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4482</guid>
      <author>cornerblue (CornerBLUE, Inc.)</author>
    </item>
    <item>
      <title>Configure MSSQL Linked Server to DB2 (via ODBC System DSN)</title>
      <link>http://snippets.dzone.com/posts/show/3731</link>
      <description>1. Install DB2 on MSSQL machine&lt;br /&gt;2. Start Configuration Assistant. Add a new database mapping to the desired target DB2 database. Select option to create a System DSN along the way.&lt;br /&gt;3. Start Microsoft&#8217;s ODBC Data Source Administrator. There should be a System DSN created from the previous step. Configure it with the userid/password for the target DB2 database.&lt;br /&gt;4. Create linked server in MSSQL: EXEC sp_addlinkedserver @server = 'TMON', @srvproduct = '', @provider = 'MSDASQL', @datasrc = 'TMON'&lt;br /&gt;5. Map access to linked server: EXEC sp_addlinkedsrvlogin 'TMON', 'false', NULL, 'db2admin', 'db2admin'&lt;br /&gt;6. 2 ways to test the link: SELECT * FROM TMON..DB2ADMIN.USERS -- use uppercase for server, schema, table names SELECT * from OPENQUERY (TMON,'select * from users')&lt;br /&gt;&lt;br /&gt;Notes:&lt;br /&gt;    * TMON is the remote DB2 database, also used as the DSN name.&lt;br /&gt;    * Remote DB2 server uses access id: db2admin and password: db2admin&lt;br /&gt;    * USERS is a table in the remote DB2 database </description>
      <pubDate>Mon, 26 Mar 2007 08:49:53 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3731</guid>
      <author>wjchay (Chay Weei Jye)</author>
    </item>
    <item>
      <title>Setup for Performance Testing: Clear cache, buffers (MSSQL)</title>
      <link>http://snippets.dzone.com/posts/show/951</link>
      <description>For Microsoft SQL (MSSQL).&lt;br /&gt;Use this to clear the cache and buffers to ensure comparison are accurate.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;dbcc freeproccache&lt;br /&gt;go&lt;br /&gt;dbcc dropcleanbuffers&lt;br /&gt;go&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 08 Dec 2005 03:33:32 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/951</guid>
      <author>MattScilipoti (Matt Scilipoti)</author>
    </item>
  </channel>
</rss>
