Skip to content

drop trigger if exists and create

I would like to check if the trigger exists on [tbl] and create another one. I tried it this way but didn’t work. What am I doing wrong? Answer The [name] field in sys.objects will contain only the actual name (i.e. trg), not including the schema (i.e. dbo in this case) or any text qualifiers (i.e. [ an…

Can row_number() ignore null in oracle

I have data like this How can i write query to get row_number without counting null column. Answer Well, not specifically. But you can get what you want by using conditional logic: It is not clear to me what the order by is for the row_number() which is what the . . . means.

Return first element in array_agg()

I am writing a query to get all players for all teams. Instead of looping in the application, I decided to get the players of all teams in a single query using array_agg(). I have written the query as follows: This query gives me the result as below, in the result set the teamname is being repeated (exactly t…

Grouping Totals With SQL Query

Here’s the situation: I have a table that has two data columns: And so on… I would like to create a query that presents the totals for the different numbers separately, so it would end up being like so: I’ve tried applying a simple SUM(Value) into my Query, but I can’t seem to get it r…

Recover DB after mirroring

I have this doubt. If i have a SQL 2012 database with a mirrored database and if i stop the mirror… the mirror database will not be accessible, it will be to “In recovery” status. What would happen if i execute: “restore database DB with recovery” Will it become accesible and hav…