Search
 
SCRIPT & CODE EXAMPLE
 

SQL

divide database into structured tables

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 :: min:sec datediff mssql 
Sql :: java mysql date format 
Sql :: http://localhost:9200/_cluster/allocation/explain 
Sql :: mysql table inspector command line 
Sql :: how to create roles in oracle developer sql 
Sql :: http://challenge01.root-me.org:58036/wsasd 
Sql :: create table with error 
Sql :: psql create usr 
Sql :: download sql file of countries names 
Sql :: could not find driver (SQL: PRAGMA foreign_keys = ON;) larave 
Sql :: call function sql oracle with output put line 
Sql :: [] Wildcard in SQL 
Sql :: t-sql conditional order by multiple columns 
Sql :: xampp table doesn 
Sql :: sql restore database from bak file 
Sql :: check sql query executed wp 
Sql :: create sql table 
Sql :: azure sql-datenbank 
Sql :: view psql output in horizontal scrolling 
Sql :: add two days to current date in sql when creating tables 
Sql :: learn sqlite dart 
Sql :: big query get distinct array of objects 
Sql :: updating mysql 
Sql :: from weeknumber to date 
Sql :: AddEntityFrameworkSqlite 
Sql :: how to user id to show in from date to upto date in mssql server 
Sql :: how to install sql server 
Sql :: mysql order by desc 
Sql :: Data type and their numeric form 
Sql :: sql into vs insert into 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =