Thursday, October 5, 2017
my_permissions
USE [sandbox]
GO
select * from sys.fn_my_permissions(NULL, 'database')
select * from sys.fn_my_permissions(NULL, 'server')
Friday, May 12, 2017
Quick View Table Structure and Contents
Viewing table Structure & Contents
USE [db_name]
go
declare @tableName as nvarchar(50) = 'test'
declare @SQLstmt as nvarchar(100) = 'SELECT top 10* FROM [dbo].[' + @tableName + ']'
SELECT obj.type_desc, OBJECT_NAME(col.object_id) as 'table_name', col.column_id, col.name as 'column_name'
, TYPE_NAME(col.user_type_id) as 'DataType_name'
--, col.system_type_id, col.user_type_id
, col.max_length, col.[precision], col.scale, col.collation_name, col.is_nullable, col.is_ansi_padded, col.is_rowguidcol, col.is_identity
FROM sys.objects obj inner join sys.columns col on obj.object_Id=col.object_Id
WHERE obj.Name=@tableName
--AND col.name LIKE '%org%'
ORDER BY col.column_id
EXEC sp_executesql @SQLstmt
Monday, May 8, 2017
Month and Day Leading Zeros? 09 not 9
declare @REL_START_DATE as datetime = GetDate()
SELECT cast(year(@REL_START_DATE) as varchar(4)) + '-' + RIGHT('0' + cast(month(@rel_start_date) as varchar(2)),2) + '-' + right('0' + cast(day(@rel_start_date) as varchar(2)),2) + ' 00:00:00.000' as 'REL_START_DATE'
Friday, March 31, 2017
Always On
If secondary runs out of space, make sure the Always On connection is removed and re-added so that no data is lost between the two.
Saturday, July 9, 2016
Check for Index on table
IF EXISTS (SELECT * FROM sys.indexes WHERE name='Index_Name'
AND object_id = OBJECT_ID('[SchmaName].[TableName]'))
begin
DROP INDEX [Index_Name] ON [SchmaName].[TableName];
end
Friday, May 20, 2016
Perform Mass Table Drops
You can build up a string using the catalog views, e.g.:
DECLARE @sql NVARCHAR(MAX) = N'';
SELECT @sql += '
DROP TABLE '
+ QUOTENAME(s.name)
+ '.' + QUOTENAME(t.name) + ';'
FROM sys.tables AS t
INNER JOIN sys.schemas AS s
ON t.[schema_id] = s.[schema_id]
WHERE t.name LIKE 'LG_001%';
PRINT @sql;
-- EXEC sp_executesql @sql;
To just get the list of tables, use:
SELECT s.name, t.name
FROM sys.tables AS t
INNER JOIN sys.schemas AS s
ON t.[schema_id] = s.[schema_id]
WHERE t.name LIKE 'LG_001%';
Wednesday, January 13, 2016
The transaction log for database is full due to 'LOG_BACKUP'
There are only 2 ways the Transaction Log will truncate itself to reuse the internal space (Virtual log files) , 1 is through checkpoint process, on the simple recovery model when the log gets 70% full. The other, is after every Log Backup under Full recovery model. Maybe something is going on with these log backups. Perhaps they are completing in SQL Agent, but not doing anything at all? Try checking the backup history table in MSDB to make sure the log backups are happening and their physical file exist
SELECT TOP (10) a.database_name[DB],a.server_name[SQL INST],b.physical_device_name,a.backup_finish_date [BKP END DATE],CASE a.type
WHEN 'D' THEN 'FULL'
WHEN 'L' THEN 'LOG'
END AS 'Backup Type'
FROM dbo.backupset a
JOIN dbo.backupmediafamily b
ON a.media_set_id = b.media_set_id
WHERE database_name IN ('Your Database Here') AND type = 'L'
ORDER BY backup_finish_date DESC
Thanks
SELECT TOP (10) a.database_name[DB],a.server_name[SQL INST],b.physical_device_name,a.backup_finish_date [BKP END DATE],CASE a.type
WHEN 'D' THEN 'FULL'
WHEN 'L' THEN 'LOG'
END AS 'Backup Type'
FROM dbo.backupset a
JOIN dbo.backupmediafamily b
ON a.media_set_id = b.media_set_id
WHERE database_name IN ('Your Database Here') AND type = 'L'
ORDER BY backup_finish_date DESC
Thanks
Wednesday, August 26, 2015
EXCEL :: Excel FIND() function
| IF Cell A1 = "cfuccillo003***********00300285569" THEN Cell B2 = LEFT(A1, FIND("*",A1,1)-1) |
Wednesday, August 5, 2015
ORACLE SQL BETWEEN two dates
SELECT * FROM ps_job
WHERE emplid = '00000000000'
and action_dt between to_date('10/01/2014','mm-dd-yyyy') and to_date('06/30/2015','mm-dd-yyyy')
Monday, August 3, 2015
Display Column Properties
SELECT b.name as 'schema_name', a.name, c.name as 'Column_Name', c.column_id, a.object_id, a.schema_id, a.parent_object_id, a.type, a.type_desc, a.create_date, a.modify_date
FROM sys.columns c INNER JOIN (sys.objects a INNER JOIN sys.schemas b ON a.schema_id = b.schema_id) ON c.object_ID = a.object_id
WHERE a.object_id IN (select object_ID from sys.columns where name like 'snapshot%')
and b.name = 'dbo'
and a.name = 'Flatfile_employee'
ORDER BY a.[type], b.name, a.name
FROM sys.columns c INNER JOIN (sys.objects a INNER JOIN sys.schemas b ON a.schema_id = b.schema_id) ON c.object_ID = a.object_id
WHERE a.object_id IN (select object_ID from sys.columns where name like 'snapshot%')
and b.name = 'dbo'
and a.name = 'Flatfile_employee'
ORDER BY a.[type], b.name, a.name
Subscribe to:
Posts (Atom)