﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SQL Server’da Tablonun Foreign Key İlişkisini Gösteren Prosedür &#8211; SQL Server Eğitimleri</title>
	<atom:link href="https://sqlserveregitimleri.com/etiket/sql-serverda-tablonun-foreign-key-iliskisini-gosteren-prosedur/feed" rel="self" type="application/rss+xml" />
	<link>https://sqlserveregitimleri.com</link>
	<description>SQL Server ile ilgili her şey</description>
	<lastBuildDate>Sat, 17 Mar 2018 22:00:58 +0000</lastBuildDate>
	<language>tr</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.1</generator>
	<item>
		<title>SQL Server’da Tablonun Foreign Key İlişkisini Gösteren Prosedür</title>
		<link>https://sqlserveregitimleri.com/sql-serverda-tablonun-foreign-key-iliskisini-gosteren-prosedur</link>
		
		<dc:creator><![CDATA[Yavuz Selim Kart]]></dc:creator>
		<pubDate>Sat, 17 Mar 2018 22:00:58 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server’da Tablonun Foreign Key İlişkisini Gösteren Prosedür]]></category>
		<category><![CDATA[Tablonun Foreign Key İlişkisini Gösteren Prosedür]]></category>
		<category><![CDATA[Tablonun Foreign Key İlişkisini Gösteren Prosedür Kullanımı]]></category>
		<guid isPermaLink="false">http://sqlserveregitimleri.com/?p=5001</guid>

					<description><![CDATA[Herkese merhaba, Bu kısımda SQL Server’da tablonun foreign key ilişkisini gösteren kodları olacak. create proc dbo.TablonunForeignKeyIliskisiniGosterenKod @table varchar(256) -- tablo adı , @lvl int=0 --seviye ,...]]></description>
										<content:encoded><![CDATA[<p>Herkese merhaba,</p>
<p>Bu kısımda SQL Server’da tablonun foreign key ilişkisini gösteren kodları olacak.</p>
<pre class="lang:default decode:true ">create proc dbo.TablonunForeignKeyIliskisiniGosterenKod
  @table varchar(256) -- tablo adı
, @lvl int=0 --seviye
, @ParentTable varchar(256)='' -- anatablo
, @debug bit = 1
as
begin
	set nocount on;
	declare @dbg bit;
	set @dbg=@debug;
	if object_id('tempdb..#tbl', 'U') is null
		create table  #tbl  (id int identity, tablename varchar(256), lvl int, ParentTable varchar(256));
	declare @curS cursor;
	if @lvl = 0
		insert into #tbl (tablename, lvl, ParentTable)
		select @table, @lvl, Null;
	else
		insert into #tbl (tablename, lvl, ParentTable)
		select @table, @lvl,@ParentTable;
	if @dbg=1	
		print replicate('----', @lvl) + 'lvl ' + cast(@lvl as varchar(10)) + ' = ' + @table;
	
	if not exists (select * from sys.foreign_keys where referenced_object_id = object_id(@table))
		return;
	else
	begin -- else
		set @ParentTable = @table;
		set @curS = cursor for
		select tablename=object_schema_name(parent_object_id)+'.'+object_name(parent_object_id)
		from sys.foreign_keys 
		where referenced_object_id = object_id(@table)
		and parent_object_id &lt;&gt; referenced_object_id; -- add this to prevent self-referencing which can create a indefinitive loop;

		open @curS;
		fetch next from @curS into @table;

		while @@fetch_status = 0
		begin --while
			set @lvl = @lvl+1;
			-- recursive call
			exec dbo.usp_SearchFK @table, @lvl, @ParentTable, @dbg;
			set @lvl = @lvl-1;
			fetch next from @curS into @table;
		end --while
		close @curS;
		deallocate @curS;
	end -- else
	if @lvl = 0
		select * from #tbl;
	return;
end
GO

--Kullanımı
exec dbo.TablonunForeignKeyIliskisiniGosterenKod 'Categories'
</pre>
<div class='epvc-post-count'><span class='epvc-eye'></span>  <span class="epvc-count"> 339</span><span class='epvc-label'> Kez Okundu</span></div>]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
