-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommonSQLQueriesAndTools.sql
More file actions
54 lines (45 loc) · 1.54 KB
/
Copy pathCommonSQLQueriesAndTools.sql
File metadata and controls
54 lines (45 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
--SQL Stuff
--Delete Temp Table If Exists
IF OBJECT_ID('tempdb..#Results') IS NOT NULL DROP TABLE #Results
--Find Tables with Constraints
SELECT
table_name,
constraint_type,
constraint_name
FROM information_schema.table_constraints
--WHERE table_name = 'student';
--Get Open Transactions
DBCC OPENTRAN
SELECT * FROM sys.sysprocesses WHERE open_tran = 1
--Finding Special Characters
select 'ItemScore',*
from eva.ItemScore iscore
with(nolock)
where charindex(CHAR(0x1f), iscore.Notes, 0) > 0
--Enable/Disable Triggers
-- Disable trigger if needed for bulk changes or whatever
DISABLE TRIGGER vnd.TRG_VendorUser_InsertUpdate_UserName ON vnd.VendorUser
--update vnd.vendoruser
--set UserName = 'cbarrugardensupplies'
--where VendorUserID = 409383
-- Re-enable trigger
ENABLE TRIGGER vnd.TRG_VendorUser_InsertUpdate_UserName ON vnd.VendorUser
--Finding Tables with Specific Column Names
--Search Tables:
SELECT c.name AS 'ColumnName'
,(SCHEMA_NAME(t.schema_id) + '.' + t.name) AS 'TableName'
FROM sys.columns c
JOIN sys.tables t ON c.object_id = t.object_id
WHERE c.name LIKE '%MyName%'
ORDER BY TableName
,ColumnName;
--Search Tables and Views:
SELECT COLUMN_NAME AS 'ColumnName'
,TABLE_NAME AS 'TableName'
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE '%MyName%'
ORDER BY TableName
,ColumnName;
--Finding Tables
SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE '%VendorMergeNotification%'