MySQL Timestamping - mysql

I have a table in an Amazon Web Service (AWS) Relation Database Service (RDS) and the table columns are "Memory", "Cores", "Speed" and "Insert_Timestamp" and I am trying to get the database to log each time a new row is added to this table. With this being said, I am running the following code Alter table Instace_Types ALTER COLUMN Insert_Timestamp SET DEFAULT CURRENT_TIMESTAMP. I am running into this error:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'COLUMN Insert_Timestamp SET DEFAULT CURRENT_TIMESTAMP' at line 1"
any input would be greatly appreciated.

The second ALTER should be a CHANGE.
Alter table Instance_Types
CHANGE Insert_Timestamp
Insert_Timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP

Related

MySQL vs MariaDB - ddl - setting default for time field

I've got table products, and want to add column with type time.
I've got statement as follows:
ALTER TABLE products ADD openTime1 TIME DEFAULT TIME(now());
it works on MariaDB, but it doesnt work on Mysql.
On mysql it produces Error -
[42000][1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(now())' at line 1
Can someone tell me why? whats wrong here? I thought that this should be the same.
In MySQL the expression used in DEFAULT field attribute must be wrapped into the parenthesis:
ALTER TABLE products ADD openTime1 TIME DEFAULT (TIME(now()));
db<>fiddle here

Problem with making a database on base of EER

I want to make a database based on my EER, but if I use Forward Engineering it always throws the same error.
Executing SQL script in server:
> ERROR: Error 1064: You have an error in your SQL syntax; check the
> manual that corresponds to your MariaDB server version for the right
> syntax to use near ') ENGINE = InnoDB' at line 8
SQL Code:
-- Table `gip`.`Groepen`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `gip`.`Groepen` (
`idGroepen` INT NOT NULL,
`Groepnaam` VARCHAR(45) NOT NULL,
PRIMARY KEY (`idGroepen`),
UNIQUE INDEX `Groepnaam_UNIQUE` (`Groepnaam` ASC) VISIBLE)
ENGINE = InnoDB
SQL script execution finished: statements: 6 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
Any idea how to fix this?
I think VISIBLE is added after MySQL server version > 8.0 and you are using less than that.
Moreover, according to https://bugs.mysql.com/bug.php?id=92269, VISIBLE is default value. You can remove it.

MySQLWorkbench forward engineering error

I'm working on a model in MySql Workbench 8.0, when I click on forward engineering and try to generate the script of my model I get
Executing SQL script in server
ERROR: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VISIBLE,
CONSTRAINT `fk_Compras_Personas`
FOREIGN KEY (`persona_id`)
R' at line 9
SQL Code:
-- -----------------------------------------------------
-- Table `bd_inventario2018_2`.`compras`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `bd_inventario2018_2`.`compras` (
`nmcompra` INT(11) NOT NULL,
`persona_id` INT(11) NOT NULL,
`fecompra` DATE NOT NULL,
PRIMARY KEY (`nmcompra`, `persona_id`),
INDEX `fk_Compras_Personas_idx` (`persona_id` ASC) VISIBLE,
CONSTRAINT `fk_Compras_Personas`
FOREIGN KEY (`persona_id`)
REFERENCES `bd_inventario2018_2`.`personas` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
SQL script execution finished: statements: 6 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
Or when i try to syncronize the model I get
Executing SQL script in server
ERROR: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VISIBLE' at line 4
SQL Code:
ALTER TABLE `bd_inventario2018_2`.`productos`
ADD COLUMN `anchetas_id` INT(11) NOT NULL AFTER `psventa`,
ADD COLUMN `productoscol` VARCHAR(45) NOT NULL AFTER `anchetas_id`,
ADD INDEX `fk_productos_Anchetas1_idx` (`anchetas_id` ASC) VISIBLE
SQL script execution finished: statements: 3 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
Someone knows what's happening? This is an automatic process, I'm not overwritting anything,
Thanks
MySQL Workbench is generating the script for MySQL 8 (which supports the new invisible indexes), which you likely do not have.
You need to specify the MySQL version you are using, either in Model\Model Options\MySQL\Target MySQL Version or, globally, in Edit\Preferences\Modelling\MySQL\Target MySQL Version.
Alternatively, you can go on the MySQL Workbench GUI, Edit->Preferences then Modeling->Mysql and change the default target MySQL.
I had the same problem, using version = 8.0.17.
The error originates when a relationship is formed if No action is selected in the "Foreign Key Options" section. Ensure that the Skip in SQL generation is checked (When No action is selected).
This should solve the problem!

MySQL Generated Columns of date type

i use mysql version 5.7
i have a field devicetime which is a datetime field.
for some reason i want to add a generated column which stores only the date part of the devicetime field.
i have tried the following statement
alter table mytable
add COLUMN recorddate date generated always as date(devicetime) stored;
i get an error
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'date(devicetime) stored' at line 2
i have taken the inputs from MySQL documentation from this link.
my current table structure is like this
For whatever reason MySQL needs some ()'s around the expression:
ALTER TABLE `mytable `
ADD COLUMN `recorddate` DATE GENERATED ALWAYS AS (date(devicetime)) STORED;
One solution came into my mind is,you can store TIMESTAMP into table.
And when try to get anywhere in your SYSTEM you can use DATE_FORMAT() and STR_TO_DATE() function to whatever part you required from that actual data.

How to rename table and change storage type in MySQL?

I first create a table which is set to store data in MyISAM engine. Later this table would be replaced with new table, but I still whant to keep this table and just rename it and change her engine type to "archive". I have try this:
ALTER TABLE myTable RENAME TO myTable-[DATE] ENGINE=archive;
Error which I get is: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ENGINE=archive' at line 1 (1064) (SQLExecDirectW)")"
So how to in mysql rename and convert table from MyISAM to ARCHIVE engine?
Tnx for help
Kindly try this:
ALTER TABLE `test1` RENAME TO `myTable-[18-Aug-2015]`, ENGINE=archive;
Pass the new name as a string as well. Make sure to also include a comma ( , ) between the alterations that you require.