Representing M:N relationship in database

Hi,
I have created three tables basically. They are as follows:
Table 1:
CREATE TABLE BOOKS
     ( ID CHAR(4) NOT NULL,
     TITLE VARCHAR(100),
     PRICE DECIMAL(5,3),
     ONSALE CHAR(2),
     YEAR CHAR(4),
DESCRIPTION VARCHAR(100),
INVENTORY CHAR(2),
PRIMARY KEY(ID));
Table 2:
CREATE TABLE AUTHORS
     ( AUTHID CHAR(4) NOT NULL,
FIRSTNAME VARCHAR(20),
SURNAME VARCHAR(20),
ORGANIZATION VARCHAR(19),
PRIMARY KEY(AUTHID));
// Since the above relationship is M:N we need to create a New table and I've done that below:
Table 3:
CREATE TABLE HAS_AUTHORS
     (BOOKID CHAR(4) NOT NULL,
AUTHORID CHAR(4) NOT NULL,
PRIMARY KEY(BOOKID,AUTHORID),
FOREIGN KEY(BOOKID) REFERENCES BOOKS(ID) on delete cascade,
FOREIGN KEY(AUTHORID) REFERENCES AUTHORS(AUTHID) on delete cascade);
Now My Question is:
Do I have to populate the HAS_AUTHORS table manually too or will the values I put into Table1 and Table 2 for ID and AUTHID be propagated to BOOKID and AUTHORID? It's probably a silly question but am a beginner.
Thanks.
Message was edited by:
user503246

I think table 3(relationship) is not need.
table 3 is just relation table.
BOOKS
# ID
# AUTOID <--- I define this new relation key
TITLE
PRICE
ONSALE
YEAR
DESCRIPTION
INVENTORY
| M
|
|
|
| 1
AUTHOR
# AUTOID
FIRSTNAME
SURNAME
ORGANIZATION
CREATE TABLE BOOKS
( ID CHAR(4) NOT NULL,
AUTOID CHAR(4) NOT NULL,
TITLE VARCHAR(100),
PRICE DECIMAL(5,3),
ONSALE CHAR(2),
YEAR CHAR(4),
DESCRIPTION VARCHAR(100),
INVENTORY CHAR(2),
PRIMARY KEY(ID)
FOREIGN KEY(AUTHORID) REFERENCES AUTHORS(AUTHID));
you have to add new foreign key in books table.
Message was edited by:
dokeun Kim

Similar Messages

  • How to represent foreign key relationship between entity services

    Hi All,
    I have two entity services sbu and lob with remote persistensy(web service).In the sql database also i have these two tables.
    lob table attributes: lobId and lobName.
    sbu table attributes:sbuId,sbuName,and lobId.Here lobId a is foreign key referring to primary key of lob table.
    I want to represent this in the entity services.
    Can you plz tell me how can i do this?.
    Thanks
    Sampath.G

    Hi Sampath,
    to avoid creating a lob entity set the lobId and the timestamp attributes. because this is not smoothly done in the service browser, continue writing your UI.
    in old caf implementation this blog serie gives you a short overview...
    /people/raphael.vogel/blog/2006/05/18/writing-a-betting-pool-application-for-the-soccer-world-cup-2006-part-i
    /people/raphael.vogel/blog/2006/05/18/writing-a-betting-pool-application-for-the-soccer-world-cup-2006-part-ii
    /people/raphael.vogel/blog/2006/05/19/writing-a-betting-pool-application-for-the-soccer-world-cup-2006-part-iii
    /people/raphael.vogel/blog/2006/05/21/writing-a-betting-pool-application-for-the-soccer-world-cup-2006-part-iv
    Regards, Jens

  • How to find relationship between database tables

    Hi Mate,s.
    Iam new to SAPBW , PLZ tell me , How to find releationship between database table(Transperent tables).
    Regards.
    harry

    hi harry,
    from your previous postings, i guess you are asking relationship between tables in r/3, following links may help :
    http://www.sapgenie.com/abap/tables.htm
    http://www.sapgenie.com/abap/tables_sd.htm
    http://www.sapgenie.com/abap/tables_mm.htm
    http://www.sapgenie.com/abap/tables_fi.htm
    http://www.sapgenie.com/abap/tables_ps.htm

  • Crmm_erm_cat and relationship between database questions and activities

    Hello Guys,
    Using this transaction, it´s possible to make the relationship between the questions from the solution database with activities, and it´s possible to locate some activities over there. These activities are not apearing. Is there something else in the transaction, or additional transaction, I have to execute, to make the crmm_erm_cat work fine?
    cheers
    Luiz David

    Already solved, thanks

  • Direct IO,Asynchronous IO and relationship with database performance

    What is concept of Direct IO, Asynchronous IO from the DBA prospective? How does it relates to the database performance?
    Any simple explanation will be highly appreciated. Thanks in advance.

    918868 wrote:
    What is concept of Direct IO, Asynchronous IO from the DBA prospective? How does it relates to the database performance?
    Any simple explanation will be highly appreciated. Thanks in advance.yet another interview question from you?

  • EJB representing optional relationship

    Hi,
    I was wondering how does EJB 2.0 deployment descriptor handles the 1 to 1/0 relationship between 2 entites. For example, 1 course can have 0 or 1 textbook. In this case, textbook is optional and might be represented as null in the database.
    The following represents 1-to-many relationship, how can I define 1-to-1/0 relationship? Please help. Thanks.
    <relationships>
       <ejb-relation>
          <ejb-relation-name>Textbook-Course</ejb-relation-name>
          <ejb-relationship-role>
             <ejb-relationship-role-name>Textbook-has-Course</ejb-relationship-role-name>
             <multiplicity>many</multiplicity>
             <relationship-role-source>
                <ejb-name>TextbookBean</ejb-name>
             </relationship-role-source>
             <cmr-field>
                <cmr-field-name>course</cmr-field-name>
             </cmr-field>
          </ejb-relationship-role>
          <ejb-relationship-role>
             <ejb-relationship-role-name>Course-has-Textbook</ejb-relationship-role-name>
             <multiplicity>one</multiplicity>
             <relationship-role-source>
                <ejb-name>CourseBean</ejb-name>
             </relationship-role-source>
             <cmr-field>
                <cmr-field-name>textbooks</cmr-field-name>
                <cmr-field-type>java.util.Collection</cmr-field-type>
             </cmr-field>
          </ejb-relationship-role>
       </ejb-relation>
    </relationships>

    hi,
    I think you can use 1-1 relation for your case. It will also take care of 1-0.
    You just need to update the Textbook-Course multiplicity tag.
    Set multiplicityto one
    If there is no textbook in a course the Collection will be empty. if you strictly want to model 1 -1/0 , then no need to using Collection in following tag. Just use the type of TextBookbean's remote interface.
    <cmr-field>
        <cmr-field-name>textbooks</cmr-field-name>           
        <cmr-field-type>java.util.Collection</cmr-field-type>        
    </cmr-field>I am using the same technique in our application . We take help of model 1-1 for 1-0 type of relation.
    regards,
    Amit

  • Create repository from database model- snowflake facts and dimension joins

    I am working on a project that has a database model similar to the image in the link below.
    There are other few tables around it, but this generally represent the spine or major database model. This is not exactly a snowflake schema as there are no intrinsic hierarchy in the dimension tables. As you can see dim2 and dim4 has one to many relationship with dim3. there are joins between the fact tables as well.
    From some blogs and forum threads, I found out that I can create one fact/dimension table by joining many fact/dimension tables. Is this a right approach? Any thoughts on this model please?
    Thanks,
    Rakesh
    ps: I am using Windows XP Pro and OBIEE 10.1.4.3.1 and right now analyzing the data to create a repository.

    Hi Rakesh,
    As above post says you combine all fact tables into single fact table with other dimension tables so it would become a simple start schema .Go throught these blogs for further information .
    http://forums.oracle.com/forums/thread.jspa?threadID=2124061&tstart=0
    http://www.obinotes.com/2010/08/joins-within-logical-table-sources-in.html#comment-form
    Hope it helps you.Seems your new to forum you sud follow these rules http://forums.oracle.com/forums/ann.jspa?annID=939
    By,
    KK

  • New User Question : Many to Many relationship Association

    Hi
    I am trying to code a many to many relationship between two entities. One of my entity is named View and the other is Column.
    I am trying to use the @JoinTable annotation and for the table property in the annotation I am specifying a table column_view (which I have created in the database).
    My associative table has other fields, apart from the primary key of view and column entities. This makes me feel that my current way of using @JoinTable would not work under this condition and I have to create two onetomany mappings like
    Column -> OnetoMany -> ColumnView <- OnetoMany <- View.
    Am I right in my approach or is there anyother way out to represent such manytomany relationships.

    Why other fields are required in your relationshipt table?
    have only two columns and perform @ManyToMany.
    @JoinTable has to be used only on owning side.
    user (mappedBy ) on the other side
    thanks

  • Is there a way to find the email address of the user's from SCCM database.

    Hi All,
    I am using SCCM 2012 R2 and trying to find a query/report that can help in finding the email address of the user the machine is assigned to (Primary device). And if that is a machine which is being shared between different user, I need to gather the same
    information or the user who last logged on that machine.
    Can you please help?
    Thanks
    Manish

    My opinion: I think you'll need to define what, to you, means "primary user".  a primary user relationship can be defined manually by you one by one in the console, automatically by usage, imported via script, or the end user (if they know
    how and you've allowed this in settings) can indicate a machine is a primary machine for themselves.
    How is primary user relationship set, in your environment?  Depending upon how that relationship is determined in your environment, then you can track for that particular machine how or why the relationship you expect to be there, isn't the relationship
    the database acknowledges.
    Standardize. Simplify. Automate.

  • Any ideas on how to incorporate a simple database into my website?

    Firstly I am to create a website that will survey the user on what their ideal laptop would be (each answer would relate to a certain brand or model of laptop); once the user has filled out the survey I went to be able to tally up their results to work out which record in the pre-existing database would be best suited...
    This would be a simplified example,
    Which brand would you prefer:
    Apple  ( )        HP      ( )         Sony    ( )
    Price range:
    100   ( )       200    ( )     300     ( )
    I have attempted to just 'search the database' since each answer has is representing a record in the database; however this does not take into account various answers across the survey (Will only search and display for the price, while ignoring what brand, etc.)
    The database is on phpmyadmin, whether that makes any difference.
    Perhaps there is a simple line of code that will handle all this, but I'm relatively new to the whole thing so any help would be greatly appreciated.

    Having a bit of trouble getting it to work, would you mind looking over my code to see where I've messed up?
    <?php require_once('../Connections/survey.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
      if (PHP_VERSION < 6) {
        $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;   
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      return $theValue;
    $colname_Brand = "-1";
    if (isset($_GET['Brand'])) {
      $colname_Brand = $_GET['Brand'];
    mysql_select_db($database_survey, $survey);
    $query_Brand = sprintf("SELECT * FROM ideal WHERE Brand = %s", GetSQLValueString($colname_Brand, "text"));
    $Brand = mysql_query($query_Brand, $survey) or die(mysql_error());
    $row_Brand = mysql_fetch_assoc($Brand);
    $totalRows_Brand = mysql_num_rows($Brand);
    $colname_Price = "-1";
    if (isset($_GET['Price'])) {
      $colname_Price = $_GET['Price'];
    mysql_select_db($database_survey, $survey);
    $query_Price = sprintf("SELECT * FROM ideal WHERE Price = %s", GetSQLValueString($colname_Price, "text"));
    $Price = mysql_query($query_Price, $survey) or die(mysql_error());
    $row_Price = mysql_fetch_assoc($Price);
    $totalRows_Price = mysql_num_rows($Price);
    $colname_Rating= "-1";
    if (isset($_GET['Rating'])) {
      $colname_Rating = $_GET['Rating'];
    mysql_select_db($database_survey, $survey);
    $query_Rating = sprintf("SELECT * FROM ideal WHERE Rating = %s", GetSQLValueString($colname_Rating, "text"));
    $Rating = mysql_query($query_Rating, $survey) or die(mysql_error());
    $row_Rating = mysql_fetch_assoc($Rating);
    $totalRows_Rating = mysql_num_rows($Rating);
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Search Results</title>
    </head>
    <body>
    <h1> Survey results</h1>
    <?php
        $temp = $totalRows_Results;
        if ($temp == 0) { echo "No Records Found"; }
    ?>
    <table width="200" border="1">
      <tr>
        <td>id</td>
        <td>Brand</td>
        <td>Name</td>
        <td>Price</td>
        <td>Rating</td>
        <td>Purpose</td>
      </tr>
      <?php do { ?>
      <tr>
        <td><?php echo $row_Results['id']; ?></td>
        <td><?php echo $row_Results['Brand']; ?></td>
        <td><?php echo $row_Results['Name']; ?></td>
        <td><?php echo $row_Results['Price']; ?></td>
        <td><?php echo $row_Results['Rating']; ?></td>
        <td><?php echo $row_Results['Purpose']; ?></td>
      </tr>
      <?php } while ($row_Results = mysql_fetch_assoc($totalRowResults)); ?>
    </table>
    <br />
    <a href="survey.html">Back to survey</a>
    </body>
    </html>
    <?php
    mysql_free_result($Results);
    ?>

  • Database logical structure

    Anyone know online documentation that explains database logical structure ?
    The relationships between database, tablespace, datafile, segment, extent, and blocks ... storage structure.
    In an easy to understand document :)
    I am learning Oracle 9i, any helps are really appreciated.
    Thanks in advance.

    I'd start with [url http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96524/toc.htm]     Oracle9i Database Concepts

  • How to create a new database and use it?

    Hi there,
    I have so many tables in the current database that i'm working on. When i start to create a new table such as employee, student, person...etc it doesnt allow me to create them becuase it says the tables exists. Even when i use the drop command to drop the tables, doesn't help. So most of the time i have to create a table with postfix of 1, 2 to the table name.
    Therefore i need to create a database for every project that i do.
    How do i create a new database?
    Then how do i use the database that i just created?
    Then how do i find the out whats the database that i'm currently working on?
    Thanks!
    Message was edited by:
    dingdong
    Message was edited by:
    dingdong

    A database is a physical set of files that contains many schemas. Each schema has a one to one relationship with database users, so to create a new schema you create a new database user.
    e.g.
    CREATE USER fred IDENTIFIED BY fredspassword;Then, by logging on as fred you can create all the new tables you like as that user, in that users schema.
    If you create a new database then you will find you cannot access functions/procedures, packages, tables etc. that exist in another users schema without creating a database link to the other database that contains them.
    If you just create a new schema, you can more easily get at other users schema objects (tables, packages etc.) by referencing them with the users name e.g. JOE.TABLE1 providing that user has given permission for your user to access them. You can also create synonyms that allow you to reference other users schema objects as if they exist in your own e.g. you can have something called TABLE1 in your own schema that is in fact referencing JOE.TABLE1.
    Message was edited by:
    BluShadow
    remove quotes from password. oops! thanks padders

  • Re: Japanese Database

    Hello Billy,
    When we added support for double byte characters to
    Ambassador, we had similar concerns. We installed
    Forte and Ambassador onto a PC running the Japanese
    version of MS Windows and tested Kanji support storing
    Kanji text in the same MS Access database we use for
    storing western language text. This worked fine.
    I expect it will also work fine with Sybase.
    If you have Forte and the Japanese version of
    MS Windows, I suggest you download the demo version
    of the Ambassador Translation Wizard, and you can
    see this in action.
    You can find the demo version at:
    http://www.lindhard.com/forte/ambassador.html
    Good luck!
    Kerry
    We have been contacted by a company that would
    like us to develop a database that contains
    information from Japan. We are in the very early
    stages of conversation, however, I think want us
    to store names and addresses etc in their native
    language. We would convert and store all survey
    answers etc. into English and store them that way.
    I was curious if any out there has any experience
    in using the Kanji character set in Forte' and or
    Sybase. We are just in the feasibility phase now
    and any help would be appreciated.
    Thanks,
    Billy Haynes
    Chief Information Officer
    [email protected]
    Addressing Your Needs, Inc.
    The Sales and Marketing Database Specialists
    Visit us on the web @ www.ayn.com
    - Sales Lead Management
    - Relationship Marketing
    - Database Design & Development
    - Fulfillment
    - Telemarketing
    - Response Focused Marketing
    - Direct Marketing Creative
    - Automated Fax and Voice Systems
    2324 Ridgepoint Drive, Suite A
    Austin, TX 78754
    512/349-3100 (voice)
    800-525-6170 (toll free)
    512/349-3101 (fax)--
    | | / \ Kerry Bellerose [email protected]
    | || C | Senior Consultant direct: 45 45 94 01 03
    | | \___/ Lindhard Forte&acute; Solutions desk: 45 45 82 21 21
    | |_____ Datavej 52 fax: 45 45 82 21 22
    | | 3460 Birkeroed, Denmark
    |_________| http://www.lindhard.com/forte

    Answer, as best I can discover, is that FileMaker are aware of this issue, and have released v4 of FileMaker 11 to fix it for Lion. And told everyone using version 10 (which I believe I only bought last year) that they can go jump.
    Lovely bunch, FileMaker. I'd definitely urinate on them if they were on fire.

  • How to create database from scratch using user input

    what I am trying to do is to create database via my java code (using hibernate and my sql) and based on user input.
    The details like the name of table.... or the number of columns in it are all supposed to be determined from user input (only the first time).
    On subsequent run the program should remember the previously created database and hence work with it.
    Can somebody help me through this?
    Suppose I did create it using firing queries from my program then the next problem is how my program would start up next time......?????

    Anuvrat wrote:
    what I am trying to do is to create database via my java code (using hibernate and my sql) and based on user input.
    The details like the name of table.... or the number of columns in it are all supposed to be determined from user input (only the first time).
    On subsequent run the program should remember the previously created database and hence work with it.
    Can somebody help me through this?Presumably because you want to (fun) rather than because you need to (job or project.)
    If the second then don't do it.
    >
    Suppose I did create it using firing queries from my program then the next problem is how my program would start up next time......?????You would start by learning about DDL which is the common name for the languages, which vary by database, used to create the entities that represent the structure of a database. Until you figure out the syntax of that you can't do anything in java.

  • Populating Database values into a combo box in STRUTS Framework

    Hi Guys,
    I am currently working on a STRUTS Framework project and I can't get much resources related to the problems that I'm facing.
    Currently I need to populate a JSP file's Combo box with database values. What I don't know here is the syntax used to in STRUTS framework to populate the Combo box with database values. Anyone with experience related to this topic, please kindly help me out.

    Struts doesn't define anything about the datab layer. You're free to implement how you will.
    Struts instead guides you into following an MVC pattern.
    You populate a combo box with values from a bean.
    So you need to set up a bean for this page to talk to.
    That bean can be populated from the database - but at that point you're in java/jdbc code - and away from the struts layer.
    My suggestions
    1 - Define a bean to represent the information from the database.
    2 - write a method that queries the database, and copies the data into a List of those beans. This will be your Data access layer.
    3 - in your action, call that method, and then set the list of beans as a request attribute. Or maybe as a property on a form.
    4 - use that list of beans to populate your dropdown box.

Maybe you are looking for

  • Itunes Load Times

    Hey all. I would just like a bit of input regarding the Itunes load times? How long on average does it seem to take from when you first click on the itunes icon, until it pops up? Because it seems to take quite a bit longer than my other media player

  • Sales Order -Valuated, non valuated

    Hi, I am getting an error while saving a sales order containing Variant Configured Material. The Error description is " Sales Order is non valuated". Where do we make the config settings regarding valuation of a Sales order?i.e.valuated or non valuat

  • Custom program - unknown warning messages after upgrade (4.6c to ECC 6.0)

    Hi, At work, we are currently upgrading from 4.6c to ECC 6.0 One of the custom (z) programs that was moved is displaying warning messages, and preventing the user from viewing a report. The warnings appeared in ECC 6, but were never there in 4.6c. Th

  • Error in DBMS_METADATA

    I have used following method to copy constraints from remote tables; REMOTE: TEST LOCAL: hahmed2 SELECT DBMS_METADATA.GET_DDL ('TABLE', v_tablename) INTO v_copytablename FROM all_tables where owner='TEST'; ERROR at line 1: ORA-31603: object "ORDER_IT

  • Spry accordion problem with IE

    I tried to make a site using all different spry-widgets, so I made tabbed panels and in them accordion panels (and in other panels other spry-things). It works well in FF but in IE the accordionpanels stay all open. Can someone help me out. Many than