AUTOINCREMENT not automatically adding values in Mysql Workbench IDE - mysql

I am learning to use MYSQL-Workbench for inserting data into tables
My Problem::
I have two columns one for Sl_no and one for Name
Sl_no is the primary key which has auto increment checked as shown in
snapshot-1
If you look at Snapshot-2 auto_increment is not automatically
incremented when i keep adding the values
should i need to enable any option for this ?
Because Using the IDE should automatically add values(Since Sl_NO has
autoincrement enabled) but it is not doing so
I have to manually add it one after another
Snapshot-1
Snapshot-2
How can i resolve this ?
{EDIT}
I am using Windows-7 OS
As you can see i am clicking the marked area in the pic to apply
changes, but nothing is happening.
Should i need to enable any settings

UPDATE: It wasn't apparent right away that you're doing this from model and not directly in your db table.
To create your schema from model you need to do Forward Engineering and in the dialog choose Generate INSERT Statements for Tables.
Then go to the object browser in your MySQL connection, not your model. Fire select statement in query window or choose from context menu Select Rows - LIMIT 1000 and you'll see that your sl_no column is populated as expected.
BTW both mac and windows interfaces are identical.
Original answer:
You forgot to commit your changes by clicking Apply
And after reviewing the change script click Apply again.
After that you'll see your auto_increment column values populated

Related

Trying to track changes in my MS Access Database

I have a table set up to track when people place an order (Order_Tbl). I duplicated the table that I call my order_change_log and added a date/time field (default value set to now). I have a one to many relationship between the orderID and order_change_logID. The idea is that before update, I want the existing data to be inserted into the change log table. I went into the before update field and made the following statement:
CurrentDB.Execute “INSERT into Order_Change_Log SELECT * FROM Order_Tbl WHERE ChangeLog_ID =“”” & Me.ID & “”””
I keep getting “Invalid Outside Procedure” and I’m getting frustrated… Not sure what I’m doing wrong.
What you want to do is called a trigger. In access a table's triggers can be accessed and created from the table's design mode via [Create Data Macros] on the ribbon. You are pretty much forced to use the macro language to create the trigger.
As an aside it looks like you are setting the default date in Order_Change_Log. Leave that default blank as it is not needed here and in many other cases leads to bugs.
In this case we will be using the after-update macro. The Before-Update values are available using [Old]
For an older example of a trigger happening after Delete see MS Access trigger?
Example Table and Relationships:
After Update Trigger Macro:
Use the ribbon to save the macro and you are done. change some values in the Order_Tbl then refresh or open the Order_Change_Log table to see the results

Rows keep showing #DELETED

Everytime I enter data into one of the SQL linked tables, some of the rows keep saying #deleted no matter what I do. The data is fine in the actual SQL server but not within Access. I never have used Access before so I have no idea what I'm doing. Please use the most non-tech savy dialog as possible... This is all so new to me and I am not good with technology at all.
I have tried refreshing the tables by going to the "Linked Table Manager" thing but that hasn't helped. I tried completely deleting the data from both Access and the SQL Server, re-entering it into the SQL server, and creating a new linked table within Access. I have tried exporting the data into Excel from the server and importing it into Access. None of it has worked. It's only the first 10 rows of data though... The rest of the table is completely fine and all the data has similar structure so I don't know why only the first 10 rows are being affected.
Ok, there are 3 things that often cause this.
1 - Make sure the sql table has a PK column. This is often (useally) a autonumber (incrementing by 1 integer column). So when you create the column in sql server, set it as primry key (a button in the menu can be hit to set PK using the sql manager). Then change in the property sheet the column to identify "yes" and it will set the starting number (1) and the increment (1) for you. Now add the other columns.
So Access needs a PK column.
If above was not your issue, then next up that is common is if you have a "bit" column in sql eerver. These can't be null, or access goes crazy. so if you have a bit column, then MAKE sure you set the default for that in the sql table designer as (0).
If the above don't fix your issue? Then number 3 on the list is to add what is called a row version column to the sql table. Simply add a timestamp column (this is NOT a date column, but is a time stamp row).
In ALL of the above cases, after you make the change to the sql server table, you have to re-link the access table. It is sufficient to right click on the table in Access, choose linked table manager, and then check box the table in queston, and hit ok. The link will be refreshed for you.
So the above are the 3 main issues. In most cases, the PK is the issue. However, if the table on SQL also has a trigger (that inserts) to other tables, then that table trigger has to be changed - but lets take this 1 step and soluion at a time.
As a general rule, Access needs a PK column when working with sql server. If you have that, then check the null "bit" issue - sql server tables need a default setting of 0 for those columns, and if they are null, then Access don't like that.
If both above issues are NOT your issue, then adding a column of timestamp to the sql table will fix this.

MySQL Workbench auto increment disabled

I am using Workbench version 6.3.5 Community and this is GUI question only.
When creating a new table auto increment check-box is disabled.
Is it a bug or I need to enable this some how in options?
And how to set start value and step for auto increment in GUI when creating a table?
You need to set auto increment in table
As a work around, when you click the 'Apply' button and are presented with the generated script to review, you can actually edit that script. I ran into the issue you posted as well and just manually added AUTO_INCREMENT to the column definition I needed it applied to.
You can do it this way
Halil Saltik
Just check the AI(Auto Increment) checkbox. No work around, that's why it's a workbench. Life made easy
Make sure the datatype is INT, not character based.
If you are like me, and you are wondering how on earth to get to that primary-key, auto-increment checkbox etc:
Hover over the table name, in my example "persons"
A "spanner like icon" will appear
Click on it and that's it!
I am using MySQL Workbench 8.0 CE(v8.0.19)
The field must be both datatype int and the primary key for the table.

What does "ADD AUTO_INCREMENT value" mean in phpMyAdmin

In phpMyAdmin, I wanted to copy a database to another name so I would effectively have 2 databases exactly the same. One as my oringinal and another for testing on the staging website site that I have.
There are three main options
structure only
structure and data
data only,
I need structure and data, however there are more checkbox options below;
CREATE DATABASE before copying //was checked by default
Add DROP TABLE / DROP VIEW
Add AUTO_INCREMENT value //was checked by default
Add constraints
Switch to copied database
What does "ADD AUTO_INCREMENT value" and "Add constraints" mean and if I copy structure and data doesnt any fields with AI get copied?
When you export / import a database including structure and data, phpmyadmin restores it in the same state as it was. The same applies when you copy the database.
Add AUTO_INCREMENT value simply set the auto_increment value correctly so you can correctly use the restored database. This is necessary in case phpmyadmin does some kind of bulk insert where the auto_increment is not incremented on each insert.
This is also needed to set the correct value, as you can insert then delete some data in your table, so in order to keep the data consistency you have to keep not only the exact ID but also not use an ID which had been used by an old row.
The Add constraints does exactly what it means, i.e. it restores all the constraints on the table in your database. This is also required if you want a complet dump.
For what you are trying to do, maybe a database replication would be better.
You can find information on replication here and here.
If the "Add AUTO_INCREMENT value" and "Add constraints" checkboxes are checked, the new table should have the same next autoindex and constraints like the copied table. All the fields with AI get filled
"Add AUTO_INCREMENT" is keep doing auto increment in new copied database. if we unchecked then it will stop auto increment from that fields. so, if we want maintain auto increment into new database as well then keep checked "Add AUTO_INCREMENT"

Merge tables without overwriting existing ones in mysql phpmyadmin

I was having a "coming soon" page with a sign up form. Since a couple of weeks I've switched to another web hosting and continue working on my new site at my new host, but continued to let the visitors sign up at my old host.
Now my have pointed my domain to my new hosting and want to export all new subscribers and import them into the new DB. Some rows might use same ID.
How can I easily export and merge a table from the old DB to the new one? Please note I don't wan't it to overwrite any row that has the same ID, if it does, I want it to add a new row instead.
I've tried exporting my table "wp_csp3_subscribers" from my old DB and imported it in my new one. But get an error saying ID already exists.
If you're using phpMyAdming (based on your tags), you can expand the export options by selecting "Custom - display all possible options" instead of the default "Quick - display only the minimal options".
Under the data dump options, choose "INSERT IGNORE statements", which will tell mySQL to ignore any errors with duplicate primary keys.
Taken from the mySQL documentation on the IGNORE option:
For example, without IGNORE, a row that duplicates an existing UNIQUE index or PRIMARY KEY value in the table causes a duplicate-key error and the statement is aborted. With IGNORE, the row still is not inserted, but no error is issued.
Hope this answers your question.
also, if you have two sql files from a dump, insert one normally, maybe with Enable foreign key checks unchecked, then your second file would like to concatenate the data, remove the DROP TABLE IF EXISTS and CREATE TABLE lines in that second file. Leave only the LOCK TABLES table WRITE; and inserts