Skip to content

Instantly share code, notes, and snippets.

@thiamsantos
Created April 4, 2017 00:36
Show Gist options
  • Save thiamsantos/578dd9b8bff96e2b6d94e8717f6fb5dd to your computer and use it in GitHub Desktop.
Save thiamsantos/578dd9b8bff96e2b6d94e8717f6fb5dd to your computer and use it in GitHub Desktop.
TODOS sql
CREATE TABLE users (
id BIGINT(8) AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(16) NOT NULL,
email VARCHAR(255) NOT NULL,
password VARCHAR(32) NOT NULL
);
CREATE TABLE todos (
id BIGINT(8) AUTO_INCREMENT PRIMARY KEY,
completed TINYINT(1) NOT NULL DEFAULT 0,
text VARCHAR(255) NOT NULL,
user_id BIGINT(8),
FOREIGN KEY (user_id) REFERENCES user(id)
);
INSERT INTO users (username, email, password)
VALUES ('batman', 'batman@gmail.com', '1234');
INSERT INTO todos (text, user_id)
VALUES ('HEY There', 1);
SELECT * FROM todo JOIN user on todo.user_id = user.id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment