Search
 
SCRIPT & CODE EXAMPLE
 

SQL

split a database into related tables based on their structure in MySQL

CREATE TABLE old_table (name VARCHAR(255), id BIGINT, colg VARCHAR(255), schol VARCHAR(255), addit VARCHAR(255), no VARCHAR(255), subject VARCHAR(255), marks VARCHAR(255), surname VARCHAR(255), lectures VARCHAR(255));

INSERT INTO old_table VALUES("shaun", 1234, "DePaul University", "Computing and Digital Media", "something", "something", "some subject", "A", "Husain","no thank you");

mysql> SELECT * FROM old_table;
+-------+------+-------------------+-----------------------------+-----------+-----------+--------------+-------+---------+--------------+
| name  | id   | colg              | schol                       | addit     | no        | subject      | marks | surname | lectures     |
+-------+------+-------------------+-----------------------------+-----------+-----------+--------------+-------+---------+--------------+
| shaun | 1234 | DePaul University | Computing and Digital Media | something | something | some subject | A     | Husain  | no thank you |
+-------+------+-------------------+-----------------------------+-----------+-----------+--------------+-------+---------+--------------+
1 row in set (0.00 sec)

CREATE TABLE table1 (name VARCHAR(255), id BIGINT PRIMARY KEY, colg VARCHAR(255), schol VARCHAR(255), addit VARCHAR(255), no VARCHAR(255));
CREATE TABLE table2 (id BIGINT PRIMARY KEY, subject VARCHAR(255), marks VARCHAR(255), surname VARCHAR(255), lectures VARCHAR(255));

INSERT INTO table1 (name,id,colg,schol,addit,no) SELECT name,id,colg,schol,addit,no from old_table;
INSERT INTO table2 (id,subject,marks,surname,lectures) SELECT id,subject,marks,surname,lectures from old_table;

mysql> select * from table1;
+-------+------+-------------------+-----------------------------+-----------+-----------+
| name  | id   | colg              | schol                       | addit     | no        |
+-------+------+-------------------+-----------------------------+-----------+-----------+
| shaun | 1234 | DePaul University | Computing and Digital Media | something | something |
+-------+------+-------------------+-----------------------------+-----------+-----------+
1 row in set (0.00 sec)

mysql> select * from table2;
+------+--------------+-------+---------+--------------+
| id   | subject      | marks | surname | lectures     |
+------+--------------+-------+---------+--------------+
| 1234 | some subject | A     | Husain  | no thank you |
+------+--------------+-------+---------+--------------+
1 row in set (0.00 sec)

mysql> select * from table1 LEFT JOIN table2 on (table1.id=table2.id);
+-------+------+-------------------+-----------------------------+-----------+-----------+------+--------------+-------+---------+--------------+
| name  | id   | colg              | schol                       | addit     | no        | id   | subject      | marks | surname | lectures     |
+-------+------+-------------------+-----------------------------+-----------+-----------+------+--------------+-------+---------+--------------+
| shaun | 1234 | DePaul University | Computing and Digital Media | something | something | 1234 | some subject | A     | Husain  | no thank you |
+-------+------+-------------------+-----------------------------+-----------+-----------+------+--------------+-------+---------+--------------+
1 row in set (0.00 sec)
Comment

PREVIOUS NEXT
Code Example
Sql :: greater than and less than in mysql query 
Sql :: SQL Injection Using Multiple Statement 
Sql :: oracle archivemode 
Sql :: SQL Hello, [firstname] [lastname] 
Sql :: error infor in sql server 
Sql :: delete record by id sql 
Sql :: ERROR: column "hourly_visitors.hour" must appear in the GROUP BY clause or be used in an aggregate function 
Sql :: enable mysql remote connection to two specific ip address 
Sql :: mysql user set plugin 
Sql :: get create sql of hibernqte entity 
Sql :: how to run sql script in postgresql in windows 
Sql :: delete hangfire retries list 
Sql :: pagination with row_number 
Sql :: añadir clave foranea mysql 
Sql :: redshift alter table alter column set not null 
Sql :: enter postgres shell o localhost 
Sql :: mysql insert into select with recursive 
Sql :: mostrar datos de tablas relacionadas mysql kjava 
Sql :: mysql phpmyadmin mysqli_construct:: error for mac user 
Sql :: ring MySQL presents the usage of MySQL_Autocommit(), MySQL_Commit() & MySQL_RollBack() functions. 
Sql :: sql get frist of month 
Sql :: oracle rolling back 
Sql :: add mysql database to power bi web 
Sql :: export partttion and import in oracle 
Sql :: write sql query to show the details start from digit 
Sql :: start whith system mysql 
Sql :: order by monthly in sql 
Sql :: Table aliases 
Sql :: sql tablo sp 
Sql :: concatenate text from multiple rows into a single text stringin SQL Server 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =