How To Get Relation Between Two Feilds Of Same Table

Apr 18, 2007

Hi,
I am new to sql and is working with sql server managment 2005 +c# 2005.

My application needs to create a blockdiagram sort of thing say
if in my database i got a table 'Addition' with 'a', 'b', 'c',and the primary key addition_id, and c is related to a and b as c = a+ b.

there is stored procedure name usp_addition which contains this relation. Each time any insert or update is done this sp is executed and all the values are updated for accordingly.
My problem starts in the front end where i need to draw the graphical representation of table addition.

In this graphical representation, I need to draw the labels a, b, c and the arrows from a and b which will connect to c, showing that c has a, b as inputs.

I got the label using dataset and datacolumns but hte problem is how to create the arrows the name of labels (i.e my column names from which the arrow should start and end)

How does I get the information that c as two inputs a, b. I dont need the values since i just want to view the columns in table and which column is input to another column.


Since I need to do this dynamically because my tablename, and the number and name of column would differ does any body knows how to do this.


Priyadarshini

View 1 Replies


ADVERTISEMENT

Can You Explain This Error To Me? The Relation Property Of The Role Xxx Refers To The Target End Of Relation Xxx Which Is No

Mar 29, 2007

I'm getting this warning each time I auto-generate my model. I'm using named queries with logical primary keys.

The relation property of the role "xxx" refers to the target end of relation "xxx" which is not bound to a set of uniquely contrained columns.

I've searched and can't figured out what I am being warned about and whether I need to fix something. Can you help?

Thanks,
Toni



View 1 Replies View Related

Add Relation To New Table

Dec 29, 2003

If i add a new table to my database with a stored procedure, using that same sp or another can i also add a 1-M relationship with another table that is currently in the database. Please if you can provide an example.

Thank you,

View 1 Replies View Related

What Do We Call The Table That Does The N To N Relation

Dec 13, 2007

 When we have Table1 and Table2, then we
link both tables using a third table Table3 that relates n records in
Table1 to n records in table2, how do we call Table3? There is a name
in dataBase modeling for that, right?

View 1 Replies View Related

How To: Delete All Rows Without Relation To 2nd Table?

Feb 13, 2008

I'm a bit new to SQL, so this might be a very simple question, but I was not able to find an answer by search:

I got two tables, with a 1:n relation between them, seller and article, and I want to delete all sellers that do not offer any articles anymore.

An extract of my SQL to show the tables and the relation:

@"CREATE TABLE dbo.[Seller]
(
[ID] uniqueidentifier NOT NULL ROWGUIDCOL CONSTRAINT [PK_Seller] PRIMARY KEY,
) ON [PRIMARY]",
@"CREATE TABLE dbo.[Article]
(
[ID] uniqueidentifier NOT NULL ROWGUIDCOL CONSTRAINT [PK_Article] PRIMARY KEY,
[SellerID] uniqueidentifier NOT NULL,
) ON [PRIMARY]",

@"ALTER TABLE dbo.[Article] ADD CONSTRAINT [FK_ArticleSeller] FOREIGN KEY
(
[SellerID]
) REFERENCES dbo.[Seller]
(
[ID]
)",


Now say I got two sellers (1 & 2), and only one article (1, offered by seller 1). The delete query should delete seller 2 because he is not offering articles anymore.

This probably is dead simple in SQL, something like
DELETE FROM seller WHERE COUNT(article.SellerID=seller.ID)==0
but honestly, my SQL books leave me guessing here, and I found no online ref for cases like this.

Maybe someone can help me here?

Thanks in advance,
Sam

View 3 Replies View Related

T-SQL (SS2K8) :: Getting Records In N-Relation Table In One Select Statement?

Jun 9, 2014

I have 2 tables in a 1: n relation. How can i get a select statement that the field in the n-relation with outputs, separated by a semicolon; Example: One person have many Job Titles

Table1 (tblPerson)
Table2 (tblTitles)
1, "John", "Miller", "Employee; Admin; Consultant"
2, "Joan", "Stevens", "Employee, Software Engineer, Consultant"
and so on .... 1 in select statement:

View 1 Replies View Related

Multilevel Parent-Child Relation In Single Table

Nov 10, 2013

I have a table called "College". In a table, I have to create a structure for multilevel parent-child relationship

For Example,

1) State has number of colleges, Number of colleges has Number of dept. , Number of dept. has no. of subjects, no. of subject has number of chapters and the hierarchy goes on.

Expected Output is,
College 1
Dept 1
subject 1
subject 2
subject 3
Dept 2
Dept 3

[Code] ....

I tried in so many ways, I do not know how to query in single table.

View 6 Replies View Related

Parent Child Relation Ship Table In SQL Express

Jan 15, 2007

I want to build Parent child relation . i have two aproaches .I would like to know which is the best solution ?

1)1st method:-

Parent table with parent id . Child table with child id and parent id.Foreign key relationship exists between parent and child tables with cascade delete option enabled.

Parent TAble

Id name

1 XYZ

Child table

id name parent id

1 abc 1

2 qwe 1

2)2nd method

table with id and parent ID. Top level element will have null value in table. eg

id name parent id

1 xyz

2 abc 1

3 qwe 2

4 adf 1

Retrieve data using recursive queries supported in SQL Express.

Which is the best solution to store parent child relationship???



View 1 Replies View Related

Relation Table With Same Field From 2 Table

Jan 15, 2014

I have problem for create relation between table. I have one table refer to 2 table with same field. Here's the code.

create table TopHeadConfTbl (
PartNumber varchar(14) primary key not null,
TpHdTypeID varchar(4) not null)

create table BotHeadConfTbl (
PartNumber varchar(14) primary key not null,
BotHdTypeID varchar(4) not null)

create table QuoDetTbl(
MainAsID varchar(14)not null,
PartNumber varchar(14) not null references (TopHeadConfTbl,BotHeadConfTbl) ,
ItemNumber varchar(14) notnull)

View 3 Replies View Related

Max Number Of Feilds

Apr 28, 2004

hi all

having worked with access in the past and getting stumped by the fact a table could only hold 256 feilds....... does sql server have any such limit????

thanks

cq

View 7 Replies View Related

Devide 1 Feild Into 3 Feilds!

Oct 22, 2004

Hi there!

There is a feild in my table that contains the city, state and zip, all in the same feild. I was wondering how would be the best way to devide all that info up into 3 feilds? i really don't know how I would go about it since there are cities that can be comosed of 2 or more words. Here is some sample data. I hope someone can help.

SOUTH EL MONTE CA91733617
BOSSIER LA71172
GARDENA CA90249107
MILWAUKEE WI53216
PARIS IL61944
DUQUOIN IL62832
REDWOOD FALLS MN56283
AUBURN ME04210

IRWINDALE CA91706048
PORTLAND OR97202901
PORTLAND OR972028901
ANAHEIM CA928071735
KENT WA98032
CRYSTAL LAKE IL60014611

View 2 Replies View Related

SQL Query Multiple/Optional Feilds

Dec 3, 2004

Hello Group
I am having a little trouble with a search. I have 12 checkbox controls and 12 textbox controls. I want to be able to choose which textbox to query from. Most of the time the search may be from one or a couple of textboxes. My problem is I can get the SQL String right. Below is what I have for a string. I know I could write an SQL string for every possible combination and put in all 144 in a SELECT CASE, but I would think there is an easier way to do this. Is there anything that would let me build a SQL string depending what checkbox are checked true?


Dim SQL_SL As String = "SELECT * FROM BuildZone" & _
" WHERE Parcel = '" & strPercelS & "'" & _
" ORDER BY Parcel Asc" & _
" SQL_SL As String = SELECT * FROM BuildZone" & _
" WHERE fldNameLast = '" & strNameLastS & "'" & _
" UNION" & _
" SQL_SL As String = SELECT * FROM BuildZone" & _
" WHERE fldDateMonth = " & intDateYearS & "" & _
" AND fldDateYear = " & intDateYearS & "" & _
" UNION" & _
" SQL_SL As String = SELECT * FROM BuildZone" & _
" WHERE fldNameLast = '" & strNameLastS & "'" & _
" UNION" & _
" SQL_SL As String = SELECT * FROM BuildZone" & _
" WHERE fldPermitNum = " & intPermitS & "" & _
" UNION" & _
" SQL_SL As String = SELECT * FROM BuildZone" & _
" WHERE fldStructureType = " & intStructureTypeS & "" & _
" UNION" & _
" SQL_SL As String = SELECT * FROM BuildZone" & _
" WHERE fldConstructionCost >= " & intCCost1S & "" & _
" AND fldConstructionCost <= " & intCCost2S & "" & _
" UNION" & _
" SQL_SL As String = SELECT * FROM BuildZone" & _
" WHERE fldRange = " & intRangeS & "" & _
" AND fldTownship = " & intTownshipS & "" & _
" AND fldSection = " & intSectionS & "" & _
" UNION" & _
" SQL_SL As String = SELECT * FROM BuildZone" & _
" WHERE fldZoningDistricts = " & intZoneS & "" & _
" UNION" & _
" SQL_SL As String = SELECT * FROM BuildZone" & _
" WHERE fldTwsp = " & intTwspS & "" & _
" UNION" & _
" SQL_SL As String = SELECT * FROM BuildZone" & _
" WHERE fldRWD = " & intRWDS & "" & _
" UNION" & _
" SQL_SL As String = SELECT * FROM BuildZone" & _
" WHERE fldWW = " & intWWS & "" & _
" UNION" & _
" SQL_SL As String = SELECT * FROM BuildZone" & _
" WHERE fldAccessApplic = " & intAccessAppS & ""

Thanks

View 2 Replies View Related

Sorting Based On Foreign Key Feilds

Dec 1, 2006

shibu writes "I have a table 'manage_user_types' and its primary key is 'Category_ID'. There is another field 'Category_Parent_ID' which refers the 'Category_ID' in the same table. And one more field is 'Category_Name' which is related to 'Category_ID'. ie.when displaying the table in front end, 'Category_Name' is displayed under 'Category_Parent_ID'. I want to sort the table with 'Category_Name' when clicking the 'Category_Parent_ID' to sort. What should i do?"

View 1 Replies View Related

Select Distinct One Some Fields, But Return All Feilds

Jul 23, 2005

I was curious...Is there a way to select distinct on a combination of some fields andthe for each record returned also get the other fields of anarbitrarily chosen record matching the fields in the distinct record.For example, if I have a select distinct on say three fields:SELECT DISTINCT Code1, Code2, Code3but the table also has other fields, maybe Foo1 and Foo2, and I wantFoo1 and Foo2 to also be displayed. Since there may be multiplerecords that match a particular Code1, Code2, Code3, then I just wantone of those to be arbitrarily chosen.

View 3 Replies View Related

Table To Table Relation

Jan 30, 2008

Hi,
Any one tell me how to get table to table relation I want to Delete both Table's row When I am going to delete Record from One table.

Thanks

Navi

View 4 Replies View Related

How To Get This Relation(Need Sql Query)?

Dec 6, 2007

 Hi friendsI have one Table called tblCategory.I have three Column CatID, CatName, ParentIDI have many records in this TableCatID    CatName    ParentID1            Cat1            0 2            Cat2            13            Cat3            14            Cat4            25            Cat5            26            Cat6            07            Cat7            68            Cat8            69            Cat9            710          Cat10           711         Cat11            8  Here I have Main Category which has ParentID  0 [ Cat1 and Cat6 ]I Have Sub categories of Cat1 Which has ParentID  1(CatID 1 of Cat1) [ Cat2 and Cat 3 ]Cat 2 has also sub category with ParentID 2 (CatID 2 of Cat2) [ Cat4 and Cat5]I want result looks like asCat1                        Cat6       ->>>>>ParentID 0- Cat2                      -Cat7      ->>>>>ParentID 1(CatID of Root Cat1) and ParentID 6(CatID of Root Cat6)- - Cat4                     - -Cat9   ->>>>>PaerntID 2(CatID of Root Cat2) and ParentID 7(CatID of Root Cat7)- - Cat5                     - -Cat10   ->>>>>PaerntID 2(CatID of Root Cat2) and ParentID 7(CatID of Root Cat7) - Cat3                      -Cat8      -->>>>>ParentID 1(CatID of Root Cat1) and ParentID 6(CatID of Root Cat6)--No record               --Cat11    Can anybody give me solution?Thanks 

View 4 Replies View Related

First Occurrence From 1 To Many Relation

May 12, 2006

This one shouldn't be too hard to do, just can't seem to figure it out.

I have two tables
tNames which contains 'ID' and 'Name'
tLocations which contains 'ID' and 'Location'

each ID may be associated with many Locations

I want to run a query to display these results:
[ID, Name, Location]

but only to return the first Location associated with that ID (or the max, min, I don't really care as long as it's only one result)

right now I have

Code:


SELECT tNames.ID, tNames.Name, tLocation.Location
FROM tNames INNER JOIN tLocations
ON tNames.ID = tLocations.ID



but this returns a new row for each different Location of the same ID

Thanks.

View 3 Replies View Related

Foreign Key Relation

Jun 18, 2007

hi all

i want to insert null values into a column which is a foreign key
It has relation form other table.Is it possible to insert null to such a field .if so please tell the synatax to insert(i mean the process)

Thanks In Advance

Malathi Rao

View 3 Replies View Related

Remove Relation

Feb 12, 2008

Hi everyone...got a question.

How could i remove a relation from 2 tables using a script?

Thanks

RON
________________________________________________________________________________________________
"I won't last a day without SQL"

View 1 Replies View Related

Relation && Query

Jul 23, 2005

Hello,I'm relative new to sql and databases and the last few weeks I learnedmyself a lot. I'm trying to make a hotel reservation application.I have a database with a table Booking, a table Room, a tableRoomsPerBooking. So a booking contains date/time etc and a fieldRoomsPerBookingID. The table RoomsPerBooking contains number ofpersons, unitprice etc. and a field ID and a field RoomID. The tableRoom contains data like name, notes etc.now i have two questions:First about relations:The table Booking has relationship: PK table RoomsPerBooking - ID <-->FK table Booking - RoomsPerBookingID.The table RoomsPerBookingID has relationship: PK table Room - ID <-->FK table RoomsPerBooking - RoomIDIs this relationset good for my purpose? I think it is, but I am notsure.The second question is:How do I get available rooms per nightI came this far.... what are the "some statements"?CREATE PROCEDURE dbo.GetAvailableRooms(@BeginDate DATETIME,@EndDate DATETIME)ASSELECT Room.*FROM RoomWHERE Room.ID NOT IN (SELECT DISTINCT room.IDFROM Room room JOIN RoomsPerBooking roomsPerBookingON room.ID = roomsPerBooking.RoomID--Some statements--WHERE booking.FromDate <= @EndDateAND booking.ToDate >= @BeginDate)GO

View 1 Replies View Related

Load Relation From Diagram

Oct 9, 2006

I have defined a relation between 2 tables in "database diagrams" (IDE)but when a fill my tables vith a sqldataadapter i obtaina tables without relations why??how i can reslve this problem?my code is:Dim da As New SqlDataAdapter("SELECT * FROM table1", cn)Dim ds As New DataSetda.FillSchema(ds, SchemaType.Source, "table1")da.Fill(ds, "table1")--> ds.tables(0).relations.count =0 !!!!!!!!????????!!!

View 5 Replies View Related

ASPNETDB Relation With My Databas

Sep 8, 2007

HI!I have a ASPNETDB as my login databas. but now i want to connect this databas or the aspnet_user table to my table, how do i?I want to check the username in aspnet_user table and select the same username in my table?I want to write all sql code in a sql file. so i want to know how i can connect to the sql file from my c# code?I hope somebody understand me...

View 2 Replies View Related

One To Many Relation Ship Vs Look Up Field

Jan 2, 2001

hi, If I want to make one to many relationship, I put the pk of the parent as a fk in the child . like this
customer table (cust_id, fname,lname)
customer_order table(order_id,cust_id,qty,price)

I do understant this, but what about look up table, can I consider cust_id inthe customer_order table as a lookup field to the customer table?

Thanks
Al

View 1 Replies View Related

Many To One Relation - Is It A Good Idea?

Jun 11, 2008

Hi

I have about six different entities that can have zero or more note entities associated with them. The easy way to do this is obviously to have a different "note" table for each of the entities i.e. WorkItemNote, CustomerNote etc.. But I would much rather have a single "note" table since they would all be identical, so I came up with this design:


CREATE TABLE WorkItem
(
WorkItemGuid uniqueidentifier PRIMARY KEY DEFAULT (newid()),
-- rest of table declaration removed for bravity
)

CREATE TABLE Customer
(
CustomerGuid uniqueidentifier PRIMARY KEY DEFAULT (newid()),
-- rest of table declaration removed for bravity
)

CREATE TABLE Note
(
NoteId int IDENTITY(1,1) NOT NULL PRIMARY KEY,
ReferenceGuid uniqueidentifier NOT NULL,
Text ntext NOT NULL,
-- rest of table declaration removed for bravity
)


This way I can get notes associated with a given entity, either Customer or WorkItem, by just selecting from the Note table with its WorkItemGuid or CustomerGuid.

My question is: Is this the best approach to what I am trying to accomplish?

(ps: Apologies if "many to one" is not the right terminology)

Regards, Egil.

View 12 Replies View Related

Stored Procedure And Many To Many Relation

Mar 13, 2008

Hi,

This is my table setup

http://www.mshelp.be/img/logs.JPG

I want to retrieve the logs by profileId.

This is the stored procedure which I'm using. Don't get any syntax error, only not the correct output.


create procedure sp_Select_log_By_ProfileId
@ProfileId int
as
select
l.LogId, l.LogDescription, l.CreatedOn, l.LogAuthorId
from
Logs l inner join ProfileLogs pl
on
pl.LogId = l.LogId
where
pl.ProfileId = @ProfileId;


Can anyone help me ?

View 5 Replies View Related

Sql Code For UML Composition Relation - Anyone?

Jan 19, 2007

hi, I got confused for a moment about creating data structure for UMLcomposition (strong aggregation) relation one-to-many.I used Rose/DataModeler to do so.[Parent] <filled_diamond>-------- [Child]I got P/FK (primary key of my component is foreign key of it's container) inmy child table:Parent: PK Parent_IDChild: P/FK Parent_IDthat way I found out I got relation 1:1, I'm still not sure how to createdata structure realizing compositiona one-to-many.

View 4 Replies View Related

Relation Between 2 Tables In Different Databases

Nov 18, 2007

Hi All,
I have a little problem and i hope u will help me.
Well, my problem is, i want to make a relation between 2 tables which r not in the same databse.
Database D1 >>> Table T1
Database D2 >>> Table T2

So i want something like this:
Table T1:
ID >>> PK

Table T2:
ID >>> PK
Table1ID >>> FK from Table T1

so, i will have a relation between the 2 tables.
Thanks in Advance,

View 1 Replies View Related

How To Make Update Relation?

Mar 1, 2007

I have two tables: TableX & TableY

there is two similar fields (Size) with the same datatype, I want to make a relation in a way if I change the value in (TableX.Size) the same value will be applied to (TableY.Size).

How to?

View 4 Replies View Related

Physical Relation Database

Nov 7, 2007



I usually crate relation with database but not use physical relation
* My question is if crate physical relation is best way or not
and what advantage and disadvantage of physical relation
and if it the best way to make relation


thanks in advance

View 2 Replies View Related

Erroon Trying Take Make A Relation Between 2 Tables

Jun 27, 2007

I want a PK-FK relation between my tables:
Products (PK = ProductID)Orders = (FK = ProductID)
How can I do this in SQL 2005?
 
 

View 1 Replies View Related

Trust Relation - Linked Server

Nov 7, 2000

Hi Listers,

Can any one clarify me on the following doubt.

I have 2 w2k servers with different domains and On which SQL2k is running on both the Servers. Both the servers don't have any Trust Relations between them.

My questions is, Is it possible to create Linked Servers between sql servers but their Operating Systems doesn't have Trust Relationships?.

Any help would be appreciated.

tks in advance,
Sam

View 3 Replies View Related

Primary Key And Foreign Key Relation..URGENT!!!

Mar 11, 1999

Hi,

I have two tables.
CREATE TABLE Service(
SERVId varchar (10) NOT NULL,
SERVName varchar (30) NOT NULL,
SERVDesc TEXT NULL,
PRIMARY KEY(SERVId)
)



CREATE TABLE New(
SERVId varchar (10) NOT NULL,
NDId varchar (10) NOT NULL,
NDName varchar (30) NOT NULL,
NDDesc text NULL,
PRIMARY KEY(SERVId,NDId)
FOREIGN KEY(SERVId)
REFERENCES Service(SERVId)
)


Msg 547, Level 16, State 2
DELETE statement conflicted with COLUMN REFERENCE constraint 'FK__Newdev__SERVId__4939E6D2'. The conflict occurred in database 'test', table 'New', column 'SERVId'
Command has been aborted.


The same problem occurs even if the second table i.e. new is declared as follows, i.e created with only one primary key:
CREATE TABLE New(
SERVId varchar (10) NOT NULL,
NDId varchar (10) NOT NULL,
NDName varchar (30) NOT NULL,
NDDesc text NULL,
PRIMARY KEY(NDId)
FOREIGN KEY(SERVId)
REFERENCES Service(SERVId)
)


what might be the problem? But the same relation works on MS Access.
Is there anyother way of declaring this kind of relationship i.e. primary and foreign key?Can anyone pl. help me in solving this problem of foreign key relation.

thanks in advance
-chaitra

View 2 Replies View Related

SQL 2012 :: Dataset Relation In SSRS

Sep 24, 2014

Is there any way to find the dependency between two datasets in ssrs report. I want to delete one of dataset but need to find if I delete that it will work or any relation with the other dataset.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved