Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    MS SQL Server


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





What Relationship To Use Between These Two Table?


Hi I have two tables:

1.) Operator
-OperatorID{PK, int, not null}
-OperatorName{varchar(100), not null}
-Enabled{bit, not null}
-PasswordChange{bit, not null}
-BirthDate{datetime, not null}

2.) Password
-PasswordID{PK, int, not null}
-Password{varchar(50), not null}
-ExpirationDate{datetime, not null}

I'm not sure how to design and layout these two tables. The layout of these two tables is completely flexible as the application has not been deployed. I'm open to any good suggestions.

For each Operator I want to stored up to 3 previous passwords plus their current password. The password change field is so that if the operator's password expires or gets reset, they will be forced to enter a new password. This is a simple internal company application, so password encrypting is not necessary. The ExpirationDate indicates the date that the password will expire.


Hope to hear from someone soon! Thank you!




View Complete Forum Thread with Replies

Related Forum Messages:
Why I Got The Message As You Need To Create The Many-to-one Relationship Between The Case Table And The Nested Table?
Hi, all experts here,

 

Thank you very much for your kind attention.

 

I am trying to create a new mining structure with case table and nested table, the case table (fact table) has alread defined the relationships with the nested table(dimension table), and I can see their relationship from the data source view. But why the wizard for creating the new mining structure showed that message? Why is that? And what could I try to fix it?

Hope it is clear for your help.

Thanks a lot for your kind advices and I am looking forward to hearing from you shortly.

With best regards,

Yours sincerely,

 

View Replies !
How Can I Create A One-to-one Relationship In A SQL Server Management Studio Express Relationship Diagram?
How can I create a one-to-one relationship in a SQL Server Management Studio Express Relationship diagram?

For example:
I have 2 tables, tbl1 and tbl2.

tbl1 has the following columns:
id {uniqueidentifier} as PK
name {nvarchar(50)}

tbl2 has the following columns:
id {uniqueidentifier} as PK
name {nvarchar(50)}
tbl1_id {uniqueidentifier} as FK linked to tbl1.id


If I drag and drop the tbl1.id column to tbl2 I end up with a one-to-many relationship. How do I create a one-to-one relationship instead?

mradlmaier

View Replies !
Table Relationship
Hello, I created some SQL 2005 tables using Microsoft SQL Server Management Studio. I need to get the script code of those tables. I was able to do that by right clicking over each table. But how can I get the code for the relationships between the tables? Can't I create relationships between two tables by using T-SQL? Thanks, Miguel

View Replies !
Table Relationship
hi all,

Does anybody know how to check if a table has a child table?

Thanks a lot!

Mimi

View Replies !
Naming Of Relationship Table
We have two tables. Users and Projects and there is a many-to-many relationship.Ex. A user can be assigned into multiple projects.For the relationship table, should the table name be UserProjects or ProjectUsers?Also should it be singular or plural? (ex. UsersProjects or ProjectsUsers)?

View Replies !
Relationship Inside The Same Table
i ve got a database that has a table...that table has a relationship between its primary key,and another field,actuelly i did it for doing menus and sub menus,so each menu has an ID say menuID and it has DEPTH and parentID which is the menuID of the parent...the problem is that i can not use "Cascade update Related Fields" or "Cascade Delete Related Records" which are really necessary ...for example when deleting parent ,not to have a child lost :)i hope i ll have an answer soon,and thanks in advancedPS: i am using MSSQL 2000 evaluation

View Replies !
Define More Than One Relationship Per Table?
Why is it not possible to define more than one relationship per table?

i have a primary table that i would like to cascade deletes to 2 other foreign tables in 2 separate relationships. why can't i do this and what are my alternatives?

thank you

View Replies !
Combine Relationship Table
Hello everyone:

I have two database desgin questions. I hope could get some helps here to resolve my puzzle.

suppose I have a parent table which has many-to-many relationship to its three children tables. E.g:

Parent table:
webpage
-pageID
-pageTitle

child table: (which are the content could be in the webpage)

Picture
---pictureID
---pctureName

StreamVideo
--videoID
--videoName

StreamAudio
--audioID
--audioName

Normally, in a many-to-many relationship, a third table will be introduce to break down the many-to-many into one-to-many relationship. So in this case, I will have three relationship tables

1. Webpage--Picture
--pageID
--pictureID

2. Webpage--Video
--pageID
--videoID

3. Webpage--Audio
--pageID
--audioID

My question is should I combine this three relationship table into one big relationship table like:

Webpage--content
--pageID
--pictureID
--videoID
--audioID

I know the drawback of this combining will cause redundant, but this could avoid join tables when writting query (especially when there are more child table associate with one parent table). Also I was told that foreign key can be nullable, so if one webpage only have pictures, as long as I insert pictureIDs with the null value videoIDs and audioIDs into the Webpage--content table, then it seems I don't duplicate anything. So far I don't see anything wrong with this approach, I hope someone can give me some suggestions whether I should go this way.


My another question is also about the relationship table, suppose in the above exmaple, we won't combine those three relationship tables. But we need to assign a value to each pictureID, videoID, audioID. And this value will be different if a pictureID, videoID, aduioID appears in different webpage. How I should solve this issue? The best I can think so far is add a value column in the relationship table. But I have not seen people did this before. Add columns into a relationship table. Is this a good desgin?

View Replies !
Table Relationship In VB Express
I
have 3 tables I am trying to relate for a music player.  I was
following the example in the msdn however, my relationships do not seem
right.  Here are tables i want to relate:

Table 1:
ArtistID
ArtistName:

Table 2:
RecordingID
RecordingName
ArtistID

Table 3:
TrackID
TrackName
TrackNumber
TrackLocation
RecordingID

So
the main idea here is that the foreign keys are recordingId and
artistID.  So what i did is created the 3 tables and then make a
diagram to create the relationships.  I then was reading this post:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=219696&SiteID=1

What
i want to do is use 2 different text boxes lets say and as i move from
the records in the Record_table (2) the corresponding artist will
change with it.  However in the dataset the relationship looks like
this:
Artist -> Recording -> Track.... inorder for me to get
this relationship to work correctly i have to change all the
relationships in the dataset diagram.  This way the dataset would look
like this: Track -> Recording ->Artist.   This way i can use the
2 bindings to reference each other as stated in the link above.  why
doesnt the relationship of the database know this already?  why do i
have to change the relationship in the datasets.

View Replies !
Create Table With Many-to-many Relationship...
Hi, I come back again.
Can anyone help me to create table with many-to-many relationship. Here is my three tables
tbl_Networks
(
NID int identity(1,1) primary key,
NetworkName nvarchar(256)
)

tbl_Categories
(
CID int identity(1,1) primary key,
CateName nvarchar(256),
NID int
)

tbl_Sim
(
SID int identity(1,1) primary key,
NID int,
CID int,
NameOfSim nvarchar(256)
)
My problem is 1 value in tbl_Sim may have multiple values in table tbl_Categories and vice versal. And I don't know how to organise them


So I need some help...

View Replies !
Table Relationship. What Am I Doing Wrong?
Hello,

I have 3 tables: Articles, ArticlesTags and Tags.
ArticleTags relate Articles and Tags records.

When I try to delete a record in Tags I get the following error:

The DELETE statement conflicted with the REFERENCE constraint

"FK_ArticlesTags_Tags". The conflict occurred in database "MyDB", table "dbo.ArticlesTags", column 'TagID'.
The statement has been terminated.

What am I doing wrong?

Here is how I am creating my tables:

create table dbo.Articles
(
ArticleID uniqueidentifier not null
constraint PK_Article primary key clustered,
Body nvarchar(max) not null

)
create table dbo.ArticlesTags
(
ArticleID uniqueidentifier not null,
TagID uniqueidentifier not null,
constraint PK_ArticlesTags
primary key clustered (ArticleID, TagID),
constraint FK_ArticlesTags_Articles
foreign key(ArticleID)
references dbo.Articles(ArticleID)
on delete cascade,
constraint FK_ArticlesTags_Tags
foreign key(TagID)
references dbo.Tags(TagID)
)
create table dbo.Tags
(
TagID uniqueidentifier not null
constraint PK_Tag primary key clustered,
[Name] nvarchar(200) not null
)

Basically, what I need is:

1. If an Article is deleted then:
> Delete all records for that Article in ArticlesTags
> Don't delete any Tag in Tags.

2. If an Tag is deleted then:
> Delete all records associated with it in ArticlesTags.
> Don't delete any Article in Articles.

What am I missing?

Thanks,
Miguel

View Replies !
Problems Creating Second Relationship To The Same Table
I have two tables: ads and categories. I have an existing relationship: categories.id (PK) and ads.categoryid (FK). Now I want to create additional relationship with categories.id (PK) on ads.SecondCategoryID (FK). When I try to save it in SQL Manager I get the following error:
- Unable to create relationship 'FK_classifieds_Ads_classifieds_Categories2'.  The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_classifieds_Ads_classifieds_Categories2". The conflict occurred in database "mydb", table "dbo.classifieds_Categories", column 'Id'.
 

View Replies !
Create Table With Recursive Relationship
I am fairly new to SQL and I am currently trying to createa SQL table (using Microsoft SQL) that has a recursiverelationship, let me try to explain:I have a piece of Data let's call it "Item" wich may again contain onemore "Items". Now how would I design a set of SQL Tables that arecapable of storing this information?I tried the following two approaches:1.) create a Table "Item" with Column "ItemID" as primary key, somecolums for the Data an Item can store and a Column "ParentItemID". Iset a foreign key for ParentItemID wich links to the primarykey"ItemID" of the same table.2.) create separate Table "Item_ParentItem" that storesItemID-ParentItemID-pairs. Each column has a foreign key linked toprimary key of the "Item" Column "ItemID".In both approaches when I try to delete an Item I get an Exceptionsaying that the DELETE command could not be executed because itviolates a COLUMN REFERENCE constraint. The goal behind these FK_PKrelations is is that when an Item gets deleted, all childItems shouldautomatically be deleted recursively.How is this "standard-problem" usually solved in sql? Or do I inned toimplement the recursive deletion myself using storedprocedures or something ?

View Replies !
Want 1 To Many Relationship When Child Table Has No Primary Key
I want to create a 1-many relationship. Parent table has a primarykey, child table has no primary key. The child table does have anindex with all four fields of the parent's PK. How can I do this?Thanks, Bob C.

View Replies !
Search On Table With Recursive Relationship
I am using tables with recursive relationships extensively. For example the table tbComponent has a primary key called Co_ID and a foreign key called Co_Co_ID which references the field Co_ID. This allows a component to have unlimited child components, and each child component can have an unlimited number of tiers of children. I have a few question for which I have seen no documentation on.

1. How can I create a view or a SP that will return a component record and all of its children and children's children records down to the last/lowest child record?

2. I need to be able to do a search in this table. Example:

Table: tbComponent
Columns: Co_ID Integer
Co_Co_ID Integer
Co_Name Text
Co_Attribute Text
Co_Category Text


Note: the data for Co_Category comes from a lookup table with also has a recursive relationship to itself where a category can have an unlimited number of tiers of children categories.

A typical group of records could be something like this:


Co_ID Co_Co_ID Co_Name Co_Attribute Co_Category

1 1 Car Blue Ford
2 1 Body Steel Parts
3 2 Door Front Parts
4 3 Invoice April 1 1999 Accounting

Ok, say there is over a million records in this table. Say I want to query this table and return all of the invoices for cars between March 1 1999 and May 1 1999. Say for example that there are less records where Co_Name has a value of Car then there are records with a value of Invoice, so logically I would set some kind of criteria to limit only invoices with where Co_Name = "Car". That's easy, I can return a result set of all the records Where Co_Name = "Car" and I can hold these in a view or a temp table. Now I need to query this View or temp table and see if it has any children records records Where Co_Name = "Invoice" . The problem is that the Invoice child could be a child record directly under the "Car" record, or 10 levels of children records down. The logic for this would be:

If Co_Name = "Car" Then Select * Where Co_Co_ID = 1, then take all of those record's values in Co_ID and run another statement Where Co_Co_ID = X and so on until there are no more children to search. If any of those records have a value of Invoice in Co_Name then return them.

Please don't give any speeches on Normal Relationship Database design suggesting a typical design using something like a Car table, a parts table, and a invoice table. I used the example above to demonstrate the dynamics of doing a search on a recursive relationship. I understand relationship theory and a recursive relationship is what we need to use in our situation.

Thanks for any and all input!

View Replies !
Create A View For One-to-many Relationship Table
hi..

I would like to create a view for two tables which have a one-to-many relationship.


Code:


Table: Supplier
Supp_ID
1

Table:Supplier_category
Supp_ID,StockCategoryID
1,56
1,57
1,90



How can i create a view that has columns like below:
Supp_ID, Stock
1,[56,57,90]

Thanks in advance.

View Replies !
How Can I Get Primary Key Col And Other Two Cols In The Same Table Become One To One Relationship.
For ex.

Table  Match_List ( MatchID, UserID_A, UserID_B)

constraints like

MatchID primary key

UserID_A <> UserID_B

unqiue index (UserID_A,UserID_B)

but I wish to  exclude  duplicated rows like 1,1,2 & 2,2,1,

cause UserA to UserB, and UserB to UserA are the same thing.

How can I get this?

 

View Replies !
Trying To Enforce Ref Integrity On Hierarchy Table Relationship
I've got a table that includes:CREATE TABLE [dbo].[Content] (  [Id] int IDENTITY(1, 1) NOT NULL,  [ParentId] int NULL,
I'm wanting to make sure that a ParentId must be in the table as Id someplace else.  When I try to do it by making it a foreign key  get the error:
--------------- SQL ---------------
ALTER TABLE [dbo].[Content]ADD CONSTRAINT [Content_fk3] FOREIGN KEY ([Id])   REFERENCES [dbo].[Content] ([ParentId])   ON UPDATE NO ACTION  ON DELETE NO ACTIONGO
---------- ERROR MESSAGE ----------
There are no primary or candidate keys in the referenced table 'dbo.Content' that match the referencing column list in the foreign key 'Content_fk3'.Could not create constraint. See previous errors.
 
Any ideas? 
 
ALTER TABLE [dbo].[Content]ADD CONSTRAINT [Content_fk3] FOREIGN KEY ([Id])   REFERENCES [Content].[dbo] ([ParentId])   ON UPDATE NO ACTION  ON DELETE NO ACTIONGO
 

View Replies !
Database Table Data Modifications With PK/FK Relationship
I have two tables (T1 and T2). In T1 I have a field FT1 that is aprimary key in T2 I have a field FT2 that is a foreign key linked toFT1. These fields have been populated with data. Lets say that in onerow of data I have in T1 under FT1 "my cell" as the data entry,similarly with T2 under FT2 I have 2 rows of data that also have "mycell" as the data entry. What is the best line of action is I wantedto change "my cell" to "my data"?

View Replies !
Link Table Versus XML Column For One-to-many Relationship
I am designing a database schema where several tables have one-to-many relationships to records in other tables. One way to implement it is to create a link table for each pair of tables that have a relationship:





identity
Table1_ID
Table2_ID

1
12
9

2
12
15

3
18
42With the SQL 2005 support for the XML data type, there is the possibility of storing the IDs in an XML column. The XML stored with a record (equivalent to record 12 from the above example) might look like this:

<Links>
  <Table2_LinkType>
    <ID>9</ID>

   <ID>15</ID>
  </Table2_LinkType>
  <Table8_LinkType>

  . . .

 </Table8_LinkType>
</Links>The XML column method has the advantage of not requiring that a separate table be created but does not enforce referential integrity. The link table method has the advantage of allowing constraints to enforce referential integrity but has the disadvantage of requiring the creation of a separate table for each pair of tables having a relationship and joining to an additional table has performance implications. Implementing standard Add, List and Delete operations for the link table method is straightforward. As a test and to familiarize myself with the new XML features, I created Set, List and Delete stored procedures for the XML method. Both methods will work.



In deciding which method to go with are there any other issues I should be considering besides database integrity, complexity and possible performance issues?
From the standpoint of best practices and coding standards is one method preferred over the other?
Here is some additional information. The data set I will be working with has table sizes numbering in the hundreds of thousands. Any given record will only be linked to at most a half-dozen records in any other table.

I searched on-line for information and I was able to find plenty of good articles discussing how to use the new XML data type in SQL. However, I was not able to find any information on when not to use the XML data type over equivalent joined-table methods.

View Replies !
Table Relationship Question For Unique Record
Hello Hello,
This Noob has a question.
I have been atempting for days to figure this out.
I have this set up: (See Below)

The Problem I am having is occuring at the Table named OU in Maroon below.
It combines 2 chains of keys into one table to try and make a unique record.
The problem is that it is not.

Pasted below is a Query run on the data within the tables:
As you can see certain data is getting duplicated in this tabel.
I want 1 Unique record in the OU table based upon the Study ID Primary Key and the zCombined Primary Key.

Any Ideas as to what is wrong, or how to make it work would defineatly be appreciated.

Thanks a Bunch


Table: Sponsor
PK: Sponsor ID

Table: Protocol
PK: ProtocolID
FK: Sponsor ID

Table: Study
PK: StudyID
FK: ProtocolID
Table: OUPK: OUIDFK: StudyIDFK: zCombinedID

Table:zCombined
PK: zCombinedID
FK: TempID ~ To Temp Table
FK: ShipTypeID ~ To Ship Type Table
FK: CoordinatorID ~ To Coordinator Table
FK: BoxTypeID ~ To Box Type Table







Sponsor

Protocol

Study

OU~Column1

OU~Column2

Box

Coordinator

Ship Type

Temp


Omni

AAAAA

XPG

S0101

NA

Wheaton

Raul Vargas

Daily       

-70


Omni

AAAAA

XPG

S0101

NA

Matrix

Raul Vargas

Daily       

-70


Omni

AAAAA

XPG

S0101

NA

B-1  

Raul Vargas

Daily       

-70


Omni

AAAAA

XPG

S0101

NA

9 x 9 4mL

Raul Vargas

Daily       

-70


Omni

AAAAA

XPG

S0101

NA

9 x 9 2mL

Raul Vargas

Daily       

-70


Omni

AAAAA

XPG

S0101

S0201

Wheaton

Mike Keane

DNA

-40


Omni

AAAAA

XPG

S0101

S0201

Matrix

Mike Keane

DNA

-40


Omni

AAAAA

XPG

S0101

S0201

B-1  

Mike Keane

DNA

-40


Omni

AAAAA

XPG

S0101

S0201

9 x 9 4mL

Mike Keane

DNA

-40


Omni

AAAAA

XPG

S0101

S0201

9 x 9 2mL

Mike Keane

DNA

-40

View Replies !
Any Built-in Function To Show Table Relationship?
Hi guys

I have a table which I need to analyze, what jobs this is working with, what stored procedure is calling this table etc. Is there any built-in function to show me or anybody know how to do it? This is my new job, and there are hundreds of stored procedures and jobs, do i really have to go thru one by one?

Please help.

Michelle

View Replies !
Insert Statement For Junction Table On Many To Many Relationship Ms Sql Server 2005
Hello,
 
This seems like such a simple problem but I am new developer even through I have been on the administration end of things for some time.  I will go into more detail about my tables and there relationships below.  Anyway, I am trying to create a many-to-many relationship within ms sql server 2005.  I have created both of my primary tables and also a junction table per the directions on microsoft's website all per ms's instructions as stated here...
 
http://msdn2.microsoft.com/en-us/library/ms178043.aspx
 
At then end of these instruction it states as a NOTE:   The creation of a junction table in a database diagram does not insert data from the related tables into the junction table. For information about inserting data into a table, see How to: Create Insert Results Queries (Visual Database Tools).
 
http://msdn2.microsoft.com/en-us/library/ms189098.aspx
 
and these directions do not go into detail on how to do an insert on a junction table. And I cant find out how to do this anywhere on the internet...  I did create a T-SQL INSERT statement in a trigger as listed below but I end up getting an error AS LISTED BELOW....
 
Here is how I set everything up...
 
PetitionSet table consists of: 
 
PetitionSetID int auto-increment primary key
PetitionSetName varchar(50) no nulls
PetitionSetScope varchar(50) no nulls

 
the Petition table consists of:
 
PetitionID int auto-increment primary key
PetitionSetID int no nulls
PetitionName varchar(50) no nulls
 
 
the SetToPetitionJunction table consists of:
PetitionSetID int
PetitionID int

And, there is a composite key made up of both the PetitionSetID and PetitionID fields.
 
I have created the foreign key relationships with DEFAULT VALUES from the SetToPetitionJunction table to each column's respective corresponding column in each of the tables: PetitionSet and Petition.
 
 
The trigger is on the Petition table and it has the following code:
 
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
-- =============================================
-- Author: Name
-- Create date:
-- Description:
-- =============================================
ALTER TRIGGER .[SetToPetitionJunctionTrigger]
ON .[dbo].[Petition]
AFTER INSERT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
 
INSERT INTO SetToPetitionJunction
(PetitionID, PetitionSetID)
SELECT Petition.PetitionID, PetitionSet.PetitionSetID
FROM Petition INNER JOIN
PetitionSet ON Petition.PetitionSetID = PetitionSet.PetitionSetID

END
 
I have created an asp.net 2.0 front end to insert values into the PetitionSet table and the Petition Table. And in the detailsview for the Petition table I manually insert the PetitionSetID field to the number that corresponds to an auto-generated number on the primary key of the PetitionSet table. So I am maintaining referential integrity...
 
The first time it works and inserts one record in the Junction table containing the PetitionSetID from the PetitionSet table and the PetitionID from the petition table.
 
Then when I try to add in another petition for the same petition set number just like I did the first time and then I get this error...

Violation of PRIMARY KEY constraint 'PK_SetToPetitionJunction'. Cannot insert duplicate key in object 'dbo.SetToPetitionJunction'.
The statement has been terminated.
 
 
 
David
 
All Rights Reserved in All Media
 
 
 

 
 
 
 

View Replies !
How To Write A Select Query To Return Records In A Many-to-Many Relationship - Junction Table???
Can Somebody please show me how to acheive this, using the order details in Northwinddatabase or any other good example. as much details as possible. Many Thanks!  

View Replies !
Failing To Create Relationship (SQL Server Claims Table Lacks PK For Some Reason ?)
I tried to create a relationship in EM's diagram pane inSQL Server 2000 (I'd list the version of EM, but About gives methe MMC version, which is probably not relevant.)(The database itself is SQL Server 2000 SP3.)I got an error that I don't understand (because, at leastat first blush, it appears to be quite untrue). Note thatI have never clicked before on the diagrams child of thedatabase; this was entirely experimental."Primary key or UNIQUE constraint must be defined fortable 'xxx' before it can participate in a relationship."http://msdn.microsoft.com/library/d...cantbepktbl.asp1) My table already had a primary key; why is MS SQL Server apparentlyclaiming otherwise ? (I don't think I can define a second primary keyon the same table. I could perhaps define an additional unique indexon top of the primary key, but, I'm not sure.)2) What does it mean: table '<0s>' ? That is, what does 0s mean ?

View Replies !
Import Csv Data To Dbo.Tables Via CREATE TABLE &&amp; BUKL INSERT:How To Designate The Primary-Foreign Keys &&amp; Set Up Relationship?
Hi all,
 
I use the following 3 sets of sql code in SQL Server Management Studio Express (SSMSE) to import the csv data/files to 3 dbo.Tables via CREATE TABLE & BUKL INSERT operations:
 
-- ImportCSVprojects.sql --

USE ChemDatabase

GO

CREATE TABLE Projects

(

ProjectID int,

ProjectName nvarchar(25),

LabName nvarchar(25)

);

BULK INSERT dbo.Projects

FROM 'c:myfileProjects.csv'

WITH

(

FIELDTERMINATOR = ',',

ROWTERMINATOR = ''

)

GO
=======================================
-- ImportCSVsamples.sql --

USE ChemDatabase

GO

CREATE TABLE Samples

(

SampleID int,

SampleName nvarchar(25),

Matrix nvarchar(25),

SampleType nvarchar(25),

ChemGroup nvarchar(25),

ProjectID int

);

BULK INSERT dbo.Samples

FROM 'c:myfileSamples.csv'

WITH

(

FIELDTERMINATOR = ',',

ROWTERMINATOR = ''

)

GO
=========================================
-- ImportCSVtestResult.sql --

USE ChemDatabase

GO

CREATE TABLE TestResults

(

AnalyteID int,

AnalyteName nvarchar(25),

Result decimal(9,3),

UnitForConc nvarchar(25),

SampleID int

);

BULK INSERT dbo.TestResults

FROM 'c:myfileLabTests.csv'

WITH

(

FIELDTERMINATOR = ',',

ROWTERMINATOR = ''

)

GO

========================================
The 3 csv files were successfully imported into the ChemDatabase of my SSMSE. 
 
2 questions to ask:
(1)  How can I designate the Primary and Foreign Keys to these 3 dbo Tables?
      Should I do this "designate" thing after the 3 dbo Tables are done or during the "Importing" period?
(2) How can I set up the relationships among these 3 dbo Tables?
 
Please help and advise.
 
Thanks in advance,
Scott Chang
 
  

View Replies !
How To Set A Relationship Here?
How to create a relation between gf_game and gf_gamegenre here? gf_gamegenre is responsible for the relation between a game and it's genre(s). The relationship between gf_genre and gf_gamegenre worked. (http://img361.imageshack.us/my.php?image=relationzl9.jpg)

 When I try to set a relationshop between gamegenre and game I'm getting this error:
'gf_game' table saved successfully'gf_gamegenre' table- Unable to create relationship 'FK_gf_gamegenre_gf_game'.  The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_gf_gamegenre_gf_game". The conflict occurred in database "gamefactor", table "dbo.gf_game", column 'gameID'.
Thanks for any help!

View Replies !
Need Help With Relationship
I have this situation in my DB:
tblClients, ClientID(pk) 1---M tblDocuments, DocumentID(pk), ClientID(fk), DocumentTypeID M---1 tblDocumentTypes, DocumentTypeID(pk)(this is a lookup table)
If a client is deleted I want to cascade and delete that clients documents from tblDocuments. When I set the relationships delete and update to cascade on tblDocuments it is also set to cascade on the lookup table (tblDocumnetTypes).
Why is this and how do I make it stay the way I want it?
 

View Replies !
Many To One Relationship
Hello
 I have need to write a query that I can pass in a bunch of filter criteria, and return 1 result....it's just ALL of the criteria must be matched and a row returned:
 example:
 Transaction table: id, reference
attribute table: attributeid, attribute
 transactionAttribute: attributeid, transactionid
 Example dat
 Attribute table contains: 1 Red, 2 Blue, 3 Green
Transaction table contains: 1 one, 2 two, 3 three
transactionAttribute contains: (1,1), (1,2), (1,3), (2,3), (3,1)
 
If I pass in Red, Blue, Green - I need to be returned "one" only
If I pass in Red - I need to be returned "three" only
If I pass in Red, Green - nothing should be returned as it doesn't EXACTLY match the filter criteria
 
If anyone's able to help that would be wonderful!
Thanks, Paul

View Replies !
How Can I Set A One-to-one Relationship
How can I set a one-to-one relationship using the Management Studio Express and SQL Server 2005 Express
tblClient, CleintID (PK)
tblProcess, ClientID (FK)

View Replies !
One To One Relationship
I created 2 tables with one to one relationship. if I add a record intable A, how does table B record get created? Does SQL do thisautomatically because it is one to one relationship? or do I need tocreate a trigger? if i need a trigger, how do I get the ID of newrecord to create the same ID in table B?thanks for any help.Joe Klein

View Replies !
One-One Relationship
Hi,Do you guys know what's wrong with a one-to-one relationship?The reason I want to make it like this is that at the very end of the chain,the set of keys is huge. I want to limit the number of columns to be thekey. i.e. the [company] table has 1 column as the key. The [employee]table will have 2 columns as the key.e,g,If I add a [sale] table to the [company]-[employee] relationship, the thirdtablewill have 3 columns as the key -- "company id", "employee id", and "saleid".(e.g.)I have a company with many employees and computers. But instead of classifyall these, I just want to call all these as an entity. A company is anentity. An employee is just another entity. etc.So, instead of a one-to-many:[company]---*[employee]---*[sale]||*[computer]I make it one-to-one.[entity]---*[entity]If I want to know the name and address of the entity "employee", I will havea 1-to-1 table [employee] to look up the information for this employeeentity.[entity]---*[entity]||[company]||[employee]||[computer]||[sale]--[color=blue]> There is no answer.> There has not been an answer.> There will not be an answer.> That IS the answer!> And I am screwed.> Deadline was due yesterday.>> There is no point to life.> THAT IS THE POINT.> And we are screwed.> We will run out of oil soon.[/color]

View Replies !
ER Relationship
For a weak relationship, will 0 and 1 in the ER diagram represent partialand total participations of the 2 entities sets respectively or vice versa.

View Replies !
Many To Many Relationship
hi all,
how to implement the many to many relation ship....
i get stucked it.......
plz help
thanx
sajjad

View Replies !
Why Using One-to-One Relationship
Hey,
I know I'm asking a stupid question but I need to get a clear response please:
why using One-to-One relationship instead of meging the 2 tables in only one?
thanks.

View Replies !
ISA Relationship
Hi,
do you use ISA relationship or do you avoid it? Why?
Could you write me some its benefitsand drowback?
Thanks

View Replies !
One To One Relationship
Can anyone provided insight on how to create a one-to-one relationship between
SQL tables? Every time I try to link two tables that should be one-to-one, the link says one-to-many.
How can I specify one-to-one when SQL Server automatically thinks it is a one-to-many?
Thanks,
Kellie

View Replies !
Fk Relationship
 Hi.
I get this error when i try to create a relationship in a db diagram (sql 2005)
"'tblActivedir' table saved successfully
'tblClient' table
- Unable to create relationship 'FK_tblClient_tblActivedir1'.
Introducing FOREIGN KEY constraint 'FK_tblClient_tblActivedir1' on table 'tblClient' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Could not create constraint. See previous errors."


What i have is 2 tables.
1 named client
1 named activedir

In the client table the columns i want to bind with activedirtable are FR1 and DC1
I want to bind them in the ID of the activedir table (both, in different fk relationships) so that they get the id of activedir.
Fr1 has an fk relationship with activedir (pk is activedir' id)
and DC1 exactly the same in another fk.
So i want both columns to comunicate with activedir.
If p.e. activedir has 3 elements (a,b,c) when i delete element a then werever FR1 or DC1 have this element(binded to it's id) then the element will also be deleted (id of the element) from both FR1 and DC1
I don't want to set Delete and Update action to none because i want the element changed or deleted from activedir, to do the same on Fr1 or DC1 or both.
Any help?
Thanks.

View Replies !
ERD 1:1 Relationship
I am trying to create a 1:1 relationship, but not primary key to primary key. In table 1 I have a uniqueidentifier as a primary key. In table 2 I have an int as the primary key and a column that takes the uniqueidentifier from table 1. Everytime I drag and drop the relationship line and link table 1 to table 2 it creates a 1:N relationship: ie. tbl1.primarykey links to tbl2.column2. So I'm not linking primary key to primary key however I still want a 1:1 relationship.

 

How do I do that?

Thanks in advance.

View Replies !
One-To-Many Relationship
SQLServer 2005 - I have two tables.  One has a field defined as a Primary Unique Key.  The other table has the same field, but the Index is defined as non-Unique, non-clustered.  There is no primary key defined on the second table.  I want to set up a one-to-many relationship between the two, but am not allowed.
 
This should be simple.  What am I doing incorrectly?

View Replies !
Relationship Between A AND ( B OR C )
I have a fact table with 2 fields : "Dim Code 1" and "Dim Code 2" that I want to link with a Dim table.
I don't want to create two dimensions Dim1 and Dim2 but only one dimension with something like :





Code Snippet


      Dim.Code=Fact.DimCode1 OR Dim.Code=Fact.DimCode2



Is it possible to do this ?


Thanks in advance

View Replies !
ERD Relationship
hi, I've draw the ERD for my database in management studio express but I have a question regarding the relationship between tables. How can I define the cardinality of the relationship between two tables? by default in managemet studio is it the relationship is only one-to-many relationship?

View Replies !
Relationship
Hi.
(Sorry if i am not posting this in the right forum)

well i am learning to create a small software and have come up with four tables which are as follows;


Client
date
<!--[if !vml]--><!--[endif]-->client_id
name
address
contact_num
 
Smoking
smoking_id
client_id
meas_arm
meas_neck
meas_shoulder
Color_code
description
Trousers
trousers_id
client_id
meas_leg
meas_hips
meas_waist
color_code
description
 
Shirt
shirt_id
client_id
meas_arm
meas_neck
meas_shoulder
color_code
description
My question
Is it possible to have a relationship linking one single table to other several one.
For example i wanted to relate the field client_id from table client which is the primary to tables shirt,trousers and smoking with the client_id field which is the foreign key ?

thanks 

View Replies !
Key Relationship
This is the message that i get when trying to assign keys when creating diagrams in visual express:

 

'tbh_Polls' table saved successfully
'tbh_PollOptions' table
- Unable to create relationship 'FK_tbh_PollOptions_tbh_Polls'. 
The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_tbh_PollOptions_tbh_Polls". The conflict occurred in database "C:USERSSTICKERDOCUMENTSMY WEB SITESPERCSHARPAPP_DATAASPNETDB.MDF", table "dbo.tbh_Polls", column 'PollID'.

 

PollID is my primary key in tbh_Polls

And PollID is in tbh_PollOptions table

 

No matter what I do, I get this message, I'm Lost!

Help plz.

Thanks

 

View Replies !
One To One Relationship
How do I create a one to one relationship in a SQL2005 Express database? The foreign key needs to be the same as the primary key so it can't just increment to the next number.

View Replies !
Get Relationship Via SQL
Hey,

is it possible to get the relationship of a table via sql? Like I need to know which relations the table t has. Is that possible?

Thanks

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved