How to use SQL Server apply in typeorm - sql-server

For a project I'm assigned to I have to alter a typeorm querybuilder to incorporate an "outer apply".
I could not find any support in typeorm for this.
I've looked for ways to do this by a join and a sub-query in the "on" of the join but the amount off data in the DB generates a timeout using multiple sub-queries.
Furthermore, I looked into inserting a RAW query into the builder but could not find the mechanism for this.
Is there any way to use "apply" with typeorm?
I personally prefer to write all my queries by hand so if you come up with reasons NOT to use typeorm, I agree!! But this is an existing project and no way I'm going to rewrite it!

Related

How we can perform CRUD and Join operations using C/AL in NAV 2016?

Currently I am working on NAV 2016. I came across some C/AL functions to Insert, Delete, Modify data from the table after retrieving them statically.
I want to know is there any use of SQL statement in C/AL to perform CRUD and join operations or we have to rely on C/AL inbuilt functions only?
Only c/al.
No join.
Fo read operations you can use Query object. It’s highly limited version of the SQL’s query. But it can do join.

Python - extracting a SQL Server database schema to a file

Often I need to extract the complete schema of an existing SQL Server DB to a file. I need to cover every object -- tables, views, functions, SPs, UDDTs, triggers, etc. The purpose is so that I can then use a file-diff utility to compare that schema to a baseline reference.
Normally I use Enterprise Manager or Management Studio to script out the DB objects and then concatenate those files to make one big file in a consistent predictable order. I was wondering whether there's a way to accomplish this task in Python? Obviously it'd take an additional package, but having looked at a few (pyodbc, SQLAlchemy, SQLObject), none of them seem really suited to this use case.
If you can connect to SQL Server and run queries in Python then yes – it’s possible but it will take a lot of effort and testing to get it to work correctly.
Idea is to use system tables to get details about each object and then generate DDL statements based on this. Some if not all DDL statements already exist in sys.syscomments table.
Start off by executing and examining this in SSMS before you start working in Python.
select *
from sys.tables
select *
from sys.all_columns
select *
from sys.views
select *
from sys.syscomments
All system tables documentation from MSDN.
I've used this PowerShell strategy in the past. Obviously, that isn't Python, but it is a script you can write then execute from within Python. Give this article a read as it may be your easiest (and cheapest) solution: http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/04/use-powershell-to-script-sql-database-objects.aspx
As a disclaimer, I was only exporting stored procedures, not every single object.

SQL Client with inner join exploration

I have a database which I sometime like to manually explore, in order to get info.
I currently use squirrel sql client, which is quite good, but there's a feature I miss badly : when I issue a simple select to a table, let's say there's a line I want to know references.
For that purpose, I need to manually write big sql request with inner joins, which can be quite daunting...
So my question : is there any (possibly free) SQL Client that just lets you explore the possible inner joins?
For example, a click on the line id would give me all the lines from other tables referencing it, just as simply as an hypertext link would do...
Try DBeauty:
"A relationship-oriented Database Browser.
Provides insight into both the data and the interrelation of the rows."

How to execute dynamic .net code in clr stored procedure in SQL Server

Is there a way to change the code of CLR procedure in SQL Server dynamically?
Suppose you have an assembly with your business logic deployed in MS SQL Server 2008 R2. This assembly (or assemblies) is being used constantly (for example calling some functions for each row of a table in multiple concurrent queries). So you cannot just drop assembly. Is there a way to change my business logic dynamicly or some way to execute external changable code?
I've already explored these approaches, but none worked:
Reflection.Emit
Mono.Cecil
Loading external assembly in the assembly deployed in SQL Server
UPDATE:
The question was not about release process: I want to be able to set some security rules dynamically via GUI.
For instance some users should be able to see only clients without their addresses or the transactions within the last year and so on.
The rules are not complicated but they may change almost every day and we cannot put them in the code. The rest of the business logic is implemented in TSQL. CLR was chosen because of the performance issue (dynamic SQL is too slow).
There was another option: generate clustered views (with rules in WHERE section) but it was not quick enough.
Some more details:
Suppose we have some code selecting a part of big table dbo.Transactions
select *
from dbo.Transactions
where ... --filters from your business logic
If we want to filter the result to show allowed rows we could generate some indexed view and join it with the result set like this:
select *
from dbo.Transactions t
inner join dbo.vw_Transactions v
on t.id = v.id
where ... --filters from your business logic
But if we check the execution plan in most cases the query analyzer decides not to filter dbo.Transaction and then join with vw_Transactions, but to join first and filter later (which is absolutely not desirable). Hints like FORCE ORDER doesn't help.
I'm not a CLR assembly expert, but the obvious options are:
ALTER ASSEMBLY
Drop and re-create the assembly inside a transaction
Define a maintenance window and deploy it then
gbn's point about release processes is a good one. If your procedures (and therefore your business operations) are really constantly running 24x7 then presumably you already have some form of system redundancy and established maintenance procedures for patching and upgrading applications? If so, just deploy your new code in your usual maintenance window.
There's a good library for dynamic evaluating arithmetic expression (with parameters) - Flee
In my case I didn't have to execute any .Net code - just the expressions like "Date > '20100101' Or Status = 2", so Flee satisfies almost completely. The only issue is that its logical operators don't work with SqlBoolean type (which is used in sql expressions) but it's not a big deal to add this feature.
But in general case it's seems to be impossible to execute dynamic .Net code inside Sql Server host.

Which is faster for SSIS, a View on a table or a Conditional Split?

I have an SSIS project where one of the steps involves populating a SQL Server table from an Oracle Table.
The Oracle table has a column ssis_control_flag. I want to pull across all records that have this field set to 'T'.
Now, I was wondering which would be the best way of doing this, and the two options as I have detailed in the question presented themselves.
So really, I am wondering which would be faster/better. Should I create a conditional split in the SSIS package that filters off all the records I want? Or should I create a view in Oracle that selects the records based on the criteria, and utilise that view as the data source in SSIS?
Or is there an even better way of doing this? You help would be much appreciated!
Thanks
Why don't you use a WHERE clause to filter the records, instead of creating a view? May be I am not getting your question correctly.
Then in general, bringing all the data to SSIS and then filtering out is not recommended. Especially when you can do the filtering at the source DB end itself. Consider the network bandwidth costs as well.
Then this particular filter that you are talking about here, cannot be done with a better efficiency in SSIS than that can be done at DB. Hence better do it in the Oracle DB itself.
You can use a query using openrowset as the source for the dataflow instead of directly accessing the Oracle table.

Resources