Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

How to import data into my new database table

Questions related to using nuBuilder Forte.
Post Reply
icoso
Posts: 181
Joined: Sun Feb 07, 2021 11:09 pm
Been thanked: 1 time

How to import data into my new database table

Unread post by icoso »

I have my database system ready to use and need to import all the data from my old database (from another source) into my new TaxCustomers table. What is the best way to do this?

I currently have all the old data in a CSV file.

1. The Built-In CSV Transfer doesn't seem to be very customizable and appears to only import the data into a NEW table. Is this correct?
2. Once the CSV file is imported into a new table, how would be the best way to move the data in my Tax Customers table?
3. Since two of my fields in my existing TaxCustomers table contains encrypted data, SSN fields, how then can I run my encryption routine when importing the new data into my existing TaxCustomers Table?
4. Will I have to do this via a nuBuilder procedure or SQL code to move the data from one table to another?
5. Will this procedure or SQL code have to process this new data, one record at a time?
6. How do I generate the the TaxCustomers_id field data during the import that was automatically created by nuBuilder when I first created my Table?
7. My original database table (old data) has 1000's of records. Will nuBuilder be able to import and process this data?
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

Re: How to import data into my new database table

Unread post by kev1n »

1. Yes. You can also try using phpMyAdmin's Import feature.
2. https://stackoverflow.com/questions/424 ... ther-table
3. By running a PHP script after the import?

Why don't just just export the old table + data to an sql file and import it again (using phpMyAdmin) ?
icoso
Posts: 181
Joined: Sun Feb 07, 2021 11:09 pm
Been thanked: 1 time

Re: How to import data into my new database table

Unread post by icoso »

Why don't just just export the old table + data to an sql file and import it again (using phpMyAdmin) ?
I know how to export and import using phpMyAdmin. But that brings up question 6. How do I generate the the TaxCustomers_id field data during the import that was automatically created by nuBuilder when I first created my Table?

On every table that nuBuilder creates there is an "id" field that is added as the index for that table. It has a unique code id in it for every record. If I do a simple import using phpMYAdmin, How do I create that code? Is it a self-generating code id that MySQL generates for each records? Looking at the structure for any of the tables that nuBuilder creates that id does not have any auto-increment or any other function on it that I can tell. So I assumed I have to use the CSV import so that "id" field would get auto generated. When I did a test import using that CSV import function, nuBuilder added an id field and auto-populated it.

If I import directly into my TaxCustomers table using phpMyAdmin, that id field will not get auto-generated, right? So How do I do it? This is why I ask a lot of questions.
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

Re: How to import data into my new database table

Unread post by kev1n »

All the data you export can be re-imported 1:1.

E.g. when I export a table called product, the SQL looks like this:

Code: Select all

CREATE TABLE `product` (
  `product_id` varchar(25) NOT NULL,
  `pro_code` varchar(1000) DEFAULT NULL,
  `pro_description` varchar(1000) DEFAULT NULL,
  `pro_price` decimal(12,4) DEFAULT NULL,
  `pro_group` varchar(1000) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table `product`
--

INSERT INTO `product` (`product_id`, `pro_code`, `pro_description`, `pro_price`, `pro_group`) VALUES
('5d881a5cc309669', 'P1', 'Large Pineapple Pizza', '1.0000', 'Pizza'),
('5d881afd0f7e7ea', 'P2', 'Large Pizza wth the Lot', '23.0000', 'Pizza'),
('5d881b2d40b46ef', 'Prawn Pizza', 'Large Prawn Pizza', '27.5000', 'Pizza'),
('5d881ba8dd326a7', 'A2', 'Spaghetti and Meatballs', '15.5000', 'Pasta'),
('5d881be75552ac6', 'D1', 'Can of Coke', '3.0000', 'Drink'),
('5d881bf6c772e79', 'D1', 'Can of Pepsi', '3.0000', 'Drink');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `product`
--
ALTER TABLE `product`
  ADD PRIMARY KEY (`product_id`);
COMMIT;
Now when I either run the query or import the exported sql file, all data is imported into the db.
icoso
Posts: 181
Joined: Sun Feb 07, 2021 11:09 pm
Been thanked: 1 time

Re: How to import data into my new database table

Unread post by icoso »

Kev1n,

I understand how the phpMyAdmin works and exports and imports data. I've been using it for many years.

The data that Im trying to import is NOT coming from a nuBuilder table. This is a separate database that I am converting to nuBuilder. The old data that I need to ADD to my nuBuilder TaxCustomers database DOES NOT have the nuBuilder generated "id" field. Hence my questions andwhy I stated this in my original post:
need to import all the data from my old database (from another source)
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

Re: How to import data into my new database table

Unread post by kev1n »

Code: Select all

DOES NOT have the nuBuilder generated "id" field
Does your data contain another unique key? If you want to replace/or add one after importing yours data, you could run a php script that adds/replaces that key. use the PHP function nuID() to generate a unqiue id.

It's probably easier to use nuBuilder's csv import feature and then past your data into the other table or MySQL INSERT INTO SELECT
icoso
Posts: 181
Joined: Sun Feb 07, 2021 11:09 pm
Been thanked: 1 time

Re: How to import data into my new database table

Unread post by icoso »

No the data does not contain a unique key. I think Youre Right, I'll use the CSV import to import the data into a new table so that Unique key gets generated then I'll copy the data from that table into my existing Tax Customers table.
Post Reply