Reputation: 21
I am having script text file that inside having
I need to know views, SPs, tables names and its roles (create or alter) when I run the script.
Example following are text file.
and the result should be following
proc, alter, bal.vendor
table, select, manager
table, create, employee
table, alter, persons
Upvotes: 0
Views: 45
Reputation: 14928
All those are called Objects
, so the only thing may come up to your mind is to use sys.all_objects
view which can be found in:
YourDatabase -> Views -> SystemViews
All those objects has a type
:
U -> USER_TABLE
IF -> SQL_INLINE_TABLE_VALUED_FUNCTION
P -> SQL_STORED_PROCEDURE
TR -> SQL_TRIGGER
V -> VIEW
...etc
So, you can query this View
to get the results you want as:
SELECT object_id,
name,
type,
type_desc,
CASE WHEN create_date = modify_date THEN 'Created' ELSE 'Altered' END AS state,
create_date,
modify_date
FROM sys.all_objects
WHERE type IN ('U', 'P', 'V'); --Optional you can remove it if you wan all types of objects
Upvotes: 1
Reputation: 8256
You can use sql query:
SELECT name, type, type_desc, create_date, modify_date
FROM sys.objects
WHERE modify_date > '01-01-2017' -- pass your date
The objects that were newly created will have the same date for both create_date
and modify_date
. Use this modified query to show if it was new or modified:
SELECT name, type, type_desc,
case when create_date = modify_date then 'Created' Else 'Altered' end
FROM sys.objects
WHERE modify_date > '01-01-2017'
Upvotes: 1