Last run date of a view and triggers - sql

Is it possible to find the run date of view and triggers in SQL Server? We have a script for procedures but not views and triggers. We need this to create a report of the last run date of the objects in the production.

This can also be achieved by using a server side trace
https://www.sqlservercentral.com/blogs/setting-up-a-server-side-trace

Related

Creator of a column - SQL Server

How to find the creator of a column in SQL Server?
I checked sys.column table but only getting the created and modified date. With these two fields I also need the Creator of the column.
By Creator I mean the userid which is used to login to sql server.
Possibly you can not but if you change the column recently than you can try to find it in the below way
This report provides a history of all committed DDL statement executions within the Database recorded by the default trace.

SQL View displaying incorrect data while the same sql code run in a query window gives correct data

One of my SQL view when opened and run in a design window gives incorrect data while the same underlying SQL code is run in a new Query window gives correct data. To be more specific, this view is pointing to a table where data changes on a daily basis. Why am I getting stale data in the design view while the same (same view underlying sql) code run in a Query Window gives current data. This has never happened before. There is a excel sheet that connects to this view to pull data into reports and this is getting the stale data into the report.
What should I be looking at to fix this issue.
And the server is SQL Server 2008 R2 (SP1)
Any help is appreciated. Thanks in advance.
You probably use * in your view to select all columns from some table
select * from table
when you add a new column to that table you'll need to re-run the view, then it'll work... select *, especially in view is generally considered a bad practice. In the case of a * metadata is not automatically updated when the tables (or schema for that matter) used in view are modified, therefore you'll need to alter the view
another way of refreshing it is running system stored proc:
EXEC sp_RefreshView vw_ViewName

create ms sql server job schedule from datetime database

I'm using microsoft SQL server management studio 2005
I'm trying to run a job at a specific time and that time is stored in a database.
I can't insert the schedule manually because it is up to the user to decide what date and time the job(s) has to be done. php collects the time and date and sends it to a database.
I thought about runing a job every min and in my execution I have an if statement that only activates when the datetime stored in the database is one minute greater or lower than the current datetime. but doing it like this would be inaccurate and very inefficient. would it be possible to create a schedule directly from a query or job?
You can create and modify both jobs and schedules programmatically using SMO or TSQL. That means you can use an external application, a stored procedure or a trigger to create or update a job schedule based on the table data. SMO is probably the best way to go if you want to build an application to manage jobs, but on the other hand it's .NET only.

Delete column in SQL Server after a period from creation

I am working with sensitive/private files stored in SQL Server as VarBinary(MAX). Is there a way to tell the database or nHibernate to nullify the column after a period of time after its creation.
Make sure to put a timestamp column on the table, then set up a SQL Scheduled Job with a query to delete those rows periodically based on that time.
Absolutely not
Imagine the fun when SQL Server decides to change data apparently on it's own because the code monkey fluffed setting up whatever mechanism would be used...
You could (off top of my head):
Encrypt the columns
Schedule a clean up (SQL Agent job, a config table)
Don't use SQL Server for the files themselves, just store paths/links

best way in producing a master script for SQL

i want to extract specific database tables & stored procedures into one master script. Do you know any software that can help me do this faster? I've tried using the SQL Database publishing tool, but it's not that efficient since its gathering tables that I didn't select.
In SQL Server 2005, right click on the database, then select Tasks, and then select Generate Scripts.
Generating SQL Scripts in SQL Server 2005
As mentioned in that link, I'm fairly sure you have to generate the DROP and CREATE statements separately.
Try DBSourceTools. http://dbsourcetools.codeplex.com
Its open source, and specifically designed to script databases - tables, views, procs to disk.
It also allows you to select which tables, views, db-objects to script.
I use Redgate SQL compare for this (by comparing to an empty DB), as well as for doing upgrades between all my DB versions (I save a copy of the DB for each released version, and then just do a compare between current and previous to get a change script for that version).
I have found the "Generate Scripts" does a bad job in some cases with dependencies - eg, it will try to create a stored procedure that uses a table before the table is created, causing the script to fail. I'll accept I'm possibly using it wrong, but SQL Compare "just works". The scripts it generates are also enclosed in a transaction -- so if something fails, the whole change is rolled back. You don't end up with a half-populated or half-upgraded database.
Downside is that this is a commercial tool, but IMHO worth the money.