Update the size of a column in SQL Server without affecting statistics - sql-server-2008

I'm confused and the truth is I don't know what else to do, I have a database column that has a datatype numeric(8, 4) and I need to change it to numeric(12, 2).
When I want to update it, it tells me a message that the change cannot be applied, because it has associated statistics indexes and it shows me a referenced text to which statistics it would affect.
My question is: how can I update the column without affecting the statistics or what actions should I take to proceed to update the column from the database?
SQL Server 2008

Thank you very much, I had to delete the index, apply the change, and then recreate it, I had no other option

Related

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.

how to know the date of insertion of record in SQL

I am using phpMyAdmin for my project and I have a table without date/datetime field.
I am wondering if there's a way to know when I inserted each record on the database
While designing your database if you forgot to keep an extra field to store the insertion time of a row then you have only one option left to know the the insertion time.
But the condition is you must have binary logging enabled prior to it.
Reference
You may check if binary logging is enabled in your part by executing this query :
SHOW VARIABLES LIKE 'log_bin';
Further Note:
And from now on you may keep an extra field which will track the insertion time of each row.
Change your table design :
Add an extra field in your table with datatype "timestamp/datetime" with default value CURRENT_TIMESTAMP and on update CURRENT_TIMESTAMP.

extra column in MySQL, can I drop it?

I have a database I'm creating and I made a 1 to 1 connection with another table in Mysql, below is a screen shot. My question is can I drop the extra column (assembly factory_id) that was created when I made the connection? I only want the single (factory_id) will this mess up the connection that I made? Should i drop the (factory_id) and let the connection stay?
I'm a noob, thanks!
I am assuming that your comment "but should i drop the table?" really meant to say "but should i drop the column?".
Short answer: if it is safe, you should delete the column - there's no reason to keep it cluttering up the database and the minds of future developers.
Long answer: how to determine if it's safe: If 1) the value in factory_id IS and ALWAYS WILL BE identical to assembly factory_id, eg, they are a duplicate value of each other, and 2) no other tables or program code refer to assembly factory_id, you can safely delete assembly factory_id.
However, if there's any chance that they ever mean different things (not just the sample of 20 or so rows), you can't delete it. See fiddle: http://sqlfiddle.com/#!9/0bf17/1
If they are always the same, but parts of the database or the code refer to assembly factory_id, you can refactor those database or code parts to refer to factory_id instead and THEN delete assembly factory_id.
When doing something like this, you should make tests to verify that the state of queries and programs after the change is the same as the state before the change.
You can drop the extra column by using the Alter statement.
ALTER TABLE table_name DROP COLUMN factory_id;
You can also refer to http://docs.oracle.com/cd/E18283_01/server.112/e17118/statements_3001.htm#i2103683
(Drop column clause in particular)
Edit:
As far as the connection is concerned, the Alter statement dumps to a temporary table and then rebuilds without losing any connection. Please refer to the section Storage, Performance, and Concurrency Considerations in this document

MySQL/Percona 5.6: INSERT INTO a table after a table is ALTERed

I have recently installed a new computer with Percona Server 5.6 instead of MySQL 5.6, and using InnoDB/XtraDB mostly, FWIW. The database I'm working on is merely a testing ground, but I have 1 issue: after I add a column to a table (or even remove one), I usually forget to INSERT or otherwise change another table's data, which keeps track of what column names are in which table; each table has ASCII name along with a number, and this number is the only difference between table names for simplicity. So, is there a way to auto-update the "relation" table so that the column name and table's number are added or changed, instead of using a cronjob ?
Now that I think, I could DROP that table and use information_schema instead ...
EDIT 0: Don't let the above realization stop you; it's just good to know if this is possible before going for a possible other way.
Yes, relying on the 'INFORMATION_SCHEMA.COLUMNS' may be best.
Unfortunately mysql does not support DDL TRIGGER events, as this would be what you are looking for.
triggers allow you to perform many SQL and procedural operations before insertion, update or deletion of rows in a specific table. However to the best of my knowledge - and I would be stoked if I were wrong - you cant set TRIGGER events on DDL statements like ALTER and DROP TABLE...
However still take the time to learn about triggers - they save a lot of time by eliminating the need for cronjobs and external updates for things like aggregate values.
https://dev.mysql.com/doc/refman/5.6/en/trigger-syntax.html

Using MySQL triggers to update table with last_modified data

How can I use trigger to simply update a table with the last time a table was edited? I know that by using triggers it is "for each row" but if someone's inserting more than one row, it'd be pointlessly inserting or altering the table over and over again. Is there any way to do this without doing it over and over again?
I'd like to be able to just have it do it once for all of the inserts instead of having it done time and time again. If not I guess I can force it, via a wrapper.
edit 1:
Well to explain some more of the design I guess then.
I'm going to be having a table in another database to handle the last_updated data for things like chat, or the players "mailbox", and another one for the development things like tables for quests, skills, items etc. And I want to be able to know when a table was last updated so that I can easily see before I go scan the table to see for new things.
Basically this is what I'd like to do(or something similar), I'm also using PHP so it's likely to be PHP-based approach in the code but the SQL should be kind of standard. I'm not going to do full code but rather semi-runnable.
last_modified=mysql_query("select last_modified from various_stats.table_last_updated where database_name=`database_name` and `table_name`");
if(last_modified>last_checked_time){
data_to_get_updated=mysql_query("select something from various_<something>.table_name where last_modified>last_checked_time");
}
else{
do_nothing;
}
edit 2: I'm using InnoDB, and thus I cannot use the information schema's update_time since it never changes.
will this help you, if im on the right track that is:
SELECT UPDATE_TIME
FROM information_schema.tables
WHERE TABLE_SCHEMA = 'dbname'
AND TABLE_NAME = 'tabname'
The above solution is for myisam, for innodb the norm is to set a sceduled script, this can be set as a cron job or a windows scheduled task, if you dont have that kind of control over your web host, you could possibly set up a small server at your work office and run the cron from there. if you do this every say 20 seconds you could simply record the current top auto incremented ID and use this as a guid, if current ID is higher than the last recorded ID you then update your records to show the last changed time to be now.
as this will only be one call to a server every XX seconds, it wont really hammer the server too much and should just run silently in the background.
If you do go down the scheduled task root, it would be wise to add error capture in your script so that you can be alerted via email if something stops working etc.