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

Post New Web Links

Primary key

Posted By:      Posted Date: September 28, 2010    Points: 0   Category :ASP.Net

 Can we use more than one primary key in a table. 

plz help


View Complete Post

More Related Resource Links

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.

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.

Can't perform Create, Update or Delete operations on 'Table(outbox)' because it has no primary ke



I'm a beginner in asp.net and I have some problem inserting data into sql server 2005 with linq.


my code is : 


        Dim Result As New SMS.SendResult
        If Result.status = 0 Then
            Label1.Text = "Your Message Sent Successfuly"
            Dim db As New IGSSDataContext
            Dim out As New outbox With {.ClientID = intRandomNumber, .From = User.Identity.Name, .TO = TextBox1.TabIndex, _
            .Time = Now, .Message = Message}
            out.ID = (ID)
            TextBox1.Text = ""

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

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

Creating Sequence as Primary Key

Hi. I need to have a running number of 12 digits to be acted as ref number. it needs to be increment by 10.May I know how can I do that? Eg: Record 1  000000000001      Record 2 0000000000010

Primary Key Constraint Violation on Update

When UPDATING a single column (NOT the primary key column) of a transactionally replicated table, within MS SQL Server Management Studio, the replication monitor gives  Violation of PRIMARY KEY constraint 'PK_my_table. Cannot insert duplicate key in object 'my_table'. Statement Delivery is via the standard SCALL of dbo.sp_MSupd_my_table. The problem correlates with Statement Delivery of DELETE operations. That is, the problem exists if I specify "Do not replicate Delete Statements" and goes away if I specify standard behaviour for delete i.e a call on dbo.sp_MSdel_My_Table dbo.sp_MSupd_my_table does not appear to invoke deletion in any way and Im not updating the primary key value Any ideas Henrietta

Error Message: The referenced table must have a primary or candidate key. [ FK Name = FK_tblA_tblB ]

An Entity Data Model is used to generate the script to create  a SQL CE database.  It creates all of the 10+ tables and their primary keys without any problem. A lot of foreign key creations generate errors like the following: SQL Execution Error. Executed SQL statement ALTER TABLE [tblA] ADD CONSTRAINT [FK_tblA_tblB] FOREIGN KEY([A], [B], [C]) REFERENCES [tblB]([A], [BBB], [C]) Error Source: SQL Server Compact ADO.NET Data Provider Error Message: The referenced table must have a primary or candidate key. [ FK Name = FK_tblA_tblB ] The primary keys are there and correct. Could anyone offer some tips on how to figure out what is wrong?hz

Gridview Selected Value is Not a Primary Key

Hello,  I have 2 GridViews.  One is working perfectly.  What I would like to have happen is when a row is selected on GridView1 (with Primary key of OrderNumber), the matching records from the field in GridView1 ClientID to show up in GridView2. <asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="\\sjfileserver\data\database\S.J. Rollins Technologies Information Center.mdb" SelectCommand="SELECT [ClientID], [OrderNumber], [Field1] FROM [ORDERS] WHERE ([ClientID] = ?)"> <SelectParameters> <asp:ControlParameter ControlID="GridView1" Name="ClientID" PropertyName="SelectedValue" Type="Int32" /> </SelectParameters> </asp:AccessDataSource> <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID" DataSourceID="AccessDataSource2"> <Columns> <asp:BoundField DataField="CustomerID" HeaderText="ClientID" SortExpression="ClientID" /> <asp:BoundField DataField="OrderNumber" HeaderText="OrderNumber"

How can you use Linq to SQL to get the primary key of a record you've just inserted?

Hi,I'm inserting data into a database with Linq to SQL and would like to access the primary key of that record WITHOUT doing a query for the values I've already captured.Here is my insert startment: Dim page As New pageData With {.pageTitle = txtPageTitle.Text, .pageDescription = txtPageDescription.Text, .pageContent = HttpUtility.HtmlEncode(txtPageContent.Text) }There is a value in the table that is an auto increment integer.Rather than doing a query for the pagetitle, description and content I'd like to just access the primary key that I would have just generated by performing the insert.Is this possible or would I have to perform the query as I've just mentioned to retrieve it?

LINQ - Can't perform Create, Update or Delete operations on because it has no primary key.

Hi, not sure if I'm posting this thread in the right section. anyway, I''m trying to do the update/insert/delete using LINQ but the underlying table does not a primary key. The table consists of composite ket (e.g. fieldA & FieldB make a primary key). At the moment, I have LINQ complaning about not having a single primary key (not sure what LINQ does it - not making any sense at all). did anyone ever come across this issue and rectified it?  thanks

Two Primary key for table???

i HAVE FOLLOWING SCRIPT TO CREATE TABLE. create table Grade_report (STUDENT_NUMBER SMALLINT NOT NULL, SECTION_ID SMALLINT NOT NULL, GRADE CHAR(1), CONSTRAINT stno_secid PRIMARY KEY (STUDENT_NUMBER, SECTION_ID)) tHE BOLD line shows that it has two primary key. would that be possible to create two primary key for a single table??  If not then what does it for?? may be unique key??? anyone can explain me please.     Thanks,      

MVC is validating primary key which is identity

Hello,   I am following this tutorial : http://www.asp.net/mvc/tutorials/getting-started-with-mvc-part4 I am where you "Create" an entry  in the table, i have deleted the Id field, as Id is my primary key, and Is Identity = Yes, Identity Increment = 1, Identity Seed = 1. When i hit the create button, the Id value is being validated, giving an invalid error. If i add the Id column back to the page, and fill in any number and click create, the entry is added to the database, with the Id value incremented (the typed in value does not matter). I believe this must have to do with the Movies.Designer.cs... but not sure how to fix it. Id should not be validated as it auto-incraments, but the model is looking for a Id value.... How do i fix this?   Thanks, -Mike

passing a primary key value from a parent to a child viewmodel

I have a view (parent), a user control (child), and each have their own viewmodels. I need to tell the user control's view model what the parent's viewmodel primary key (PK) is. I am creating an instance of the child's viewmodel in the parent viewmodel, but I can't seem to get the child viewmodel to bind to the parent's PK value. Parent viewmodel:         private void Initialize()         {    CurrentParent currentParent;        // set the datacontext of the parent             if (NavigationActions.DataContext != null)             {                 CurrentParent = (ParentDto)NavigationActions.DataContext;             }             else             {                 CurrentParent = new ParentDto();             }        // create an instance of the child's view

Violation of PRIMARY KEY constraint 'PK_droughtDataTable_1'.

 Hello, I have a droughtDataTableAdapter which has the sqlINSERT INTO [droughtDataTable] ([StateName], [Moist], [Drought], [region], [district], [ID]) VALUES (@StateName, @Moist, @Drought, @region, @district, @ID) In the code I have the codeDataSet1TableAdapters.droughtDataTableAdapter k1 = new DataSet1TableAdapters.droughtDataTableAdapter(); for (int a = 0; a <= 254; a++) { k1.FillDrought( k[a][0], double.Parse(k[a][9]), double.Parse(k[a][12]), 1, k[a][1],a); }   However I got an error Violation of PRIMARY KEY constraint 'PK_droughtDataTable_1'. Cannot insert duplicate key in object 'dbo.droughtDataTable'. The question is that I don't have 'droughtDataTable_1', where is from for "_1"? The definition of the table droughtDataTable isStateName nchar(10) Moist float Drought float region smallint district varchar(50) ID int (Primary Key)   Thanks for help.
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