Need to Change ids of records from SugarCRM Export for Accounts and Contacts - csv

I have a bit of a complex issue to deal with here at the moment and would love some help please.
I have exported data from SugarCRM in CSV format to be imported in to my new app. Now my app works slightly differently in terms of database schema. I use auto-incrementing integers for id's where as SugarCRM uses long alphanumeric strings like dc4c072c-ec0e-26b6-8780-4a9e7ec8375d.
I need to be able to take the data for say accounts and contacts, using the SugarCRM pivot table export from accounts_contacts, and change the id's, while keeping them all linked correctly. I then need to use the changed data to import in to my database, where each record in the contacts table contains an account_id field which links them to accounts, rather than a pivot table.
Now, my first thoughts would be to import all the required data in to clean database and use a lookup table with four fields in it to change the id's. So I would have old_account_id, new_account_id, old_contact_id, new_contact_id. I'd then use that table to find the right id's and amend the data.
The only issue I have with this, is that my SQL isn't amazing, so I'm having difficulty visualising and writing the query to use the lookup table and change the data. So I would love some help with this.
Also, once I have the query and the correct amended data, I need another query to then create the contacts table using an account_id field from the pivot table.
Hope you guys can help out. Thanks in advance.

Are you planning on keeping the data in sync? I'd suggest adding a "sugar_id" column in your app and a "your_app_id" column in SugarCRM. This way the native id column remains the same and that it will maintain a reference to the record in the other system.

Related

How can I update values in MySQL database table to conform to a different pattern?

I intend to clean some data in a MySQL database table for some data that was not properly captured. The table in question contains numerous columns but the column of interest is named id_number. Sample data in the column is captured as follows: BUT3345622019, PAC1034412016, etc. in that format. However, my requirement is to re-write each value in the column replacing it with values like BUT-3-3456-2/2019, PAC-1-0344-1/2016, etc. I have been thinking about the perfect SQL script (in MySQL) to solve the problem but so far I have not been successful. The table name is users. I am requesting for some help on this particular problem.

Need help starting simple MySQL database using data from Excel

I'm and intern and I've been tasked with something I'm pretty unfamiliar with. My manager has requested I create a simple MySQL database using data from an Excel file(s) and I have no idea where to start. I would normally ask someone here for help but everyone seems to be really busy. Basically, the purpose of the database is to see what different object-groups relate to one another so as to keep things standardized. Trying not to go into detail about things not really relevant.
I was asked to first design a schema for the database and then I would get an update on how to implement it. Would I just start by writing queries to create tables? I'm assuming I would need to convert the Excel files to .csv, how do I read this data and send it to the correct table based on Object Type (an attribute of each object, represented in a column)?
I don't want to ask too much right now, but if someone could help me understand what I need to do to get started I would really appreciate it.
Look at the column headers in your spread sheet.
Decide which columns relate to Objects and which columns relate to Groups
The columns that relate to just Objects will become your field names for the Object table. Give this table an ID field so you can uniquely identify each Object.
The columns that relate to the Groups will become field names for a Group table. Give this table an ID field so you can uniquely identify each Group.
Think about if an Object can be in more than one Group - if so you will probably need an Object-Group table. This table would most likely contain an ObjectID and a GroupID.

In a mysql database is it possible to find a table that would contain a specific column name?

I’m using a heavy duty CMS and have created a new data field for a certain content type. the data field is named ‘sort order’ or possibly ‘sort_order’. I’m assuming the data field is added to a table and have no way of knowing which table it was added to. When viewing the database via phpmyadmin there are simply too many tables to go looking for it.
Is there any way possible to do a search to find which table would contain this column name? or maybe an alternate method would be some look for most recent updated table?

How to Map/Merge multiple tables?

I am new to SQL, I am trying to "map" data from several tables in ONE database to create ONE table with relational information. For example, I am trying to take data from my tables ps3_productcategories, ps3_categories and "map"/"merge" to the ps3_products table, The previous tables contains all the "category information" needed to map to "correct products".
I am trying to "MAP" the productID to the "correct"=> categoryID=> categoryName=> categoryParent etc.....
Any help would be appreciated
I suggest you look into views, it may be what you are looking for, although they do not create this in another database they do allow to create virtual tables from existing data.
A database View is known as a "virtual table" which allows you to query the data in it.
See the MySql manpage on views..
And here is a small tutorial on the subject.
If you really need this in a seperate database, you can easily create a view and export the results of that, and import it in other database.

Merging tables from two Access databases into one new common

I have this assignment that I think someone should be able to help me. I have 5 ACCESS databases wvrapnaoh.accdb, wvrappaul.accdb, ....etc. These databases have about 45 tables each and 15 forms. The good part is the structure, the name and the fields of each table in all the databases are all the same except the data or the records are different. For example I have a stress table in wvrapnoah as well as wvrappaul with the same fields in both tables but different data or records.
So, I need to merge all these five into a new Access database that will have the same structure as the 5 databases but will include the complete data that is all the records from the 5 databases merged into this new database.The same applies to even the 15 forms. It does not seem to be having a primary key I guess. I was planning to add a field for each table that would give me the name of the database as well from which it was merged. Example I will add a DBName field in Wvrapnoah in all the tables and add the name Noah in that field for all the records in each table. I basically need to automate this code.
I need a script (VBA or anything) so that the guys creating these databases can just run this script the next time and merge the databases.
Talking about the 'table' part of the problem:
Questions
Are the databases / table names defined or you don't know them?
Are you able to use linked tables?
I believe the straightforward way to merge all of them is to link all tables into a single access DB and then run a UNION ALL query. It would be something like this:
SELECT "HANK", *
FROM MyTableHank
UNION ALL
SELECT "JOHN", *
FROM MyTableJohn;
Notice I defined a field to identify the origin of the data being merged ("HANK", "JOHN"), as you suggested above.
About the forms, I believe you'll need to import them and then review the whole code. It basically depends on what the forms are doing. If they're query-based won't be a big deal (importing / fixing the queries, will make the form works). However, if the forms are related to the tables, you'll have more work to do.