terça-feira, 26 de julho de 2011

Quente.. Sistema para Controlar Estoque e atendimento de Farmacias..

Sistema para controlar o estoque de farmácias e ainda:
  1. Os mais vendidos.. 
  2. Reposição de estoque
  3. Analises dos dias que mais se vende..
  4. Os itens mais vendidos
  5. Os dias que mais se vende e o que se vende
  6. Abertura e fechamento do caixa por dia
  7. Já vem com todos os produtos da ABC Farma.
  8. Com o modulo de atualização de preços e itens. Apartir da ABC Farma.
  9. Voce ainda pode personalizar alguma opção desejada.
  10. Estatísticas diversas de sua farmácia.
Entre em contato comigo no fone (91) 8235 - 0249
Ulisses Ramos.


terça-feira, 15 de março de 2011

Exportar Todos os Logins do SQLServer

--------------------------

-- voce esta trocando de servidor ou vai atualizar seu sqlserver do
-- 7 para o 2000 ou do 2000 para o 2005 ou do 2005 para o 2008
-- esse script gera uma stored procedure chamanda
-- "sp_help_revlogin"
-- depois rode na tela o comando "exec sp_help_revlogin"
-- salve o result e depois carregue ele no novo sqlserver
-- rode so depois de ter restaurado todos os bancos.
--------------------------

use master
go
if object_id ('sp_hexadecimal') is not null
drop procedure sp_hexadecimal
go
create procedure sp_hexadecimal
@binvalue varbinary(256),
@hexvalue varchar (514) output
as
declare @charvalue varchar (514)
declare @i int
declare @length int
declare @hexstring char(16)
select @charvalue = '0x'
select @i = 1
select @length = datalength (@binvalue)
select @hexstring = '0123456789abcdef'
while (@i <= @length)
begin
declare @tempint int
declare @firstint int
declare @secondint int
select @tempint = convert(int, substring(@binvalue,@i,1))
select @firstint = floor(@tempint/16)
select @secondint = @tempint - (@firstint*16)
select @charvalue = @charvalue +
substring(@hexstring, @firstint+1, 1) +
substring(@hexstring, @secondint+1, 1)
select @i = @i + 1
end

select @hexvalue = @charvalue
go

if object_id ('sp_help_revlogin') is not null
drop procedure sp_help_revlogin
go
create procedure sp_help_revlogin @login_name sysname = null as
declare @name sysname
declare @type varchar (1)
declare @hasaccess int
declare @denylogin int
declare @is_disabled int
declare @pwd_varbinary varbinary (256)
declare @pwd_string varchar (514)
declare @sid_varbinary varbinary (85)
declare @sid_string varchar (514)
declare @tmpstr varchar (1024)
declare @is_policy_checked varchar (3)
declare @is_expiration_checked varchar (3)

declare @defaultdb sysname

if (@login_name is null)
declare login_curs cursor for

select p.sid, p.name, p.type, p.is_disabled, p.default_database_name, l.hasaccess, l.denylogin from
sys.server_principals p left join sys.syslogins l
on ( l.name = p.name ) where p.type in ( 's', 'g', 'u' ) and p.name <> 'sa'
else
declare login_curs cursor for


select p.sid, p.name, p.type, p.is_disabled, p.default_database_name, l.hasaccess, l.denylogin from
sys.server_principals p left join sys.syslogins l
on ( l.name = p.name ) where p.type in ( 's', 'g', 'u' ) and p.name = @login_name
open login_curs

fetch next from login_curs into @sid_varbinary, @name, @type, @is_disabled, @defaultdb, @hasaccess, @denylogin
if (@@fetch_status = -1)
begin
print 'no login(s) found.'
close login_curs
deallocate login_curs
return -1
end
set @tmpstr = '/* sp_help_revlogin script '
print @tmpstr
set @tmpstr = '** generated ' + convert (varchar, getdate()) + ' on ' + @@servername + ' */'
print @tmpstr
print ''
while (@@fetch_status <> -1)
begin
if (@@fetch_status <> -2)
begin
print ''
set @tmpstr = '-- login: ' + @name
print @tmpstr
if (@type in ( 'g', 'u'))
begin -- nt authenticated account/group

set @tmpstr = 'create login ' + quotename( @name ) + ' from windows with default_database = [' + @defaultdb + ']'
end
else begin -- sql server authentication
-- obtain password and sid
set @pwd_varbinary = cast( loginproperty( @name, 'passwordhash' ) as varbinary (256) )
exec sp_hexadecimal @pwd_varbinary, @pwd_string out
exec sp_hexadecimal @sid_varbinary,@sid_string out

-- obtain password policy state
select @is_policy_checked = case is_policy_checked when 1 then 'on' when 0 then 'off' else null end from sys.sql_logins where name = @name
select @is_expiration_checked = case is_expiration_checked when 1 then 'on' when 0 then 'off' else null end from sys.sql_logins where name = @name

set @tmpstr = 'create login ' + quotename( @name ) + ' with password = ' + @pwd_string + ' hashed, sid = ' + @sid_string + ', default_database = [' + @defaultdb + ']'

if ( @is_policy_checked is not null )
begin
set @tmpstr = @tmpstr + ', check_policy = ' + @is_policy_checked
end
if ( @is_expiration_checked is not null )
begin
set @tmpstr = @tmpstr + ', check_expiration = ' + @is_expiration_checked
end
end
if (@denylogin = 1)
begin -- login is denied access
set @tmpstr = @tmpstr + '; deny connect sql to ' + quotename( @name )
end
else if (@hasaccess = 0)
begin -- login exists but does not have access
set @tmpstr = @tmpstr + '; revoke connect sql to ' + quotename( @name )
end
if (@is_disabled = 1)
begin -- login is disabled
set @tmpstr = @tmpstr + '; alter login ' + quotename( @name ) + ' disable'
end
print @tmpstr
end

fetch next from login_curs into @sid_varbinary, @name, @type, @is_disabled, @defaultdb, @hasaccess, @denylogin
end
close login_curs
deallocate login_curs
return 0
go

sábado, 12 de março de 2011

Firewall Windows 2008 Server vs SQL2008



Guia Exceptions, adicione dois serviços: sqlservr e sqlbrowser: 


1) C:\Program Files\Microsoft SQL Server\90\Shared\sqlbrowser.exe 
2) C:\Program Files\Microsoft SQL Server\MSSQL10.NOVO2008\MSSQL\Binn\sqlservr.exe 




ou mude a pasta para "C:\Program Files(x86)" 
Verifique a instância do SQLSERVER = MSSQL10.NOVO2008 para MSSQL.

quinta-feira, 10 de março de 2011

Zerar Campos de auto incremento SQLServer



--Os campos de identificação automática (Indentity Increment) do 
--SqlServer possuem um contador mantido nas tabelas do sistema,
--para alteraras mesmas deve-se utilizar o comando DBCC para auterar a mesma.
--Para zerar completamente o contador, iniciando do zero novamente:

DBCC CHECKIDENT ('NomeDaTabela', RESEED, 0) 

--Para colocar o ultimo numero utilizado: 
DBCC CHECKIDENT ('NomeDaTabela', RESEED, (select max(nome_campo) from NomeDaTabela))

terça-feira, 8 de março de 2011

COMANDO PARA RECRIAR LOGS NO SQLSERVER 2008

  
-- No exemplo temos um Banco sem o seu log no sql2008
-- arquivo ldf .. o comando abaixo recria o log e anexa o banco. 

use master 
go 
sp_attach_single_file_db 'NomeLogicoBanco', 'Caminho e nome do arquvo.mdf' 
go  

sexta-feira, 25 de fevereiro de 2011

Verificando espaço em disco e o espaço ocupado por tabelas!

  
-- No exemplo temos um Banco sem o seu log no sql2008
-- arquivo ldf .. o comando abaixo recria o log e anexa o banco. 


use master 
go 
sp_attach_single_file_db 'NomeLogicoBanco', 'Caminho e nome do arquvo .mdf' 
go 

/*
Muito interessante, foi feito por Thiago Zavaschi
Verificar o tamanho ocupado por tabelas no banco (a.k.a achar maiores tabelas):
Ordenado por quantidade de linhas:
SELECT object_name(id), rowcnt, dpages * 8 AS [tamanho KB] FROM sysindexes
WHERE indid IN (1,0) AND objectproperty(id,'isusertable') = 1
ORDER BY rowcnt DESC
Ordenado por tamanho físico:
SELECT object_name(id), rowcnt, dpages * 8 AS [tamanho KB] FROM sysindexes
WHERE indid IN (1,0) AND objectproperty(id,'isusertable') = 1
ORDER BY [tamanho KB] DESC
E para mostrar o espaço em disco disponível (valor absoluto e percentual) e o espaço total dos discos, é possível utilizar (a fonte deste script é o SQLDBATips): */
DECLARE @hr int
DECLARE @fso int
DECLARE @drive char(1)
DECLARE @odrive int
DECLARE @TotalSize varchar(20)
DECLARE @MB bigint ; SET @MB = 1048576
CREATE TABLE #drives (drive char(1) PRIMARY KEY,
                      FreeSpace int NULL,
                      TotalSize int NULL)
INSERT #drives(drive,FreeSpace)
EXEC master.dbo.xp_fixeddrives
EXEC @hr=sp_OACreate 'Scripting.FileSystemObject',@fso OUT
IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @fso
DECLARE dcur CURSOR LOCAL FAST_FORWARD
FOR SELECT drive from #drives
ORDER by drive
OPEN dcur
FETCH NEXT FROM dcur INTO @drive
WHILE @@FETCH_STATUS=0
BEGIN
        EXEC @hr = sp_OAMethod @fso,'GetDrive', @odrive OUT, @drive
        IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @fso
        EXEC @hr = sp_OAGetProperty @odrive,'TotalSize', @TotalSize OUT
        IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @odrive
        UPDATE #drives
        SET TotalSize=@TotalSize/@MB
        WHERE drive=@drive
        FETCH NEXT FROM dcur INTO @drive
END
CLOSE dcur
DEALLOCATE dcur
EXEC @hr=sp_OADestroy @fso
IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @fso
SELECT drive,
       FreeSpace as 'Livre(MB)',
       TotalSize as 'Total(MB)',
       CAST((FreeSpace/(TotalSize*1.0))*100.0 as int) as 'Livre(%)'
FROM #drives
ORDER BY drive
DROP TABLE #drives
RETURN
GO
/*
A saída do script deverá ser semelhante a:
drive Livre(MB)   Total(MB)   Livre(%)
----- ----------- ----------- -----------
C     9541        49999       19
D     46002       317966      14
F     37549       99998       37
K     68581       476269      14
É isso pessoal, fazia tempo que não postava algo masi focado a área de DBA (a qual gosto muito também), espero que seja útill.
*/