Skip to content

Commit

Permalink
chore(doc): add more to column default NOT NULL and NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
BohuTANG committed Apr 6, 2022
1 parent 33b629a commit 47abcbe
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ Create a new table.
```sql
CREATE TABLE [IF NOT EXISTS] [db.]table_name
(
<col_name> <col_type> [ { DEFAULT <expr> }] [ NOT NULL | Null ],
<col_name> <col_type> [ { DEFAULT <expr> }] [ NOT NULL | Null ],
<col_name> <col_type> [ { DEFAULT <expr> }] [ NOT NULL | NULL],
<col_name> <col_type> [ { DEFAULT <expr> }] [ NOT NULL | NULL],
...
)
```

```sql
CREATE TABLE [IF NOT EXISTS] [db.]table_name
LIKE [db.]origin_table_name
Expand All @@ -26,11 +27,22 @@ AS SELECT query

## Column Option is nullable or not

By default, all columns are not nullable.
By default, **all columns are not nullable(NOT NULL)**, if you want to special a column default to `NULL`, please use:
```sql
CREATE TABLE [IF NOT EXISTS] [db.]table_name
(
<col_name> <col_type> NULL,
...
)
```

```sql
create table t1(a int NULL);
```

## Default Values
```sql
DEFAULT <expr>
DEFAULT <expression>
```
Specifies a default value inserted in the column if a value is not specified via an INSERT or CREATE TABLE AS SELECT statement.

Expand Down Expand Up @@ -97,7 +109,7 @@ mysql> SELECT * FROM copy1;
| 888 | stars |
+------+-------+

mysql> CREATE TABLE copy2(x VARCHAR null, y VARCHAR null) AS SELECT * FROM source;
mysql> CREATE TABLE copy2(x VARCHAR NULL, y VARCHAR NULL) AS SELECT * FROM source;

mysql> SELECT * FROM copy2;
+------+------+------+-------+
Expand Down

0 comments on commit 47abcbe

Please sign in to comment.