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

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

foreigh key for composite primary key

Posted By:      Posted Date: October 14, 2010    Points: 0   Category :Sql Server


i created one table in stock management which contatins cascade primary key like below

Create table TblStockLocation
LocationName varchar(50),
RacNumber int(50),
constraint pkForStock primary key(LocationName,RacNo))

how I can reference this primary key in stock table

create table stock(productid tinyint primary key,

pname varchar(20),

productLocation ? data type references TblStockLocation(?)



is this is currect way please suggest



View Complete Post

More Related Resource Links

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

should i make that composite key into a 1-col primary key



Hi all, what i have now is this:

create table House(Id int identity(1,1)primary key, ..)

create table People(HouseId int not null references House, Id int not null, ..primary key(HouseId, Id))

so basically the Id column of table People is supposed to be auto-increment.

i've read this thread http://social.msdn.microsoft.com/forums/en-US/transactsql/thread/792a5b82-2d13-46bd-8650-a75a74ea222f but the solution is not concurrent (i think, or am i wrong)

should i recreate the People table and identify each "People" with a single auto-incrementing primary key, or should i create a stored procedure that maintains the calculation of the Id column in a concurrently safe way to "fake" autoincrementing?


ps: human and people tables is just a simulation to voice the problem more easily instead of using my actual tables

need to change primary key to a composite primary key.


This is a daunting task, because I have never done it before and don't want to seriously break anything. Basically I have a table with on primary key. I need to change the table to have a composite primary key. So do I first remove the primary key constraint and then proceed from their? I can do it through the GUI. It would be nice to know how to do it through sql though. Can anyone give me some guidance/help?

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.

Composite Control which contains arbitrary content defined in .aspx of parent and thier ViewState


I want to write own control which can contain other. And I want to define content of the control in the .aspx file where the control is defined. I have written such control. But now I have issue with ViewState of inner controls of my control. The following samle illustrates the issue: I defined two asp:DropDownList ID="ddl1" and ID="ddl2" One of them is inside of my control and other is outside. When posback is occurred asp:DropDownList ID="ddl1 loses state and becomes empty. How to say ASP.net to store state of inner controls defined by this way?


<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyControl.ascx.cs" Inherits="DynamicControls.Controls.MyControl" %>

<div class="box">
    <div class="Header-Left">
        <div class="Header-Right">
            My Control
    <div class="Content">
        <asp:PlaceHolder ID="contentPlace" runat="Server" />

video tutorial link for composite and rendered custom server control


hii all

i am new to technology so go easy on this post

according to what i read from web there are 3 type of custom server controls

1 superclass

2 composite

3 rendered

i found video tutorial for superclass custom server control but couldnt find video tutials for other 2.

please forward me link for composite and rendered custom server controls video tutorial  

require Video tutorial for Composite server control and rendered server control


hi guys

i am new to forum and technology so please go easy

according to what i read from web there 3 types of custom server controls

1. composite



i found video tutorial to create and use superclass custom control in your project (extending dropdown control functionality)

i am trying to search video tutorial for other 2 types .please help me.

Not getting multiple composite controls on master page


I have created two composite controls in the same assembly and registered that assembly in a master page using <%@ Register tag.

When I try to use these controls using the registered tag prefix I am getting only one control along with the tagprefix .

How to get all the composite controls present in the registered assembly?

Composite control: How to bubble a textbox's TextChanged event?


I've created a composite control that contains several controls, including a textbox. I'm trying to expose the TextChanged event of the textbox as an event on the composite control. I understand that events can be bubbled up the control hierarchy and handled at a higher level, which I've attempted to do, but I can't get the bubbled event to fire. When I drop the control on an aspx I can see the TextChanged event, I can subscribe to the event, but nothing ever happens. Any suggestions? Here is what I think is the relevant code:

// My event
private static readonly object EventTextChanged = new object();

//Handle the bubbled event
EventHandler textChangedHandler = (EventHandler)Events[EventTextChanged];

protected override bool OnBubbleEvent(object source, EventArgs e) 
    bool handled = false;

Localization not working in class library (composite control)



I have a class library called WEM.portal which used Resource files to localise text in my composite controls.

I store my resource files (eg MyResourceFile1.resx) in App_GlobalResources folder and then refer to them using

MyLabel1.text = My.Resources.MyResourceFile1.MyResourceKey1

This is all working ok until I create seperate files for each language such as MyResourceFile1.FR-fr.resx.

I have implemented this throughout my other web applications but the Class Library doesnt seem to want to work the same way

When I load the page it correctly showes the resourced keys which I have done through the web application BUT the resource keys in the composite controls does not seem to pick up the culture code.

Am I missing something stupid. Ive tried

  • changing the Build Action on the resource file to Content and Custom tool to GlobalResourceProxyGenerator
  • Creating a resourceManager but to no avail


Silverlight: Composite Web Apps With Prism


This article reviews the Prism project developed by the Microsoft patterns & practices group and demonstrates how to apply it to composite Web applications using Silverlight.

Shawn Wildermuth

MSDN Magazine July 2009

Prism: Patterns For Building Composite Applications With WPF


We introduce you to the benefits of building composite applications with the Composite Application Guidance for WPF from Microsoft patterns & practices.

Glenn Block

MSDN Magazine September 2008

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



User Control as Composite Control Property


I have a composite control (Called Dialog) which has a property "ContentControl"

At design time, I'd like this property to bind to a user control that is on the page.

When I add the items in the designer, the designer loads as expected.

However, when I try to run the web page, I get the following error:

Parser Error Message: Cannot create an object of type 'System.Web.UI.UserControl' from its string representation 'EditTerm1' for the 'ContentControl' property.

Please let me know if there is another way to bind a user control as a property of a composite control.


Designer Code:


	<cc1:Dialog ID="Dialog1" runat="server" Buttons="SaveCancel" 
Title="Edit Term" ContentControl="EditTerm1" />

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.



Developer Training: Composite Solutions in SharePoint 2010

Discover how composite capabilities in SharePoint 2010 can be combined to provide desired functionalities. This training module covers new site-scoped workflows and tools, as well as the steps needed to write connectivity between SharePoint and external systems.
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