Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of SQL Script for User Table Creation #40

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions examples/create_user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE User (
id INT NOT NULL AUTO_INCREMENT,
username VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
last_login TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY (username),
UNIQUE KEY (email)
);
Comment on lines +1 to +11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ask explain this

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This SQL script is for creating a new table named User in a database. Each line within the parentheses defines a column in the table, specifying its name, data type, and any constraints or default values. Here's a breakdown of each line:

  • CREATE TABLE User (: This line starts the creation of a table named User.
  • id INT NOT NULL AUTO_INCREMENT,: Defines a column named id with data type INT (integer). It cannot be null (NOT NULL) and will auto-increment with each new record, typically used as a primary key.
  • username VARCHAR(255) NOT NULL,: Defines a username column that can store strings up to 255 characters. It cannot be null.
  • email VARCHAR(255) NOT NULL,: Similar to username, this defines an email column for storing email addresses, also up to 255 characters and not null.
  • password VARCHAR(255) NOT NULL,: A password column for storing user passwords, up to 255 characters, and cannot be null.
  • created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,: A created_at column that records the timestamp when a record is created. It cannot be null and defaults to the current timestamp when a new record is inserted.
  • last_login TIMESTAMP,: A last_login column to store the timestamp of the user's last login. It doesn't have a NOT NULL constraint, so it can be null if the user hasn't logged in yet.
  • PRIMARY KEY (id),: Specifies that the id column is the primary key of the table, ensuring each record has a unique id.
  • UNIQUE KEY (username),: Ensures that all values in the username column are unique across the table.
  • UNIQUE KEY (email): Similarly, this ensures that all email values are unique in the table.

In summary, this script creates a User table with columns for user ID, username, email, password, creation timestamp, and last login timestamp. The id column is the primary key, and both username and email are required to be unique.