I have to add a new column to one of the existing DB2 tables. If I do so, do I need to recompile all the stored procedures accessing that table? What happens if I don't do that?
Documentation is pretty clear on that:
Adding a column to a table will result in invalidation of all packages with INSERT usage on the altered table. If the added column is the first user-defined structured type column in the table, packages with DELETE usage on the altered table will also be invalidated.
If the new column has a constraint on it, packages with other uses of the table may be invalidated as well.
Invalid packages will be automatically revalidated on their next use. In other words, you don't need to do anything.
Related
I have seven tables that contain hundreds of rows of related data. These tables build up quite a complex quoting tool that adds materials and costs etc.
Is it possible using EF Core and a couple of lines of code to load up all those entities, and then write them back as new ones but generating new ID's on the way and correctly relating everything to each other so I end up with complete copies of all the data. I can then change the CompanyID on the Header table and voila, a company has a complete copy of templates that they can now configure themselves.
I am about to write a procedure to load up entities one by one, loop over them, save rows one by one etc, store the id's, blah blah blah. I'm happy to write that procedure because I cannot see an automatic way to do it.
Only way I can think of to do it with EF Core. Since it does not support tampering with the primary keys you could try something like this if you dont want to create a procedure but I can see a way to perform cascade update on primary keys. This kind of code would allow you to change the primary keys using custom ids based on your needs. You will still need for loops. So yeah you first update the primary table and the below it the tables that are depending on it.
foreach(var row in your_entity){
your_context.your_new_entity.AddObject(row);
your_context.SaveChanges();
row.Id = your_id;
for(var row2 in your_depending_entity){
row2.foreignkey = your_id
.... // and so on
}
}
My app is in production and I want to manage user data when user updates the app without loss of their data, how can I achieve this with sqflite. Explicitly I want to add a column and delete another.
You can probably add a column using raw sql, but sqlite (and thus sqflite) doesn't support dropping a column. For that you would need to do the following:
increase the database version number
in onUpgrade copy the old database columns to a temporary table
delete the original table
create a new table using the original table name but with the right schema
copy the data from the temp table
delete the temp table
Sorry, this isn't a full answer, but it is the direction I would go if I were in your situation.
I have the same problem and found this article which seems to be a good solution.
I am trying to delete column last_name from Persons using FMDB,
let query = "ALTER TABLE Persons DROP COLUMN last_name;"
try FMDBHelper.database.executeUpdate(query, values: nil)
But comes with error
DB Error: 1 "near "DROP": syntax error".
sqlite does not support DROP COLUMN in ALTER TABLE.
You can only rename tables and add columns.
If you need to remove columns, create a new table, copy the data there, drop the old table and rename the table to its intented name.
Reference: http://www.sqlite.org/lang_altertable.html
Please note that I flagged that your question could be duplicated, I will provide an answer to make it more clear.
I think that you are missing a point, which is: The FMDB is (as mentioned in their repo description):
This is an Objective-C wrapper around SQLite
Keep in mind that since FMDB is built on top of SQLite, it is not a limitation from the library itself; it is related to how SQLite ALTER TABLE works.
The SQLite ALTER TABLE statement is limited to rename a table and add a new column to the desired table:
SQLite supports a limited subset of ALTER TABLE. The ALTER TABLE
command in SQLite allows the user to rename a table or to add a new
column to an existing table.
http://www.sqlite.org/lang_altertable.html
For achieving what are you looking for:
You could check the answers of Delete column from SQLite table.
I have a stored procedure on my HANA database where I need to join two tables from different schemas. These schemas are named differently in the development, staging and production system.
The obvious solution in this situation would be to use Schema-Mapping. But unfortunately schema-mapping only seems to work for the default schema of a stored procedure. When trying to reference an authoring schema in a stored procedure (ex. JOIN "AUTHORING_SCHEMA"."SOME_TABLE" ON ...) you get the error message "invalid schema name". So it seems like I can only use schema-mapping for one of the tables but not for both.
I know I can read the schema mappings in my stored procedure by querying the table "_SYS_BI"."M_SCHEMA_MAPPING", but I can't find out how to query from a schema when I have the schema name in a variable.
I would give it a try to work around this limitation by defining two synonyms using .hdbsynonym
For details on how to create design time synonyms using .hdbsynonym check https://help.sap.com/saphelp_hanaplatform/helpdata/en/52/78b5979128444cb6fffe0f8c2bf1e3/content.htm and https://help.sap.com/saphelp_hanaplatform/helpdata/en/4c/94a9b68b434d26af6d878e5f51b2aa/content.htm
There you can also find a description on how schema mapping works with hdbsynonym.
For details on synonyms in general see https://blogs.sap.com/2016/12/05/using-synonyms-in-sap-hana/
I solved this with a workaround which I am not entirely happy about, but which works for now.
I created a second stored procedure with the second schema as default schema. This procedure does nothing but SELECTing the contents of the second database table.
The first stored procedure calls the second one to load the data into a local table variable and then performs a JOIN between the first database table and the table variable.
This works reasonably well because the second table is rather small (16 rows at the moment, unlikely to grow beyond 100). But I wouldn't want to do it with a larger table.
Using Code First EF6, the database table already includes a column that the Entity does not (I previously only accessed it as a navigation property). Now in order to hopefully speed up performance, I want to add the other, existing column so I can use in in my predicates. Do I need to worry about using migrations?
Yes and no. You don't need to use migrations to create the column, obviously; however, EF may still see it as a mismatch between the model and the DB, because it bases its knowledge off of what's in the __MigrationHistory table. Try scaffolding the migration, and if it wants to add the column, call Update-Database -Script, then execute just the INSERT INTO __MigrationHistory part in order to convince EF that your DB is up to date.