Click here to Skip to main content
16,004,727 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 2 have tables.
one is masterdatamodel and one is masterdataattr

in masterdatamdoel i have masterdatamodelid and mastertype.
masterdataattr i have field like masterdatamodelid,mastertype,attorder,attname,atttype

i should insert new data for masterdatamodelid.
suppose for masterdatamodelid data is 1
masterdataattr data ismastermodelid =1 attorder=1 attname="test" atttype="test123"
attorder=2 attname="test2" atttype="test1234"
mastermodelid=2 attorder=1 attname="test" attype="test123"
attorder=2 attname="test" attype="test1234"

so i have to give here condition.
SQL
ALTER PROCEDURE CORE.SP_InsertMasterModelATTR 
	(
	   @MasterModelId int
	  ,@AttributeOrder int
      ,@AttributeName char(50)
      ,@AttributeType char(10)
      ,@MasterType    char(50)
      ,@Required      char(1)
      ,@ValueUsedAsKey char(1)
      ,@DefaultValue   char(100)
	)
AS
BEGIN
	
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	Insert INTO CORE.MasterModelAttr 
	(
	   AttributeOrder 
      ,AttributeName 
      ,AttributeType 
      ,MasterType    
      ,Required      
      ,ValueUsedAsKey 
      ,DefaultValue   
	)
	values(
	   @AttributeOrder 
      ,@AttributeName 
      ,@AttributeType 
      ,@MasterType    
      ,@Required      
      ,@ValueUsedAsKey 
      ,@DefaultValue )


Iam trying to write condition its not working.can anyone please help on this.
Posted
Updated 1-Nov-12 11:13am
v3
Comments
chaau 1-Nov-12 17:08pm    
What errors are you getting?
sailaja reddy 2 1-Nov-12 17:13pm    
u should enter unique attroderid
sailaja reddy 2 1-Nov-12 17:14pm    
Thank for ur reply Andrew, iam getting errorlike u should enter unique attributeorder id no duplicate ids will accepct. is there anything i need to change here

1 solution

AttributeOrder is likely set up as your primary key in the MasterModelAttr table and that will be a problem.
Your issue is that you don't associate your records in the MasterModelAttr table with a specific MasterModelID.
I would create an auto-incrementing IDENTITY to act as the primary key in the MasterModelAttr table.
Then create a new foreign key column for MasterModelID.
Then create a unique constraint containing a combination of AttributeOrder and MasterModelID so that uniqueness is respected.

Create Multi Column Unique Constraint
SQL
CREATE TABLE T
{
   Name varchar(10) ,
   Location varchar(10) ,
         CONSTRAINT U_NameLocation UNIQUE (Name,Location) 
}
 
Share this answer
 
v3
Comments
sailaja reddy 2 1-Nov-12 17:24pm    
I have given identity for attribute order and foreign key for mastermodelid.
can you give example of how to give association between these two fields.
thanku in advance
damodara naidu betha 2-Nov-12 2:39am    
If you have Attributeorder as an identity column in your table, then why are you trying to insert a value into that? Engine takes care of it automatically.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900