I am trying to programmatically drop a column in a table inside of an access database and found myself unable to do so! Is it at all possible? it makes me think that i don't have any clear idea of things linq to sql can't do.
Any ideas?
There's nothing in LINQ to SQL that allows you to do that without writing T-SQL, no.
Similarly, you can't do straight updates or deletes without selecting the data you want to alter first and manipulating the objects. You'd have to write stored procedures for those things and add them to your model to be called. See this MSDN page for an overview.
Using DataContext.ExecuteQuery should also work if you don't mind T-SQL in your source code.
You can do it.
Here's an example:
ALTER TABLE Import
Alter column [Tot_Val] DECIMAL(10,2) ;
GO
Related
TRIGGERs can be used to log changes to individual DB columns as described at https://stackoverflow.com/a/779250/569976 but that technique requires you have an IF statement for each column. It's not a huge issue if you're just interested in changes to one column BUT if you're interested in changes to all columns it becomes a bit more unweildy.
I can get all the column names of a table, dynamically, by querying the INFORMATION_SCHEMA.COLUMNS table. My question is... can I use that to dynamically reference the column names? Like in the TRIGGER you'd do OLD.columnName <> NEW.columnName but I don't think you can really make a column name dynamic like that.
In PHP you could use variable variables. eg. $obj->$var. But if MySQL has anything remotely similar that'd be news to me.
Any ideas? Or am I just going to go with the old fashioned approach of writing an IF statement for each of the 100s of columns this table has?
The trigger can only reference identifiers directly. You can't use a variable or an expression to name an identifier.
That would require dynamic SQL with PREPARE and EXECUTE so you could have the statement parsed at runtime from a string, but you can't PREPARE a new statement inside a trigger, because the trigger is already executing in the context of the currently executing statement.
The simplest solution is to write a trigger that references each column directly, with as many IF statements as there are columns in the table (I wonder why you have hundreds of columns in your table; that sounds like a different problem of bad design).
The comments above mention a binary log parser. Debezium is an example of an open-source binlog parser.
MySQL also supports an audit plugin architecture, but frankly the existing implementations of audit plugins are pretty clumsy.
https://www.mysql.com/products/enterprise/audit.html
https://mariadb.com/resources/blog/introducing-the-mariadb-audit-plugin/
https://github.com/mcafee/mysql-audit
My requirement is to create a stored procedure that joins two tables and inserts it into a remote server table.
How can I solve this without using ssis and any import/export data?
please
use the search before asking your question
Be more specific, stackoverflow is not here to write your whole program, people assist you
Use punctations marks and have a look at your format
Your question
Have a look at this, it shows you how to do that. You can first add a linked server(thats the destionation in your case) and then use it for your insert statement.
Hi I'm working with sql server 2008 and I've a table with following columns
eid,empname,sal etc.. and I've 1000 stored procedures based on this table.
Now what I want to do is, I want to rename eid to empid in table. So do I need to update all 1000 stored procedures dependent on this column? Ofcourse yes, is there any shortcut method to do this? instead of open all 1000 procedures and rename it manually?
Thanks in advance
Anything that actually uses or explicitly selects the field you are changing the name of will need to be changed. There is no real shortcut around this. Why is changing the name of the field so important if it is going to cause you this much trouble?
There are tools like SQL Prompt which will auto-generate the changes for you too ("Smart rename")
Otherwise, to avoid changing all procs in one go you could create eid as a computed column but you'd need to change the write procs.
Just wondered if there was a secret to do something like Database.Security.Users like AdventureWorks DB is setup. Seems no matter what I do to try to setup "Security.Users", I always get the dbo in front of it and have a hell of a time in C# accessing the info. Am I doing something wrong?
Are you trying to create an object called Security.Users with a dot? (as opposed to Users in the Security schema?) That's probably best avoided as you're seeing, but if you are then the best way to quote the name is probably in square brackets, i.e. [Security.Users].
dbo is the default database schema name. Unless you've configured a different default schema for your users etc. you can usually just ignore it, although it's still needed if you're referencing another database by name.
you first need to create a schema and make that schema the default schema for that user. Examples and more info can be found here: http://msdn.microsoft.com/en-us/library/ms190387.aspx
If you are using the Wizard to create this, you will always get it. Write the SQL statements and you should be fine.
I have a project with a formidable data access layer using LinqtoSQL for just about anything touching our databases. I needed to build a helper class that bridges some common crud operations from CLSA objects to LinqToSql ones. Everything has been operating swimmingly until I needed to do a truncate on a table and all I had were “delete” methods.
Uh-oh. A quick search reveals that some people are using YourContext.ExecuteCommand(), which is nice and all, but I am trying to go “t-sql-less” as much as possible these days.
Is there a LINQ way to perform a truncate on a table? Or am I just clueless?
This is not possible without doing a custom T-SQL query. Doing a .Delete() and SubmitChanges afterwords would, as you probably already know, result in a DELETE statement.
Of course you could create a stored procedure that truncates the table, and then call the procedure from LINQ, but that isn't really what you're looking for I believe.
You can do something like this:
yourDataContext.ExecuteCommand("TRUNCATE TABLE YourTable");