Setting a column as timestamp in MySql workbench?

ocean800

This might be a really elementary question, but I've never created a table with TIMESTAMP() before, and I'm confused on what to put as the parameters. For example, here:

enter image description here

I just randomly put TIMESTAMP(20), but what does the 20 as a parameter signify here? What should be put in here?

I googled the question, but didn't really come up with anything so... Anyway I'm new to sql, so any help would be greatly appreciated, thank you!!

spencer7593

EDIT

As of MySQL 5.6.4, datatype TIMESTAMP(n) specifies n (0 up to 6) decimal digits of precision for fractional seconds.

Before MySQL 5.6, MySQL did not support fractional seconds stored as part of a TIMESTAMP datatype.

Reference: https://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html


We don't need to specify a length modifier on a TIMESTAMP. We can just specify TIMESTAMP by itself.

But be aware that the first TIMESTAMP column defined in the table is subject to automatic initialization and update. For example:

create table foo (id int, ts timestamp, val varchar(2));

show create table foo; 

CREATE TABLE `foo` (
`id` INT(11) DEFAULT NULL,
`ts` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`val` VARCHAR(2) DEFAULT NULL
) 

What goes in parens following a datatype depends on what the datatype is, but for some datatypes, it's a length modifier.

For some datatypes, the length modifier affects the maximum length of values that can be stored. For example, VARCHAR(20) allows up to 20 characters to be stored. And DECIMAL(10,6) allows for numeric values with four digits before the decimal point and six after, and effective range of -9999.999999 to 9999.999999.

For other types, the length modifier it doesn't affect the range of values that can be stored. For example, INT(4) and INT(10) are both integer, and both can store the full range of values for allowed for the integer datatype.

What that length modifier does in that case is just informational. It essentially specifies a recommended display width. A client can make use of that to determine how much space to reserve on a row for displaying values from the column. A client doesn't have to do that, but that information is available.

EDIT

A length modifier is no longer accepted for the TIMESTAMP datatype. (If you are running a really old version of MySQL and it's accepted, it will be ignored.)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Setting Php and Mysql timestamp

From Dev

Update MySQL Column Timestamp

From Dev

setting up MySQL Workbench with MAMP - missing 'mysql.sock' file

From Dev

Rails: setting column default to created_at timestamp

From Dev

Column Input Greyed out in MySQL Workbench

From Dev

mysql workbench, replace column from file

From Dev

MySQL Workbench edit column without pk

From Dev

SQLAlchemy MySQL Timestamp column value

From Dev

MySQL TIMESTAMP Column - Group by Day

From Dev

Update mysql id column according to timestamp column

From Dev

Setting index in MySql on a Varchar Column

From Dev

What do the mysql workbench column icons mean in ER Diagram?

From Dev

how to change (Update) column name in table using MySQL workbench?

From Dev

What does the column flag "G" in MySQL Workbench mean

From Dev

Column Name requirement while importing csv into mysql workbench

From Dev

Source Column not properly being identified on CSV file import in MySQL Workbench

From Dev

MYSQL, Create a new Query for a Column with Decimal (M,D) in the workbench

From Dev

Set default value of a timestamp column to a sum of 2 timestamp in mySQL?

From Dev

Set default value of a timestamp column to a sum of 2 timestamp in mySQL?

From Dev

How to save integer in MySQL timestamp column in Wordpress?

From Dev

MySQL column 'not null default current_timestamp'

From Dev

MYSQL Summing Fields within a column for given Timestamp

From Dev

MySql TIMESTAMP column is auto updated. Why?

From Dev

updating column with UNIX_TIMESTAMP() in mysql query

From Dev

How to save integer in MySQL timestamp column in Wordpress?

From Dev

Setting default collation method in MySQL Workbench doesn't change the collation method

From Dev

Setting default collation method in MySQL Workbench doesn't change the collation method

From Dev

MySQL Workbench Export Privileges

From Dev

mysql Workbench insert default

Related Related

  1. 1

    Setting Php and Mysql timestamp

  2. 2

    Update MySQL Column Timestamp

  3. 3

    setting up MySQL Workbench with MAMP - missing 'mysql.sock' file

  4. 4

    Rails: setting column default to created_at timestamp

  5. 5

    Column Input Greyed out in MySQL Workbench

  6. 6

    mysql workbench, replace column from file

  7. 7

    MySQL Workbench edit column without pk

  8. 8

    SQLAlchemy MySQL Timestamp column value

  9. 9

    MySQL TIMESTAMP Column - Group by Day

  10. 10

    Update mysql id column according to timestamp column

  11. 11

    Setting index in MySql on a Varchar Column

  12. 12

    What do the mysql workbench column icons mean in ER Diagram?

  13. 13

    how to change (Update) column name in table using MySQL workbench?

  14. 14

    What does the column flag "G" in MySQL Workbench mean

  15. 15

    Column Name requirement while importing csv into mysql workbench

  16. 16

    Source Column not properly being identified on CSV file import in MySQL Workbench

  17. 17

    MYSQL, Create a new Query for a Column with Decimal (M,D) in the workbench

  18. 18

    Set default value of a timestamp column to a sum of 2 timestamp in mySQL?

  19. 19

    Set default value of a timestamp column to a sum of 2 timestamp in mySQL?

  20. 20

    How to save integer in MySQL timestamp column in Wordpress?

  21. 21

    MySQL column 'not null default current_timestamp'

  22. 22

    MYSQL Summing Fields within a column for given Timestamp

  23. 23

    MySql TIMESTAMP column is auto updated. Why?

  24. 24

    updating column with UNIX_TIMESTAMP() in mysql query

  25. 25

    How to save integer in MySQL timestamp column in Wordpress?

  26. 26

    Setting default collation method in MySQL Workbench doesn't change the collation method

  27. 27

    Setting default collation method in MySQL Workbench doesn't change the collation method

  28. 28

    MySQL Workbench Export Privileges

  29. 29

    mysql Workbench insert default

HotTag

Archive