February 2004 - Posts

Backups of user databases

Thanks to TARA for this piece of code. It shows you the last full backup of your user databases


SELECT
 bs.database_name AS DatabaseName,
 MAX(bms.physical_device_name) AS FullBackupName
FROM
 msdb.dbo.backupset bs INNER JOIN msdb.dbo.backupmediafamily bms
  ON bs.media_set_id = bms.media_set_id
 INNER JOIN master.dbo.sysdatabases s
  ON bs.database_name = s.name
WHERE
 CONVERT(VARCHAR(20), bs.backup_finish_date, 101) = CONVERT(VARCHAR(20), GETDATE(), 101) AND
 s.name NOT IN ('master', 'msdb', 'model', 'pubs', 'Northwind')
GROUP BY
 bs.database_name

Check Constraints and UDF's -Part II

Came across a problem where it was needed to check a password field to be alphanumeric with no repeating chars (Why would anybody need that ???). This is another good example for using the udf to implement a check constraint ....


use pubs
go
create table tally (id int)
GO
SET NOCOUNT ON
GO
declare @i int,@count int
select @i =1, @count = 100
while @i < @count
begin
 insert into tally select @i
 select @i = @i + 1
end
GO
SET NOCOUNT OFF
GO
Create FUNCTION [udf_PwdCheck] (@pwd varchar(40))
RETURNS INT
AS
BEGIN
DECLARE @return_value bit
declare @checkstring varchar(50)
select @checkstring = 'abcdefghijklmnopqrstuvwxyz1234567890'

if exists (
 select
  partstr,
  count(position)
 from
  (
  select
   distinct substring (@checkstring,t1.id,1) partstr ,charindex(substring (@checkstring,t1.id,1),@pwd,t2.id) position
  from
   tally t1,(select @pwd 'pwd') pwd, tally t2
  where
   t1.id <= len(@checkstring)
   and charindex(substring (@checkstring,t1.id,1),@pwd,t2.id) <> 0
   and t2.id <= len(@checkstring)
  ) a
 group by
  partstr
 having
  count(position) > 1
 )
 set @return_value = 0
else
begin
 if (@pwd like '%[1-9]%' and @pwd like '%[a-z]%')
  set @return_value = 1
 ELSE
  set @return_value = 0
end
return @return_value
END
go

CREATE TABLE [user_master] (
[userid] [varchar] (20)NULL ,
[pwd] [varchar] (40) check (dbo.udf_PwdCheck(pwd) =1)
) ON [PRIMARY]
GO

insert into user_master  select 'Enigma','I am the 1'
insert into user_master  select 'Brett','Bring on the Margaritas!!'
insert into user_master  select 'blindman', 'Where is my dog ?'

go
drop table user_master
drop function udf_PwdCheck

drop table tally


Certified 34% evil

 

Pretty Bad .. for a SQL Junkies Blog :(

Kill Everyone !!!

Personal Thoughts : Today's Websurf Results

Just came across this site ... http://homokaasu.org/killeveryone

Looks like I still have three - fours years left before I am killed :)

Can this happen ???

Personal Thoughts - Can this really happen ??


Commercial and/or recruiting "spam" will not be tolerated in the forums. Our forums are member-policed via the forums' "Red-Flag" utility. Offending posters will be dealt with sternly not only by the management of this site, but also face possible retaliation by the members of this web community (we exert no control over our members and in no way encourage this kind of activity).


Just saw this on the Tek-Tips Site. Can you believe that the members of these kind of forums who always help other people would go down to this level ... Just my  .02 $

 

Bloggers From India

[Community] - Indian Bloggers

I would like to know if there are people blogging on technical topics from India ... request everybody to please make a comment on this blog so that we can build an Indian Bloggers Community ...

I 'll keep updating the list as I get to know more bloggers

Bloggers List

Blogger Name Blog Url 
Bahl, Manuj  Enigma's Weblog
Sriram Krishnan Sriram Krishnan
Anand M .NET From India

What is better ??

[Personal Thoughts] + [SQL Server] + [VB] - What is Better ??

[rant]

Everybody, (including me) is more comfortable in doing things in a way we know how to. For example, few minutes back I got into a heated argument with a developer regarding technology to be used to read mails received and save the attatchments in a folder in SQL. The developer was advocating on using VB for making the application for the same and me advocating T-SQL. 

I showed him how to do this using xp_readmail.


CREATE procedure usp_ProcessMailAttatchments @copypath varchar(256) = 'c:\Upload\'
as
begin
 set nocount on
 declare @status int 
 declare @msg_id varchar(94) 
 declare @originator varchar(255) 
 declare @cc_list varchar(255) 
 declare @msgsubject varchar(255) 
 declare @query varchar(8000) 
 declare @messages int 
 declare @mapifailure int 
 declare @resultmsg varchar(80) 
 declare @current_msg varchar(94) 
 declare @attachedfiles varchar(800)
 declare @folder varchar(200)
 declare @filename varchar(256)
 declare @filepath varchar(256)
 
 select @messages=0 
 select @mapifailure=0 
 create table #temp
 (
  results varchar(300)
 )
 exec @status = master.dbo.xp_findnextmsg 
    @msg_id=@msg_id output, 
    @unread_only='true' 
 
 if @status <> 0 
   select @mapifailure=1 
 
 while (@mapifailure=0) 
   begin 
 
      if @msg_id is null break 
      if @msg_id = '' break 
 
      exec @status = master.dbo.xp_readmail 
     @msg_id=@msg_id, 
     @originator=@originator output, 
     @cc_list=@cc_list output, 
     @subject=@msgsubject output,
     @suppress_attach = 'false',
     @attachments = @attachedfiles output,   
     @message=@query output, 
     @peek='true' 
 
    if (@attachedfiles is not null)
  begin
   Select
    reverse(substring(reverse(Path),1,charindex('\',reverse(Path),1)-1)) "Filename",
    reverse(substring(reverse(Path),charindex('\',reverse(Pat