Skip to content

Instantly share code, notes, and snippets.

@return-none
Last active August 29, 2015 13:59
Show Gist options
  • Save return-none/10769175 to your computer and use it in GitHub Desktop.
Save return-none/10769175 to your computer and use it in GitHub Desktop.
mysql> CREATE TABLE products(
-> id INT PRIMARY KEY NOT NULL auto_increment,
-> name VARCHAR(255) NOT NULL,
-> quantity INT NOT NULL
-> );
Query OK, 0 rows affected (0.22 sec)
mysql> INSERT INTO products(name) VALUES("First product");
Query OK, 1 row affected, 1 warning (0.02 sec)
mysql> SELECT * FROM products;
+----+---------------+----------+
| id | name | quantity |
+----+---------------+----------+
| 1 | First product | 0 |
+----+---------------+----------+
1 row in set (0.00 sec)
test_sql=# CREATE TABLE products(
test_sql(# id SERIAL PRIMARY KEY,
test_sql(# name VARCHAR(255) NOT NULL,
test_sql(# quantity INT NOT NULL
test_sql(# );
CREATE TABLE
test_sql=# INSERT INTO products(name) VALUES ('First product');
ERROR: null value in column "quantity" violates not-null constraint
DETAIL: Failing row contains (1, First product, null).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment