Escolar Documentos
Profissional Documentos
Cultura Documentos
FH666-Y346V-7XFQ3-V69JM-RHW28
SQL SERVER � T-SQL Script to find the CD key from Registry
Here is the way to find SQL Server CD key, which was used to install it on machine.
If user do not have permission on the SP, please login using SA username. Expended
stored procedure xp_regread can read any registry values. I have used this XP to
read CD_KEY. This is undocumented Stroed Procedure and may not be supported in
Future Version of SQL Server.
USE master
GO
EXEC xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Microsoft SQL
Server\80\Registration','CD_KEY'
GO
USE master;
GO
CREATE DATABASE Sales
ON
( NAME = Sales_dat,
FILENAME = 'C:\DATA\saledat.mdf',
SIZE = 10,
MAXSIZE = 50,
FILEGROWTH = 5 )
LOG ON
( NAME = Sales_log,
FILENAME = 'C:\DATA\salelog.ldf',
SIZE = 5MB,
MAXSIZE = 25MB,
FILEGROWTH = 5MB ) ;
GO
===================================================================================
===========================================================
CREATE login (Transact-SQL)
===================================================================================
===========================================================
CREATE table (Transact-SQL)
===================================================================================
===========================================================
CREATE VIEW (Transact-SQL)
USE AdventureWorks2012 ;
GO
IF OBJECT_ID ('Sales.SalesPersonPerform', 'V') IS NOT NULL
DROP VIEW Sales.SalesPersonPerform ;
GO
CREATE VIEW Sales.SalesPersonPerform
AS
SELECT TOP (100) SalesPersonID, SUM(TotalDue) AS TotalSales
FROM Sales.SalesOrderHeader
WHERE OrderDate > CONVERT(DATETIME,'20001231',101)
GROUP BY SalesPersonID;
GO
===================================================================================
===========================================================
CREATE TRigger (Transact-SQL)
C.Usando um gatilho DML AFTER para impor uma regra de neg�cio entre as tabelas
PurchaseOrderHeader e Vendor
Como as restri��es CHECK s� podem referenciar as colunas nas quais a restri��o de
n�vel de coluna ou de n�vel de tabela � definida, qualquer restri��o em todas as
tabelas (nesse caso, as regras de neg�cio) dever� ser definida como gatilho.
O exemplo a seguir cria um gatilho DML. Esse gatilho realiza uma verifica��o
confirmar se a classifica��o de cr�dito para o fornecedor � boa quando � feita uma
tentativa de inserir uma nova ordem de compra na tabela PurchaseOrderHeader. Para
obter a classifica��o de cr�dito do fornecedor, a tabela Vendor deve ser
referenciada. Se a classifica��o de cr�dito for muito baixa, uma mensagem ser�
exibida e a inser��o n�o ser� executada.
SE AdventureWorks2012;
GO
IF OBJECT_ID ('Purchasing.LowCredit','TR') IS NOT NULL
DROP TRIGGER Purchasing.LowCredit;
GO
-- This trigger prevents a row from being inserted in the
Purchasing.PurchaseOrderHeader table
-- when the credit rating of the specified vendor is set to 5 (below average).
===================================================================================
===========================================================
CREATE PROCEDURE (Transact-SQL)
USE AdventureWorks2012;
GO
IF OBJECT_ID (N'dbo.ISOweek', N'FN') IS NOT NULL
DROP FUNCTION dbo.ISOweek;
GO
CREATE FUNCTION dbo.ISOweek (@DATE datetime)
RETURNS int
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @ISOweek int;
SET @ISOweek= DATEPART(wk,@DATE)+1
-DATEPART(wk,CAST(DATEPART(yy,@DATE) as CHAR(4))+'0104');
--Special cases: Jan 1-3 may belong to the previous year
IF (@ISOweek=0)
SET @ISOweek=dbo.ISOweek(CAST(DATEPART(yy,@DATE)-1
AS CHAR(4))+'12'+ CAST(24+DATEPART(DAY,@DATE) AS CHAR(2)))+1;
--Special case: Dec 29-31 may belong to the next year
IF ((DATEPART(mm,@DATE)=12) AND
((DATEPART(dd,@DATE)-DATEPART(dw,@DATE))>= 28))
SET @ISOweek=1;
RETURN(@ISOweek);
END;
GO
SET DATEFIRST 1;
SELECT dbo.ISOweek(CONVERT(DATETIME,'12/26/2004',101)) AS 'ISO Week';
BEGIN TRY
-- Generate a constraint violation error.
DELETE FROM Production.Product
WHERE ProductID = 980;
END TRY
BEGIN CATCH
SELECT
ERROR_NUMBER() AS ErrorNumber
,ERROR_SEVERITY() AS ErrorSeverity
,ERROR_STATE() AS ErrorState
,ERROR_PROCEDURE() AS ErrorProcedure
,ERROR_LINE() AS ErrorLine
,ERROR_MESSAGE() AS ErrorMessage;
IF @@TRANCOUNT > 0
ROLLBACK TRANSACTION;
END CATCH;
IF @@TRANCOUNT > 0
COMMIT TRANSACTION;
GO
===================================================================================
===========================================================
SELECT
cod_produto,
des_produto,
ROW_NUMBER() over (order by des_produto) sequencial
FROM
tb_teste_produto
===================================================================================
===========================================================
===================================================================================
===========================================================
===================================================================================
===========================================================