.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

How to get all the foreign key references for a primary key

Posted By:      Posted Date: August 28, 2010    Points: 0   Category :Sql Server
Hi ,  I would like to know all the foriegn key references in the db for a table's primary key..How can i get that? Thanks sunil m datla

View Complete Post

More Related Resource Links

How to know foreign key references for a table

Hi, For a parent table, having a parent id, is it possible to know all the child tables? for e.g if TABLE1 has PK1 as primary key, TABLE2 has PK2 which is a foreign key refering to TABLE1 and TABLE3 also has a foreign key referecing TABLE1 and many others.. is it possible to know all the child tables for table TABLE1?? Thanks,

Foreign & Primary Keys


I have the following FK on Items table

ALTER TABLE [dbo].[items]  WITH NOCHECK ADD  CONSTRAINT [FK_items_i_tmpnam] FOREIGN KEY([i_tmpnm_id])

REFERENCES [dbo].[i_tmpnam] ([tmpnam_id])



Yet I'm able to delete all records from i_tmpnam and leave orphans in the FK field in the Items table. So, does NOCHECK disables the constraint completely?


Premature optimization is the root of all evil in programming. (c) by Donald Knuth

Naomi Nosonovsky, Sr. Programmer-Analyst

My blog

primary key and foreign key function generated values



how to generate invoice type of key ex:emp100 with unique identifier

i generated invoice type by creating function by concatenate string and unique identifier 

but it can't be reference to another table

 can i have any other types generating invoice type primary key and used as a reference type


foreign key to reference composite primary key


Hello all!

I am new to tsql so please be kind if this is bad idea.  I am using visual studio, thus why everything is split up.
I am writing software that allows the user to "turn on" customizable tables to use.  each table is the same.  so for brevity in the database i made a single table 'User'.

CREATE TABLE [dbo].[User]
 U_Table    int     NOT NULL,
 U_ID     varchar(50)   NOT NULL


ALTER TABLE [dbo].[User]

the primary key is made up of a table id (which user-customizable table) and the record id
now i have a transaction table that holds the id's used for each user customizable table

CREATE TABLE [dbo].[Transaction]
TRAN_ID      int     NOT NULL,
TRAN_User_01    varchar(50)   NULL,
 TRAN_User_02    varchar(50)   NULL,
 TRAN_User_03    varchar(50)   NULL,
 TRAN_User_04    varchar(50)   NULL

My question is, i want to add a foreign key relationshi

SQL Server Mgmt Studio - primary/foreign keys


I currently have a number of tables in my database, which include these 2 tables:

tblOne - Uid(pk), FirstName, LastName, Email

tblTwo - HCCID(pk), Uid, Category, Description, Company, Manager


In my application I have users from tblOne logging in and creating records which are inserted into tblTwo. Thankfully this is working ok, however, my problem is with the Uid in tblTwo (fk).

When a new record is created in tblTwo, the HCCID(pk) iterates, so i have a numeric identifier for each record. However is there any way i can also keep a record of the user by recording the Uid in tblTwo based on which user creates the record?

Seeing as though this is already a pk in tblOne and I also already have a pk in tblTwo, is this possible?

Any ideas will be greatly appreciated!

When doing Snapshot Replication and Transactional Replication, are the Foreign Keys and Primary Keys

When doing Snapshot Replication and Transactional Replication, are the Foreign Keys and Primary Keys replicated?

Foreign Key Drop downlist available in edit mode even though part of primary key


I am using Dynamic Data 4 in VS2010 with EF4.

So I have noticed and read that DD using Entity Framework does not allow editing of primary keys in a scaffolded table...fair enough...I don't know if its a difference between developing in SQL Server vs Oracle but often in our database we use composite primary keys that consists of several columns in a table (as in not generated ids, or unique ids as the primary key).  
So I have a table that has a primary key that that consists of two text fields and a foreign key from another table.  I have a custom entity template that i use to insert new records into the table.  When I select new, I get the desired behavior of a dropdown for the foreign key field to pick to insert a new record.  That works great.  When I select edit on a row in the table, I still get that dropdown!  Of course if I select a different entry from the dropdown DD yells at me since the foreign key field is part

So I have noti

Surrogate vs Natural Primary Keys - Data Modeling Mistake 2 of 10

In case you're new to the series I've compiled a list of ten data modeling mistakes that I see over and over that I'm tackling one by one. I'll be speaking about these topics at the upcoming IASA conference in October, so I'm hoping to generate some discussion to at least confirm I have well founded arguments.

The last post in this series Referential Integrity was probably less controversial than this one. After all, who can argue against enforcing referential integrity? But as obvious as surrogate keys may be to some, there is a good deal of diversity of opinion as evidenced by the fact that people continue to not use them.

Rendering ASP.NET Script References into the Html Header

One thing that I've come to appreciate in control development in ASP.NET that use JavaScript is the ability to have more control over script and script include placement than ASP.NET provides natively. Specifically in ASP.NET you can use either the ClientScriptManager or ScriptManager to embed scripts and script references into pages via code.

*.axd script references not being rendered to browser


I'm running VS2010 with .net 4.0, and am running into issues with the .net ajax script tags mysteriously not being rendered to the browser.

So far I've reduced it to a scenario where I set the DataSourceID property of a databound control.  More specifically, I've only tested it on a Gridview and a DropDownList.

This can be reproduced fairly easily on my machine by following these steps:

1. Create a new empty Web Application Project

2. Create a new Web Form

3. Add a ScriptManager inside the form

4. Add a DropDownList and a DataSource (I used an ObjectDataSource)

5. Set the DataSourceID property of the DropDownList to the ID of the DataSource.  This can be done either declaratively on the .aspx page, or in the code behind in the aspx.cs page, and both produce the same results.

6. Open the page in a browser and watch as you get a javascript error stating "Sys is not defined" and notice that the page source contains no script tags referencing *.axd scripts.

Here's my source code showing my set up:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ScriptResourceFAIL.Default" %>


Could not find default endpoint element that references contract 'CurrencyProxy.CurrencyServiceSoap



I created 2 projects in my solution:

  1. Classic asp.net web service (asmx)
  2. Class library project which references service
  3. web site project which references class library project
  4. Windows app project which references service.

Both projects were created in 3.5 framework and in Visual Studio 2008 Beta 2.

I added web service reference to Class library project. When it asked for namespace I typed "CurrencyProxy". Projects build ok, but when I run web app, Class library throws an error: Could not find default endpoint element that references contract 'CurrencyProxy.CurrencyServiceSoap' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

I believe it has something to do with app.config in Class library project. Here is part from app.config:

<binding name="CurrencyServiceSoap" closeTimeout=

Test Run: Determining .NET Assembly and Method References


Before you can test any software system effectively, you must understand the system under test. If the system includes the Microsoft® . NET Framework, understanding the system under test includes understanding its assembly and method dependencies.

James McCaffrey

MSDN Magazine March 2006

Delegates in .NET: A Primer on Creating Type-Safe References to Methods in Visual Basic .NET


Delegates, new in Visual Basic .NET, are type-safe, object-oriented references to methods. By using delegates, you make your methods accessible to others and therefore more extensible. This article provides an introduction to delegates, their benefits, and how they are used.Here the author shows you how to declare, create, and use delegates to invoke instance and shared methods at run time, and how to implement delegates as properties. He then goes on to provide examples of how delegates are used for callback functionality and explains the relationship between delegates and events. Finally, the article provides a glimpse at how delegates are implemented in intermediate language code by the Visual Basic .NET compiler.

Jesse Liberty

MSDN Magazine February 2003

Passing Primary Key to User Control to Display Record Detail


I'm building a user control to display detail information on a parent record. The user control will be displayed via an Ajax Modal Popup. The user control works and is displayed when expected. The problem that I'm having is that I'm not able to pass in the primary key for the parent. The control is displayed via the _ItemCommand event of a Repeater. In the markup for the user control, I explicity set the ContactId to 0 to avoid an error when the control loads (its still underdevelopment, eventually that I'll check if the value is valid).

I was assuming that I could change the property in the _ItemCommand event, but obviously its not working.

In the Page_Load event this code successfully sets the ContactId property of the control. The _ItemCommand event appears to set the value. However when I set a test label on the user control to the Me.ContactId, its showing '0' as if it was never passed in.

        UserControlContactDetail.ContactId = "1462"
        test.Text = UserControlContactDetail.ContactId

    Protected Sub RepeaterDirectory_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles RepeaterDirectory.ItemCommand

Protected Sub RepeaterDirectory_ItemCommand(By

Using Ref as an increasing primary key value


Hi. I need to set the Ref value as an increasing value starting with the number 2010 ... it will be a 12 digits characters.

I tried using identity but it doesn't work. Could anyone advice on how should one could insert an increment of 10 to the ref value? In case, my explaination is not clear, below is an example.

For an example:

Record 1: ref - 201000000123

Record 2: ref - 201000000133

Record 3: ref - 201000000143



Primary Key In Share Point 2007/ 2010


Can I create 3 columns Primary key in a list using the MOSS 2010 or 2007

Actually My requirement  is

I collect some information by Country,State,Dist wise Temperature


1.  India-Andraprades-Hyderabad-Temp-30

2.  India-Andraprades-KarimNagar-Temp-30

here first 2 column is Same but 3rd column is different that's I required 3 column is Primary Key


Any one help me.



Using table with no primary key in CTP4



Does anyone knows if CTP 4.0 supports table with no primary key. I know Entity framework does.

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend