Gurgaon, , India
Javascript, HTML, jQuery
0 टिप्पणी करें | 16 लोगो ने देखा है | 25 दिसम्बर 12  | Sunil Kumar Yadav
Recently while working on one of my project i faced a requirement wherei have to merge tables of same field type but they are from two different Database. The schema of both the tables of two databases are the same but there was a problem that i am going to describe in below Figure 1- In Database1.Sqlite the table name was Areaofinterest and it consists ofIn this table Primary Key is ldquoidrdquo and traineeid and areaofinterestid are foreign key of two different tables. id traineeid areaofinterestid 1 1000 12 2 9201 2 3 9201 5 4 9201 8 5 5753 10 Similarly in Database2.Sqlite the table name was also Areaofinterest ofIn this table also Primary Key is ldquoidrdquo and traineeid and areaofinterestid are foreign key of two different tables. id traineeid areaofinterestid 1 2000 3 2 8800 11 3 8800 2 4 7001 5 5 7001 9 As u can see the in tables above there is conflict in ldquoIdrdquo.So, i decided to merge table of Database2 into table of Database1. Steps are as followsI use UBUNTU 1- Start Terminal and type sqlite3 and press Enter Key. 2- If ldquoCommand Not Foundrdquo then issue command ldquosudo apt-get install sqlite3rdquo then again try step 1 and you will be on sqlite command promptrdquosqlitegtgtrdquo. 3- Put both database in same directory and goto on that particular directory using ldquocdrdquo command. Eg- cd home/deo/projectfolder 4- Now issue command ldquoATTACH ldquoDatabasename.extensionrdquo as ALIAS NAME For eg- In my case I have to attach two databases so Attach ldquoDatabase1.Sqliterdquo As DB1 Attach ldquoDatabase2.Sqliterdquo As DB2 5- Repeat step 4 as many times as u want to attach as many databases 6- ldquo.Databsesrdquo command will let you know how many databases are attached right now. 7- Now to merge data of ldquoAreaofinterestrdquo table of Database1 into ldquoAreaofinterestrdquo table of Database2 issue commands sqlitegtgtInsert into DB1. Areaofinterest traineeid, areaofinterestid ..gtgtSelect traineeid,areaofinterestid from DB2. Areaofinterest And you will get your merged output NOTE- I have left id field while merging because id field is AUTOINCREMENT in table and it will insert each row and increment by its own but remember in my case the ldquoIDrdquo field is primary key and is not refrenced as Foreign Key in any other table. So keep in mind to set Primary key Autoincrement and Foreign key reference update clause like we use ldquoCASCADE ON DELETErdquo etc. Any Query feel free to ask..Have Fun

    • इस ब्लॉग के लिए सामाजिक शेयर

पोर्फोलिओ और ब्लॉग
Sunil Kumar Yadav विभिन्न कंपनियों का अनुसरण करता है, ये कंपनियां और नियोक्ता Sunil के फिर से शुरू देख सकते हैं
सबसे अच्छा नौकरी के अवसर पाने के लिए अपना फिर से शुरू करें अपलोड करें

मुफ्त रजिस्टर करें!