How do I create mysql db table with floats and created_at (timestamp)


Problem :

I'm sure this is a simple fix but I'm not able to figure it out :( I need help creating two tables in a mysql db. This is what I was told I need to do:

make sure you have an temps table with floats and created_at (timestamp)
make sure you have an alerts table with floats for avgtemp1 and avgtemp2, open (boolean, default: true) and created_at (timestamp)

What I did in phpmyadmin:

  1. Created a mysql db named temps
  2. Created two tables, (temps, alerts)
  3. Created two columns (temp1 and temp2) in the temps table
  4. Created two columns (avgtemp1 and avgtemp2) in the alerts table

I don't understand how to add created_at (timestamp)? or what open (boolean, default: true) and created_at (timestamp)

Any help would be much appreciated



Solution :

The following will give you what you need for the timestamp column and the boolean column. The open column is just a flag that can be set to true or false, but it should default to true, in this case 1.

CREATE TABLE table1 (
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  open boolean default 1
);

Note: you only need the DEFAULT CURRENT_TIMESTAMP if you want to, otherwise you can remove that and insert a timestamp manually.


Mysql Tutorials

Mysql Howto..

How do execute a .sql script from bash

How to use mysqlimport to read in result of mysqldump --databases

how to optimise MySql function to work for concurrent users

How to swap values of two rows in MySQL without violating unique constraint?

MySQL: How to limit the results to the last 5 rows [closed]

How to store “2010-03-26 10:13:04 Etc/GMT” mysql?

How to insert two records into different tables first one with insert and then with select from the insert php mysql

How to insert data into an existing html table in php?

How to join 3 table in mysql with rule?

How to ordering name of month in MySQL & PHP?

MySQL - How to do an Oracle RANK() OVER(ORDER BY score DESC)

How to alter the auto_increment of a mysql-table using Doctrine

How to avoid multiple SQL updates using a form?

How do I properly iterate through a mysqli_fetch_array (procedural)?

How to delete all relative records in MySQL InnoDB?

How to create mysql event inside a procedure or trigger?

How To Generate A Random Decimal Value In Mysql

How to show data from database using php?

ZF2 + Doctrine - Entities - how to access related data from an Entity and do something to it?

How to define foreign key relationships in sails with mysql

When and How to use Multiple MySQL Queries with PHP (PDO)

How to backup MySQL with MySQL workbench automatically

How to calculate the day deffirence for same events

How can I modify table structure from few columns to one column?

How to update a field of a table that is inner join of another table in MySQL?

How to add Ajax on existing PHP & Mysql based pagination

how to store returning values of a stored procedure in mysql

How to use a sub query as part of a stored procedure MySQL

How to create a table with a row for each day of a given year?

Checking How Many Values in an Array are Greater than x