How can I retrieve data from one table to another automatic in SQL?

Hi, everione,
I am having a big problem, trying to create datebase.
I have 3 tables: SUPERAVATAR, MASTERAVATAR, MEGAAVATAR.
- SuperAvatars are heroes in an online role playing gaming. They have an ID, ‘superavatarID’ which contain an UNIQUE NUMBER NOT NULL PRIMARY KEY to identify them.
A wisdom – ‘trickster’,’conjuror’,’magician’, etc..
A current owner… who is the user or player of the game and has that Super Avatar– we associate the link to USERID to know the person.
SuperAvatars can be fathers or mothers of Mega Avatars.
-MegaAvatars are the children of SuperAvatars…. They also have an ID UNIQUE NUMBER NOT NULL PRIMARY KEY to indentify them.
A magic power – it can be a ‘Leader’ or ‘Sheep’…
A ‘parent’ – parent is the number identifying to know to who Super Avatar belongs.
e.g.
SUPERAVAT WISD CURRENTOWNER FATHEROF MOTHEROF
1 Thick 3 1
2 Mentally Ch. 11 3
3 Smart 9 2
4 Genius 16 4
5 Thick 19
MEGAAVATARID MAGICPOWER PARENT
1 MAGICIAN 1
2 WIZARD 3
3 SORCERER 2
4 MAGICIAN 4
-We see that MEGAAVATAR 1 has a magic power as Magician and his father is ‘1’. ‘1’ identifies the SUPERAVATAR.
We see SUPERAVATARID…. who has the number ‘1’? the first in the row… who has wisdom – thick and he belongs to the USER with ID number 3.
-We see MEGAAVATARID… we choose the number 2…. His magic power is as WIZARD… and his father is the number 3.
We see SUPERAVATARID now… we look up the SuperavatarID 3…. We can see he has a wisdom – GENIUS… who belongs to the USERID 16 and he is father of MEGAAVATAR number 2.
The list can carry on and never stop.
I have this Problems:
We create in this example 3 tables: Users, SuperAvatar, MegaAvatar
SQL
CREATE TABLE users(userID NUMBER CONSTRAINT pk_user PRIMARY KEY,email VARCHAR2(50) NOT NULL UNIQUE,password VARCHAR2(15) NOT NULL UNIQUE,subscription CHAR(8) NOT NULL CHECK (subscription IN('ACTIVE' , 'INACTIVE' ) ) );
CREATE TABLE superavatar(superavatarID NUMBER CONSTRAINT pk_superavatar PRIMARY KEY, wisdom VARCHAR2(19) NOT NULL CHECK (wisdom IN ('THICK', 'MENTALLY CHALLENGED', 'AWAKE', 'SMART', 'GENIUS')), currentOwner NUMBER NOT NULL, fatherOf NUMBER,motherOf NUMBER);
CREATE TABLE megaavatar (megaavatarID NUMBER CONSTRAINT pk_megaavatar PRIMARY KEY, magicPower VARCHAR2(12) NOT NULL CHECK (magicPower IN('TRICKSTER','CONJUROR','MAGICIAN','WIZARD','SORCERER')), parent NUMBER);
Now, the 3 tables are created…..
What happen when we try to insert values to this table?
In this case we insert to User Table some examples:
INSERT INTO users VALUES('3','[email protected]','great78','ACTIVE');
INSERT INTO users VALUES('9','[email protected]','chrisandra)','ACTIVE');
Now, we insert to SuperAvatar some examples;
INSERT INTO superavatar VALUES('1','THICK','3','1','');
INSERT INTO superavatar VALUES('3','SMART','9','3','');
|
|
‘9’ is the UserID that we already insert to the User table
What’s the problem?
We have to insert manually the data from USERID to CURRENTOWNER as we didn’t match or link CURRENTOWNER from SUPERAVATAR Table to USERID from USER Table with a SQL CODE.
What happen if we have thousands of USERS that they register to this game…? We will never know to how belongs that SUPERAVATAR but if someone do it manually can spend a year.
I am trying to fix this problem …. I add in SUPERAVATAR TABLE ‘CHECK’ in currentOwner..
SQL> CREATE TABLE superavatar
(superavatarID NUMBER CONSTRAINT pk_superavatar PRIMARY KEY, wisdom VARCHAR2(19) NOT NULL CHECK (wisdom IN ('THICK', 'MENTALLY CHALLENGED', 'AWAKE', 'SMART', 'GENIUS')),
currentOwner NUMBER NOT NULL CHECK (currentOwner IN(SELECT userID FROM users)),
fatherOf NUMBER,
motherOf NUMBER);
ERROR:
ORA-02251: subquery not allowed here
It doesn’t work.
Please HELP, I have exam tomorrow
thank you
Desy

Hallo,
you can use trigger on table USER and fill the userid in AVATAR.currentowner,
but i don't understand, how you join these tables ?
Which user id must come in which column currentowner ?
Design problem ?
Regards
Dmytro

Similar Messages

  • How can I transport data from one client to another client?

    How can I transport data from one client to another client? 
    Regards,
    Subho

    hmmm, CTS = cutomizing transport?
    If you have a customizing table, there are still two possibilities.
    1. customize in DEV system and transport
    2. customize right there where you need it.
    this depends on how the maintainance view is built. If it is a simple customizing table and you get not asked for a TR when customizing a new record or changing an existing one, you hit possibility 2.

  • How can you transfer data from one ipod to another ?

    How can you transfer data from one ipod to another ipod ?

    The geniusbar told me what to do, I understood but there is still a problem for me >:/ It's not showing up though. Like "device."  Nothing is happening, and I tried as soon as I got home. Then after half an hour, then an hour, then 3 hours. My problem is that it's not showing up! It's stuck in recovery mode! There's still like 25% battery. So I have no idea why.

  • How can I Move data from one column to another in my access table?

    I have two columns, one that stores current month’s data and one that stores last month’s data. Every month data from column 2 (this month’s data) needs to be moved to column 1 that holds last month’s data. I then null out column 2 so I can accumulates this month’s data.
    I understand how to drop a column or add a column, how do I transfer data from one column to another.
    Here is my trial code:
    <cfquery name="qQueryChangeColumnName" datasource="#dsn#">
      ALTER TABLE leaderboard
      UPDATE leaderboard SET  points2 = points3
    </cfquery>
    Unfortunately, I get the following error:
    Error Executing Database Query.
    [Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error in ALTER TABLE statement.
    How can I transfer my data with the alter table method?

    I looked up the Access SQL reference (which is probably a
    good place to start when having issues with Access SQL), and
    it suggests you probably need a WHERE clause in there.
    I agree the documentation is a good place to start. But you should not need a WHERE clause here.
    Too few parameters. Expected 1.
    If you run the SQL directly in Access, what are the results? At the very least, it should provide a more informative error message..

  • How can I transfer data from one phone to another

    I have a damaged iPhone 3 and am trying to transfer data to another iPhone 3.  How can I do that?

    take a look at the link   http:///support.apple.com/kb/HT2109

  • How Can I Send Data From One Pc To Another Using An Ethernet Connection ?

    Hi,
    I would Like to know how to send data ( For example, any String ) from a Server Pc to a Client Pc, Using the same java program installed on both computers.
    [Pc One ( Server ) [ Java Program] ] <----Ethernet--Cable----> [Pc Two( Client ) [ Java Program] ]
    Thanks .
    Edited by: jaysal2490 on Jul 7, 2008 9:45 PM
    Edited by: jaysal2490 on Jul 7, 2008 9:46 PM
    Edited by: jaysal2490 on Jul 7, 2008 9:51 PM

    Check out this tutorial:
    http://java.sun.com/docs/books/tutorial/networking/sockets/index.html
    There are code samples included.

  • How can we get data from One Form to Another Form

    Hi All,
    I have 2Forms.I'm calling one form from another form buy using next form button.
    If i press itis opening 2nd form,Simultaneously i have to get the data to the 2nd form.Can any one help me in this.
    Any triggers has to be fire tell me the solution
    Regards
    Siva

    you may have better success over here
    Forms

  • How can I move data from one loop to another?

    I am using LabVIEW to record and display data.  The problem that I have run into is that if I try to collect and display the data all in one loop data points are lost because the loop takes so long to execute.  I decided to break my program into two independent loops and the data is recorded at proper speeds, but now I cannot get the data out of the first loop and into the second loop.

    See my example for one method of how to setup the Queue which Omar suggested. You'll also see many other ways, most of which should be avoided until you get more experience.
    Communicating Between Loops
    Richard

  • How can I transfer data from one iPhone to another iPhone which is already set up?

    I have an old phone that I want to transfer data to. The phone is set up with previous data. How do I transfer current data to it?

    if the iphone have not been synced with another computer then just sync it with yours
    if it have then you cant syncing it with your computer would then clear the iphone and adding the info from your itunes to it

  • How do I make data from one Table flow into a separate Table

    How do I make data from one Table flow into a separate Table in iworks numbers?

    Great stuff Yvan,
    KOENIG Yvan wrote:
    Here you may see the way to transfer the contents of a column of Table A in a column of Table B
    I used two kinds of formulas.
    In the cell A2 of Table B
    the formula is :
    =Table A :: $B2
    It may be :
    =Table A :: $B
    Apply Fill Down
    Copy paste it in cell A1 which is in a header row.
    This formula does its duty but it’s not robust enough and will not survive to a Sort.
    This is why in B2, I inserted a more robust formula :
    =OFFSET(Table A :: $A$1,ROW()-1,2)
    You will find details about the functions used in Numbers User Guide delivered with every copy of iWork ‘08
    Yvan KOENIG (VALLAURIS, France) samedi 6 août 2011 17:45:22
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.0
    My iDisk is : <http://public.me.com/koenigyvan>
    Please : Search for questions similar to your own before submitting them to the community
    To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer !
    The first suggestion was the simple answer I needed,
    Thank you

  • How can i extract data from oracle table  to flat file or excel spread shee

    Hello,
    DB Version is 10.1.0.3.0
    How can i extract data from oracle table to flat file or excel spread sheet by using sub programs?
    Regards,
    D

    Here what I did
    SET NEWPAGE 0
    SET SPACE 0
    SET LINESIZE 80
    SET PAGESIZE 0
    SET ECHO OFF
    SET FEEDBACK OFF
    SET VERIFY OFF
    SET HEADING OFF
    SET MARKUP HTML OFF SPOOL OFF
    Sql> SPOOL bing
    select * from -------;
    SPOOL OFF;
    I do not see file.
    I also tried
    Sql> SPOOL /tmp/bing
    select * from -------;
    SPOOL OFF;
    But still not seeing the fie,

  • Adding Data From One Table to Another

    Now, this doesn't strike me as a particularly complex problem, but I've either strayed outside the domain of Numbers or I'm just not looking at the problem from the right angle. In any case, I'm sure you guys can offer some insight.
    What I'm trying to do is, essentially, move data from one table to another. One table is a calendar, a simple two column 'date/task to be completed' affair, the other is a schedule of jogging workouts, i.e, times, distances. Basically, I'm trying to create a formula that copies data from the second table onto the first but only for odd days of the week, excepting Sundays (and assuming Monday as the start of the week). Now, this isn't the hard part, I can do that. The problem comes when I replicate the formula down the calendar. Even on the days when the 'if' statement identifies it as an 'even day', the cell reference to the appropriate workout on the second table is incremented, so when it comes to the next 'odd day', it has skipped a workout.
    I can't seem to see any way of getting it to specifically copy the NEXT line in the second table, and not the corresponding line.
    This began as a distraction to try and organise my running so I could see at a glance what I had to do that day and track my progress, but now it's turned into an obsession. SURELY there's a solution?
    Cheers.

    Hi Sealatron,
    Welcome to Apple Discussions and the Numbers '09 forum.
    Several possible ways to move the data occur to me, but the devil's in the details of how the data is currently arranged.
    Is it
    • a list of three workouts, one for each of Monday, Wednesday and Friday, then the same three repeated the following week?
    • an open-ended list that does not repeat?
    • something else?
    Regards,
    Barry

  • Copy data from one Table to another Table

    How can I copy data from one Oracle Table to another Oracle Table on a different server? Question 2: How can I clear all of the data in one Table with a single SQL script?
    Thanks...

    Question 1:
    I assume you have the privileges. If you don't, ask the DBA to give them to you. Then
    1. Login to database_source (It could be either the source or the target. Let's assume it's the source.)
    2. Create a database link to database_target: CREATE DATABASE LINK link_to_database_target CONNECT TO myuserid IDENTIFIED BY mypassword USING 'database_target'; Note the single quotes.
    3. Copy the table data: INSERT INTO targetowner.mytable@link_to_database_target SELECT * FROM sourceowner.mytable; COMMIT;
    Question 2:
    You have two options, but you may not have privileges for both.
    Option 1:
    DELETE FROM tableowner.tablename; COMMIT;
    Advantage: Since this is a DML (Data Manipulation Language) statement, you have to commit the transaction. Also, the data will be gone but the table size is NOT changed, so it's ready for accepting replacement data. DML statements can simply be executed not only from SQL scripts, but from PL/SQL scripts as well.
    Disadvantage: Slow, because all record deletion is logged, so you can recover from it by issuing a ROLLBACK; instead of the COMMIT; above. The table size is NOT changed, so if you are short of disk space or tablespace space, you have not resolved the issue.
    Option 2:
    TRUNCATE TABLE tableowner.tablename;
    Advantage: Since this is a DDL (Data Definition Language) command, you do NOT have to commit the transaction. (DDL commands automatically commit both before and after their execution.) The table size will be changed back to the initial extent size which is the minimum size a table can have and can only be set when the table is created. If it needs to be changed, the table has to be dropped and recreated with a different initial extent size. The statement execution of this command is not logged, therefore it's much faster then the DELETE.
    Disadvantage: No rollback. Being a DDL, this command cannot be executed straight from PL/SQL. If you need to issue this within PL/SQL, you will have to use dynamic SQL.

  • Moving time-dependant data from one table to another (archiving)

    Hello all
    I would like to know if there's an easier solution or a "best practice" to move data from one table to another. The context of this issue can be found within "archiving".
    More concretely: we have an application that uses several tables to log information to.
    These tables are growing like crazy, and we would like to keep only "relevant" data in those tables, so I was thinking about moving data from these tables that have been in there for, say 2 months, to "archiving" tables.
    I figured there must be some kind of "best practice" to get this done.
    I have already written a procedure that loops the table that has the time indicator and inserts the records from the normal tables into the archive tables (and afterwards delete this data), but it seems to be taking ages to get it done.
    Thanks in advance!
    Message was edited by:
    timschraepen

    There is nothing to do with PL/SQL.
    You can refer below links:
    http://www.lc.leidenuniv.nl/awcourse/oracle/server.920/a96524/c12parti.htm
    http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10739/partiti.htm#i1006727

  • Insert old missing data from one table to another(databaase trigger)

    Hello,
    i want to do two things
    1)I want to insert old missing data from one table to another through a database trigger but it can't be executed that way i don't know what should i do in case of replacing old data in table_1 into table_2
    2)what should i use :NEW. OR :OLD. instead.
    3) what should i do if i have records exising between the two dates
    i want to surpress the existing records.
    the following code is what i have but no effect occured.
    CREATE OR REPLACE TRIGGER ATTENDANCEE_FOLLOWS
    AFTER INSERT ON ACCESSLOG
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    DECLARE
    V_COUNT       NUMBER(2);
    V_TIME_OUT    DATE;
    V_DATE_IN     DATE;
    V_DATE_OUT    DATE;
    V_TIME_IN     DATE;
    V_ATT_FLAG    VARCHAR2(3);
    V_EMP_ID      NUMBER(11);
    CURSOR EMP_FOLLOWS IS
    SELECT   EMPLOYEEID , LOGDATE , LOGTIME , INOUT
    FROM     ACCESSLOG
    WHERE    LOGDATE
    BETWEEN  TO_DATE('18/12/2008','dd/mm/rrrr') 
    AND      TO_DATE('19/12/2008','dd/mm/rrrr');
    BEGIN
    FOR EMP IN EMP_FOLLOWS LOOP
    SELECT COUNT(*)
    INTO  V_COUNT
    FROM  EMP_ATTENDANCEE
    WHERE EMP_ID    =  EMP.EMPLOYEEID
    AND    DATE_IN   =  EMP.LOGDATE
    AND    ATT_FLAG = 'I';
    IF V_COUNT = 0  THEN
    INSERT INTO EMP_ATTENDANCEE (EMP_ID, DATE_IN ,DATE_OUT
                                ,TIME_IN ,TIME_OUT,ATT_FLAG)
         VALUES (TO_NUMBER(TO_CHAR(:NEW.employeeid,99999)),
                 TO_DATE(:NEW.LOGDATE,'dd/mm/rrrr'),       -- DATE_IN
                 NULL,
                 TO_DATE(:NEW.LOGTIME,'HH24:MI:SS'),      -- TIME_IN
                 NULL ,'I');
    ELSIF   V_COUNT > 0 THEN
    UPDATE  EMP_ATTENDANCEE
        SET DATE_OUT       =  TO_DATE(:NEW.LOGDATE,'dd/mm/rrrr'), -- DATE_OUT,
            TIME_OUT       =   TO_DATE(:NEW.LOGTIME,'HH24:MI:SS'), -- TIME_OUT
            ATT_FLAG       =   'O'
            WHERE EMP_ID   =   TO_NUMBER(TO_CHAR(:NEW.employeeid,99999))
            AND   DATE_IN <=  (SELECT MAX (DATE_IN )
                               FROM EMP_ATTENDANCEE
                               WHERE EMP_ID = TO_NUMBER(TO_CHAR(:NEW.employeeid,99999))
                               AND   DATE_OUT IS NULL
                               AND   TIME_OUT IS NULL )
    AND   DATE_OUT  IS NULL
    AND   TIME_OUT IS NULL  ;
    END IF;
    END LOOP;
    EXCEPTION
    WHEN OTHERS THEN RAISE;
    END ATTENDANCEE_FOLLOWS ;
                            Regards,
    Abdetu..

    INSERT INTO SALES_MASTER
       ( NO
       , Name
       , PINCODE )
       SELECT SALESMANNO
            , SALESMANNAME
            , PINCODE
         FROM SALESMAN_MASTER;Regards,
    Christian Balz

Maybe you are looking for