Q:

SQL error 1113 even though table is created

I am getting an error 1113 for this which states that there are no columns in the table, even though I did initiate them, does anyone know why this is the case? 
Also under " insert into P (Pid, pstring, Tid) " how do i set Tid as a foreign key for the Tid in the T table, so that I dont manually have to plug it in?
DROP DATABASE IF exists DB1;
CREATE DATABASE DB1;
USE DB1;
Create Table T;
insert into T (Tid, tstring)
values (1, "t1");
Create Table P;
insert into P (Pid, pstring, tid)
values (1, "p1", 1),
 (2, "p2", 1),
 (3, "p3", 1),
 (4, "p4", 1),
 (5, "p5", 1);
SHOW TABLES;

A:

You are not creating any columns in your Create Table T; or Create Table P; commands. To create the columns and add a foreign key, use something like this code instead:
Create Table T (Tid INT PRIMARY KEY,
                tstring VARCHAR(100)
                );
Create Table P (Pid INT PRIMARY KEY,
                pstring VARCHAR(100),
                tid INT,
                FOREIGN KEY (tid) REFERENCES T(Tid)
                );

You can adjust the size of tstring and pstring as required. The important thing in terms of creating a foreign key is that T.Tid must have an index on it, and the type of P.tid must match that of T.Tid.
Demo on dbfiddle

