Relational database phpmyadmin varchars instead of IDs - mysql

I'm trying to create relational database. I have 2 columns in 2 tables that I would like to connect, both are varchars.
Both relations are one to many. One column Patch_No and second Champion. I've added to both indexes.
First table:
Second Table:
Here is also relational view:
http://i.imgur.com/G5MHVsD.png

Related

SQL query for Altering all the schemas present in a workbench?

I have 5 schemas, each of which has its own number of tables, but I have one table common for all the schemas(ex: Student). Can anyone tell me SQL query on how to add a field to all the Student table present in all the schema's.

mysql - can i make column refrence to table?

in mysql, there is some pre-created databases, in information_schema database contains a lot of stuff, among them :
information_schema.TABLES contains table_name
which contains every table name in databases, and it's linked to table, when clicked it select the table for you
my question is, can i do the same thing to table?
i did (foreign key) or (indexes) for columns before but never tried for table, is it possible?
thanks!

how to structure large table and its transactions in database?

I have two big tables for example:
'tbl_items' and 'tbl_items_transactions'
First table keeping some items metadata which may have 20 (varchar) columns with millions rows... and second table keeping each transaction of first table.
for example if a user insert new record to tbl_items then automatically a new record will be adding to tbl_items_transactions with same data plus date, username and transaction type to keep each row history.
so in the above scenario two tables have same columns but tbl_items_transactions have 3 extra columns date, username, transaction_type to keep each tbl_items history
now assume we have 1000 users that wants to Insert, Update, Delete tbl_items records with a web application. so these two tables scale very soon (maybe billion rows in tbl_items_transactions)
I have tried MySQL, MariaDB, PostgreSQL... they are very good but when table scale and millions rows inserted they are slow when run some select queries on tbl_items_transactions... but sometimes PostgreSQL is faster than MySQL or MariaDB
now I think I'm doing wrong things... If you was me... do you use MariaDB or PostgreSQL or somthing like that and structure your database like what I did?
Your setup is wrong.
You should not duplicate the columns from tbl_items in tbl_items_transactions, rather you should have a foreign key in the latter table pointing to the former.
That way data integrity is preserved, and tbl_items_transactions will be much smaller. This technique is called normalization.
To speed up queries when the table get large, define indexes on them that match the WHERE and JOIN conditions.

MYSQL Select tables starting with "x"

I have a bunch of tables in my "stats" database.
tcl20151w1d1
tcl20151w1d2
tcl20151w2d1
tcl20151w2d2
tcl20151w3d1
tcl20151w3d2
tcl20151w4d1
eu20151w1d1
eu20151w1d2
eu20151w2d1
eu20151w2d2
eu20151w3d1
eu20151w3d2
eu20151w4d1
..
How can i select all tables that starts with "tcl" in "stats" database. Is it possible? Do I have to union them manually?
You can query information_schema.tables table to get a list of tables where the table name start with tcl.
You can use the list to dynamically create a union query in a stored procedure using string concatenation and prepared statements.
If those tables are all myisam tables with the same structure, you may consider creating a merge table on them:
The MERGE storage engine, also known as the MRG_MyISAM engine, is a
collection of identical MyISAM tables that can be used as one.
“Identical” means that all tables have identical column and index
information.

What is better 2 tables 28 columns or 1 table 56 columns

I am using MySQL to store historical data for my weather station so that I can come up with and report monthly and yearly records.
I have a table with 28 columns and 1 row which works well with the monthly data.
I wish now to process data to make comparisons with yearly data. To do this requires a further 30+ columns with 1 row.
What do people think is the most efficient:
(a) Create a separate table for the yearly data or
(b) simply add the necessary number of columns for the yearly data to the one existing table.
Thanks
Keith Griffin
Brisbane, Australia
I suggest you to add necessary columns in single table only.
There is one major headache when you split columns in two table which is they all will have same primarykey but you will have to maintain primarykey in two tables + more complex query may need to be write in update,insert and delete.
So as per Database Normalization rules you should keep all columns in one table.
Check out database Normalization