insert data from one table to another table table name genrated runtime without declaring the table fields


HOME ยป Databases

I have two table say table1 and table2 all the columns in both table are same but table2 has some extra column in which i want to insert a some default value and name of table is generated runtime so table name can be changed so i cant declare the field of table.


Related to : insert data from one table to another table table name genrated runtime without declaring the table fields
Insert the data from Old table to new table, ID from new table and update for the corresponding row in old table. Most optimized way?
Databases

I have two table. OLDTABLE and NEWTABLE.
I need to insert some data from oldtable to newtable and the get the ID from new table and update in the oldtable for that corresponding row. the newtable ID has seperate column in oldtable which is null by default.


One way is to get the ID from both table while inserting the data in new table and then later find the data in oldtable and update it. Which is simpler way.


Can anyone suggest some optimized way to do so?


Combine multiple records in a table into one field in another table based on fields in a third table
Databases

I have three tables:


Table 1:
pid, name, address
1 Dale BLANK
Table 2:
pid, moid
1 12
Table 3:
moid, address
12 123 Main
12 12 South
12 99 North

For output I need:


Table 1:
pid, name, address
1 Dawn 123 Mian,12 South,99 North

How can i combine multiple addresses in table 3 into one address field in table 1 linking the two tables with information in table 2?


Can I select a set of rows from a table and directly insert that into a table or the same table in SQL?
Databases

Hi all I was just curious if I could do something like -


insert into Employee ( Select * from Employee where EmployeeId=1)

I just felt the need to do this a lot of times...so just was curious if there was any way to achieve it..


A2K3 table design issue? - Populating table fields with summary data from same table
Databases
I have a relatively simple (I assume) issue which I am at a complete
loss to address. My issues is: I want to populate fields in my tables
with summary data from the same table. Let me explain:
tblItemDetails (contains data on food products purchased)
Item_Description_ID (key, source link to tblMenuItemRecipe)
Item_Unit_of_Measure
Item_Location
Item_Type
Item_Category
Menu_Unit_Of_Measure
Menu_UOM_Conversion
tblMenuMaster (contains information about restaurants Menu)
Menu_Description_ID (key, source link to tblMenuItemRecipe)
Menu_Category
Menu_Type
Menu_Memo
tblMenuItemRecipe
Default Table Owner using CREATE TABLE, INSERT, SELECT & DROP TABLE
Databases
For reasons that are not relevant (though I explain them below *), I
want, for all my users whatever privelige level, an SP which creates
and inserts into a temporary table and then another SP which reads and
drops the same temporary table.
My users are not able to create dbo tables (eg dbo.tblTest), but are
permitted to create tables under their own user (eg MyUser.tblTest). I
have found that I can achieve my aim by using code like this . . .
SET @SQL = CREATE TABLE + @MyUserName + . + tblTest(tstID
DATETIME)
EXEC (@SQL)
SET @SQL = INSERT INTO + @MyUserName + . + tblTest
(tstID) VALUES(GETDATE())
EXEC (@SQL)<
Insert into a table fields from another table based on a field
Databases
Hi All
I have 2 tables (as shown below), if i add a row to the FILES TABLE then the myid value is added to mydata list in the PLAYLISTS TABLE, based on the genre matching the myname values.
Hope this makes sense.
So my question is how do i add myid to mydata when new files are added to the FILES TABLE.
Thanks
FILES TABLE
filepath.........artist..............album.....gen re.......myid
c:/files..........u2..................war........Rock ........1234
c:/files..........u2..................war........Rock ........1235
c:/files..........u2..................war........Rock ........1236
c:/files..........madonn
can not insert row in a table while data redirecting from parent table to child table in trigger(stored procedure)
Databases

I am using postgres version: PostgreSQL 9.2.4 on x86_64-unknown-linux-gnu, compiled by gcc (Debian 4.7.2-5) 4.7.2, 64-bit

Description:

I have one parent table and that parent table has many child tables. I want to redirect the data from parent table to child table (while insertion)

(same As this link: Example Link ) (example of ice cream company)

I did following things...

create table tsttbl1 (id integer, name text);

create table tsttbl1_hour0 (LIKE tsttbl1) INHERITS (tsttbl1);

CREATE OR REPLACE FUNCTION insert_tsttbl1_hourbase() RETURNS TRIGGER
AS $$
BEGIN
    RAISE NOTICE 'Hi...%', NEW;
    execute 'INSERT INTO ' || TG_TABLE_SCHEMA|| '.tsttbl1_hour0 values
'|| NEW;
    -- INSERT INTO tsttbl1_hour0 values (NEW.*)';
    RETURN NULL;
END;
$$ LANGUAGE plpgsql;

create trigger trigger_insert_tsttbl1_hourbase before insert on
tsttbl1 FOR EACH ROW EXECUTE PROCEDURE insert_tsttbl1_hourbase();

Here,

parent table:- tsttbl1

child table:- tsttable1_hour0

Trying to achieve: insert into tsttbl1 (id, name) values (0,'xyz');

should insert data in tsttable1_hour0 instead of tsttbl1;

But When i tried to insert the row, i am getting like this...

ccc=# insert into tsttbl1 (id,name) values (1, 'abc');
LOG:  statement: insert into tsttbl1 (id,name) values (1, 'abc');
NOTICE:  Hi...(1,manan)
ERROR:  column "abc" does not exist
LINE 1: INSERT INTO act1.tsttbl1_hour0 values (1,abc)
                                                 ^
QUERY:  INSERT INTO act1.tsttbl1_hour0 values (1,abc)
CONTEXT:  PL/pgSQL function insert_tsttbl1_hourbase() line 4 at
EXECUTE statement

Additional Information:

-> This data redirection can also be achieved by rule. But for my case, this insertion is frequently, so rule might be costly compare to trigger...

so i want to achieve this by trigger only.

-> if i un comment the line "INSERT INTO tsttbl1_hour0 values (NEW.*)'" .. row is inserted successfully



Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .