Need help starting simple MySQL database using data from Excel - mysql

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.

Related

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?

Asking opinion about table structure

I'm working on a project to make a digital form of this paper
this paper (can't post image)
and the data will displayed on a Web in a simple table view. There will be NO altering, deleting, updating. It's just displaying (via SELECT * of course) the data inputted.
The data will be inserted via android app and stored in a single table which has 30 columns in mysql.
and the question is, is it a good idea if i use a single table? because i think there will be no complex operation in the sql.
and the other question is, am i violating some rules for this method?
I need your opinion. thanks.
It's totally ok to use only one table, if that suits your needs. What you can do to make the database a little bit 'smarter' is add new tables for attributes in your paper that will be repeated. So, for example, the Soil Type could be another table where there are two columns, ID and Description, and you will use it as a foreign key in each record in the main table. You need this if you want your database to be in 3NF.
To sum up, yes you can have one table if that's all you need. However, adding more tables might help save some space and make your database more flexible. It's up to you to decide! :)

What is a dictionary table in SQL?

I have to build this retail site, and aparently all the properties info comes from a third party company. Everything looked fine, they sent me a .mdb file with all the tables (which convert to a .sql file), and later I get emailed with data to update those tables.
What confused me was the fact that a few of these tables already have values in them. And when looking at the documentation, it says that I will also get emailed 'dictionary tables'. It says: "These tables contain fixed values in reference to value tables".
I have googled and searched here at stalkoverflow but couldnt find an answer. What I read was something about 'sas' and 'proc sql' which I haven't heard before.
Could someone please explain me (or kindly point me to some understandable documentation) what this tables are (are they in fact tables?), and how can I use them to build my site? I also use Codeigniter, can I use active records on them? Or what would be the correct SQL to access that table? I'm pretty much lost here :(
I use Codeigniter 2.x and Mysql.
Thanks guys, I will be infinetely grateful for your help.
Two guesses:
a data dictionary provides information about tables in a database:
field names, field types, field sizes
stored procedures associated with certain tables
OR
simply a fixed table that provides lookup or validation for a separate updatable table.

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

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.

Each user has different 'structure' using only one table

I'm trying to do it like this:
Every single user can choose fields (like structures on MySQL) where this fields can handle their respective value, it's like doing a DB inside a DB.
But how can I do it using a single table?
(not talking about user accounts etc where I should be able to use a pointer to his own "structure")
Do something like: varchar Key where register something like "Name:asd" where PHP explode : to get the respective structure ('name' in this case) and the respective value? ('asd')
Use BLOB? can someone turn the light on for me? I don't know how to do something where works better than my current explanation...
I know my text is confuse and sorry for any bad english.
EDIT:
Also, they could add multiple keys/"structures" where accepts a new value
And they are not able to see the Database or Tables, they still normal users
My server does not support Postogre
In my opinion you should create two tables.
with the user info
with 3 fields (userid, key and value)
Each user has 1 record in the first table. Each user can have 0 or more records in the second table. This will ensure you can still search the data and that users can easily add more key/value pairs when needed.
Don't start building a database in a database. In this case, since the user makes the field by himself there is no relation between the fields as I understand? In that case it would make sense to take a look at the NoSQL databases since they seem to fit very good for this kind of situations.
Another thing to check is something like:
http://www.postgresql.org/docs/8.4/static/hstore.html
Do not try to build tables like: records, fields, field types etc. That's a bad practice and should not be needed.
For a more specific answer on your wishes we need a bit more info about the data the user is storing.
While i think the rational answer to this question is the one given by PeeHaa, if you really want the data to fit into one table you could try saving a serialized PHP array in one of the fields. Check out serialize and unserialize
Generates a storable representation of a value
This is useful for storing or passing PHP values around without losing
their type and structure.
This method is discouraged as it is not at all scalable.
Use a table with key-value pairs. So three columns:
user id
key ("name")
value ("asd")
Add an index on user id, so that you can query a user's attributes easily. If you wanted to query all users with the same properties, then you could add a second index on key and/or value.
Hope you are using a programming language also to get the data and present them.
You can have a single table which has a varchar field. Then you store the serialized data of the field structure and their value in that field. When you want to get the structure, query the data and De-serialize that varchar field data.
As per my knowledge every programming language supports serialization and De-serialization.
Edited : This is not a scalable option.