CREATE TABLE in SQL

Level 5192 keystrokes

CREATE TABLE defines a new table with columns, data types, and constraints.

SQL code

-- Create a new table named products
1CREATE TABLE products (
-- Integer key numbered automatically (1, 2, 3...); PRIMARY KEY makes it unique
2 id INT AUTO_INCREMENT PRIMARY KEY,
-- Text up to 100 characters; NOT NULL makes it required
3 name VARCHAR(100) NOT NULL,
-- Exact decimal with 10 digits, 2 after the point; 0.00 if not given
4 price DECIMAL(10,2) DEFAULT 0.00,
-- Optional text up to 50 characters (NULL allowed)
5 category VARCHAR(50),
-- Filled with the insert time when no value is given
6 created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
7);

Output

Query OK, 0 rows affected
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this SQL code and how often they appear.

  • ,× 5
  • (× 4
  • )× 4
  • _× 3
  • ;× 1
  • .× 1

More SQL examples at level 5

← SQL typing practice