Automated Update SQL Server - sql-server

I have a table of topics, topics might have an automatic publish date, I want to make SQL Server auto publishes them.
Previously I made it in code on each call to any method of the topics adapter, but I wanna make it automatically in SQL Server.
Can I?
It might be some kinda scheduled job or something like that.
I'm using SQL Server 2005 (Express and Professional).

What do you mean by 'publish'? It definitely sounds like you could use a SQL Server Agent job, to execute, say
UPDATE topics SET published = 1 WHERE publishdate < getdate()
if that is what all what you want to do, when you refer to 'auto publish'
EDIT
Since a SQL Server Agent job won't do. How about modifying your selects instead?
SELECT
(published OR publishdate < getdate()) as published
FROM
topics

Related

Is there a way to check Which Queries are run by a User in SSAS Tabular?

I am using a BI Model that is a based on SSAS Tabular, using SQL server 2016. Multiple team members are querying it for their needs. I want to find out what Queries are being run and who is running those queries.
Couldn't find DMVs very helpful in my case.
This query only shows the last command run by a user.
Select * from $System.discover_sessions
The simplest of the lot is still SQL Server Profiler. It's been around forever, almost replaced by Extended Events, but works just fine with SSAS, and easy to trace activity with it.
For the question of "Who is running those queries", we use the "Query Logs" feature of SSAS.
Once you setup a bunch of properties in the SSAS Server, it would start to log to the configured SQL Server table.
To enable the query log, follow these steps:
(1) Create a SQL Server relational database to store the query log.
(2) Grant the Analysis Services service account sufficient permissions on the database. The account needs permission to create a table, write to the table, and read from the table.
(3) In SQL Server Management Studio, right-click Analysis Services | Properties | General, set CreateQueryLogTable to true.
(4) Optionally, change QueryLogSampling or QueryLogTableName if you want to sample queries at a different rate, or use a different name for the table.
Un-fortunately, the Query Logs, does NOT log the queries ! But, it does help in finding who / when the queries are running.
Once you have enabled logging, you can query the table for stats.
SELECT CAST(starttime AS DATE) 'Date'
, MSOLAP_User 'User'
, COUNT(1) 'No. of queries'
FROM [dbo].[OlapQueryLog]
GROUP BY MSOLAP_User
, CAST(starttime AS DATE)
ORDER BY 1 DESC, 3 DESC
There is also the AsTrace tool
For constant monitoring and logging, the ASTrace tool will capture a Profiler trace and write it to a SQL Server table without requiring a GUI. ASTrace also runs as a Windows service allowing it to restart automatically when the server reboots.

SSRS Subscriptions - Daily Emails Within a Time Interval

I need to setup a subscription to an SSRS report that I have, so it would send emails Daily between 5PM and 5AM only. Is this supported by SSRS 2005 or 2008?
My only option right now is to set up 12 different copies of the report and have 12 different subscriptions, for 5PM, 6PM, 7PM...4AM, 5AM etc. I don't like this approach for the maintenance complexity it adds.
Is there a better way to do this?
Thanks,
Nandun
Not through Report Manager; you've already seen that you have limited options there.
However, when you set up an SSRS subscription, behind the scenes it's just set up as a normal SQL Server job run through the SQL Server Agent - these jobs are set up under a GUID type name, i.e. something like 8DF42130-97D3-41F7-B3EF-72E48BFDFBFA.
This means that you can update the job schedule in Management Studio with a few more options:
You should be able to update a SSRS created subscription to suit your requirements.
Not sure why you can't just do this through Report Manager, but hopefully this will help.

How to audit SQL Server 2008 queries through WCF Services?

I want to save any kind of log/tables with every query executed by my application.
I know I could do this by coding it (before I make any query, I insert a new row in a log table with the query and the user who is executing it.
I have read it can be done automatically but I'm not sure how can it work with WCF Services. I mean every query is going to be executed by the same SQL user and this wouldn't be very useful for audit operations (I need to know WHO made every query, and users will be validated against my own users tables).
Have you ever had a similar scenario? Thanks in advance!
As a starting point it may be worth looking into doing this via SQL Server Profiler. You can normally find this in the Tools Menu in Management Studio.
You can set up a trace to capture all SQL run on a server. More importantly you have a myriad of filter options which can be applied so that you only capture the data you are interested in (e.g. DatabaseName, UserName).
This information can be stored directly in a SQL Table, which should give you the abillity to join onto. Of course running anything like this will result in some overhead on the SQL box.
You can try the SQL Server Audit feature. It audits singe or groups of events both on server and database level. However, be advised that the database level auditing is available in SQL Server Enterprise and Developer editions only

SQL Server 2008 retain last open databases

I use around 3 SQL Server 2008 databases. Every time I need to query on a database, I need to login to that db and then query. Is there a way to retain the last opened database in SQL Server 2008?
As an analogy, think this is like firefox allowing to display the last open websites.
SQL Server retains last opened database. It actually never closes them (auto_close and user instances not withstanding). Do you mean Management Studio by any chance? You can add an USE statement to your saved query. You can use sqlcmd extensions in your query to simply run the query in one shot on all servers/db. Or you can use something like SSMS Tools Pack, a free add on that enhances SSMS with things like query history.
You would need to have the same login for all 3 databases and have auto_close set to off

SQL Server 2005 Change Auditing

Is there a built in way in SQL Server 2005 to audit things specifically like deleting a stored procedure? Is there a history table that I can query? We have a mystery sproc that has disappeared a few times now.
You can build this using DDL triggers:
http://msdn.microsoft.com/en-us/library/ms190989.aspx
Only if you use DDL triggers or use profiler to trace text "%DROP%PROC%procname%"
Note that in SQL Server 2008 they also now have AUDIT to replace Profiler Traces for auding activities. It is similar but has its own configuration UI and UI to view results
You can setup a profiler trace to capture the Audit Schema Object Management event and filter based on the database name you care about. Any time an object in the schema is created, dropped, edited it will fire an event in profiler that includes the person who did the change and the name of the stored procedure.
You will want at least these profiler columns:
ApplicationName - name of app user was running when they made change
DatabaseName - Databse containing the object changed
EventSubClass - Type of action shows Alter, Modify, Drop, Create etc
LoginName - user making change
ObjectName - object affected
[late one but adds details on how to see who made the change even before auditing system is put into place]
Others have already covered different ways you can start auditing data in order to monitor future changes but if you originally didn’t have any auditing system in place then it’s very difficult to find out who did what and when historically.
Only option is to try reading transaction log assuming database is in full recovery mode. Problem is that this is not supported by default. Options are:
Third party tools such as ApexSQL Log or Quest Toad
Undocumented functions such as DBCC LOG or fn_dblog
See these topics for more details:
How to view transaction log in SQL Server 2008
SQL Server Transaction Log Explorer/Analyzer
How to see query history in SQL Server Management Studio
I agree. It can be the SQL Server profiler with filters. The DDL triggers existed in SQL Server.
You could create something like this:
CREATE TRIGGER ddl_drop_procedure
ON DATABASE
FOR DROP_PROCEDURE
AS
RAISERROR ('You deleted a stored procedure',10, 1)
GO
The other option is to use third party tools like Auto Audit from codeplex, or apexSQL trigger.

Resources