29 jul 2011

XACT_STATE()

SELECT XACT_STATE()


IF XACT_STATE() = 1
ROLLBACK;

1 - TRANSACTION BEGIN
0 - NO TRANSACTION

TRY CATCH

-- Verify that the stored procedure does not exist.
IF OBJECT_ID ('usp_GetErrorInfo', 'P') IS NOT NULL
DROP PROCEDURE usp_GetErrorInfo;
GO

-- Create a procedure to retrieve error information.
CREATE PROCEDURE usp_GetErrorInfo
AS
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;
GO

BEGIN TRY
-- Generate divide-by-zero error.
SELECT 1/0;
END TRY
BEGIN CATCH
-- Execute the error retrieval routine.
EXECUTE usp_GetErrorInfo;
END CATCH;
GO

27 jul 2011

sp_spaceused 'Campaigns'


Name rows reserved data index_size unused

Campaigns 0 40 KB 16 KB 24 KB 0 KB

Sysobjects

--'sysobjects' tiene objectos (tablas, Stores, Funcions, etc)
--'syscolumns' tiene objectos (tablas, Stores, Funcions, etc)

SELECT SO.NAME, SC.NAME

FROM sysobjects SO INNER JOIN syscolumns SC
ON SO.ID = SC.ID

WHERE SO.XTYPE = N'U'

ORDER BY SO.NAME, SC.NAME

Column nameData typeDescription
namesysnameObject name
idintObject identification number
xtypechar(2)Object type. Can be one of the following object types:
AF = Aggregate function (CLR)
C = CHECK constraint
D = Default or DEFAULT constraint
F = FOREIGN KEY constraint
L = Log
FN = Scalar function
FS = Assembly (CLR) scalar-function
FT = Assembly (CLR) table-valued function
IF = In-lined table-function
IT = Internal table
P = Stored procedure
PC = Assembly (CLR) stored-procedure
PK = PRIMARY KEY constraint (type is K)
RF = Replication filter stored procedure
S = System table
SN = Synonym
SQ = Service queue
TA = Assembly (CLR) DML trigger
TF = Table function
TR = SQL DML Trigger
TT = Table type
U = User table
UQ = UNIQUE constraint (type is K)
V = View
X = Extended stored procedure
uidsmallintSchema ID of the owner of the object.
For databases upgraded from an earlier version of SQL Server, the schema ID is equal to the user ID of the owner.
Important noteImportant
If you use any of the following SQL Server DDL statements, you must use the sys.objects catalog view instead of sys.sysobjects.CREATE | ALTER | DROP USERCREATE | ALTER | DROP ROLECREATE | ALTER | DROP APPLICATION ROLECREATE SCHEMA ALTER AUTHORIZATION ON OBJECT
Overflows or returns NULL if the number of users and roles exceeds 32,767.
For more information, see Querying the SQL Server System Catalog.
infosmallintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
statusintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
base_schema_verintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
replinfointIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
parent_objintObject identification number of the parent object. For example, the table ID if it is a trigger or constraint.
crdatedatetimeDate the object was created.
ftcatidsmallintIdentifier of the full-text catalog for all user tables registered for full-text indexing, and 0 for all user tables that are not registered.
schema_verintVersion number that is incremented every time the schema for a table changes. Always returns 0.
stats_schema_verintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
typechar(2)Object type. Can be one of the following values:
AF = Aggregate function (CLR)
C = CHECK constraint
D = Default or DEFAULT constraint
F = FOREIGN KEY constraint
FN = Scalar function
FS = Assembly (CLR) scalar-function
FT = Assembly (CLR) table-valued functionIF = In-lined table-function
IT - Internal table
K = PRIMARY KEY or UNIQUE constraint
L = Log
P = Stored procedure
PC = Assembly (CLR) stored-procedure
R = Rule
RF = Replication filter stored procedure
S = System table
SN = Synonym
SQ = Service queue
TA = Assembly (CLR) DML trigger
TF = Table function
TR = SQL DML Trigger
TT = Table type
U = User table
V = View
X = Extended stored procedure
userstatsmallintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
sysstatsmallintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
indexdelsmallintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
refdatedatetimeIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
versionintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
deltrigintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
instrigintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
updtrigintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
seltrigintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
categoryintUsed for publication, constraints, and identity.
cachesmallintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.

26 jul 2011

Transacciones - ACID

En concreto ACID es un acrónimo de Atomicity, Consistency, Isolation and Durability: Atomicidad, Consistencia, Aislamiento y Durabilidad en español.

Atomicidad: es la propiedad que asegura que la operación se ha realizado o no, y por lo tanto ante un fallo del sistema no puede quedar a medias.
Consistencia: es la propiedad que asegura que sólo se empieza aquello que se puede acabar. Por lo tanto se ejecutan aquellas operaciones que no van a romper la reglas y directrices de integridad de la base de datos.
Aislamiento: es la propiedad que asegura que una operación no puede afectar a otras. Esto asegura que la realización de dos transacciones sobre la misma información sean independientes y no generen ningún tipo de error.
Durabilidad: es la propiedad que asegura que una vez realizada la operación, ésta persistirá y no se podrá deshacer aunque falle el sistema.
Cumpliendo estas 4 condiciones o propiedades se considera ACID Compliant.


IMPLICIT TRANSACTIONS: SET IMPLICIT_TRANSACTIONS ON

EXPLICIT TRANSACTIONS: BEGIN TRANSACTION, COMMIT TRANSACTION and ROLLBACK TRANSACTION

SSIS - Package en blanco

Como solucionarlo: 1. Renombrar Package 2. Guardar package 3. Cerrar Solución.