Jump to content

[SQL Server] Trigger - Integridade


mitra-

Recommended Posts

Boas!

Alguém me pode dar umas luzes (exemplos de código) ou links para a criação de Triggers em T-SQL (SQL Server 2000) para manter a integridade nas referências de chaves estrangeiras?

Tenho umas tabelas numa DB que precisam de referenciar chaves em tabelas de outra DB. Se estivessem na mesma DB bastava criar uma CONSTRAINT para FOREIGN KEY REFERENCE, mas como não posso fazer Cross Database References tenho de recorrer a Triggers.

Agredeço desde já qualquer ajuda!  😉

Link to comment
Share on other sites

Tens nesta secção alguns exemplos sobre como se cria um trigger em SQL Server. Por exemplo este aqui:

http://www.portugal-a-programar.pt/index.php?showtopic=12137

Na documentação da Microsoft também mostra, e mesmo na documentação que deves ter no teu PC quando instalas o SQL Server.

"Nunca discutas com um idiota. Eles arrastam-te até ao seu nível e depois ganham-te em experiência"

Link to comment
Share on other sites

Aproveitando esta treadh tenho uma duvida...

Criei um trigger relacionado com um insert numa tabela, mas sempre que tento fazer um insert da me o seguinte erro.. quer no VB.net ou no SQLServer

A .NET Framework error occurred during execution of user-defined routine or aggregate "T":

System.Security.SecurityException: Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

System.Security.SecurityException:

  at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)

  at System.Security.PermissionSet.Demand()

  at System.Data.Common.DbConnectionOptions.DemandPermission()

  at System.Data.SqlClient.SqlConnection.PermissionDemand()

  at System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection outerConnection)

  at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)

  at System.Data.SqlClient.SqlConnection.Open()

  at CLR.Texto_Em_Palavras()

.

The statement has been terminated.

Ja ando de volta disto algum tempo.. se alguem me puder ajudar!!

Cumps

FAÇO TUDO COM DUAS LINHAS DE CÓDIGO;

Link to comment
Share on other sites

Aproveitando esta treadh tenho uma duvida...

Criei um trigger relacionado com um insert numa tabela, mas sempre que tento fazer um insert da me o seguinte erro.. quer no VB.net ou no SQLServer

A .NET Framework error occurred during execution of user-defined routine or aggregate "T":

System.Security.SecurityException: Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

System.Security.SecurityException:

  at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)

  at System.Security.PermissionSet.Demand()

  at System.Data.Common.DbConnectionOptions.DemandPermission()

  at System.Data.SqlClient.SqlConnection.PermissionDemand()

  at System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection outerConnection)

  at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)

  at System.Data.SqlClient.SqlConnection.Open()

  at CLR.Texto_Em_Palavras()

.

The statement has been terminated.

Ja ando de volta disto algum tempo.. se alguem me puder ajudar!!

Cumps

Abre um tópico com a tua dúvida, e coloca o trigger sff.

"Nunca discutas com um idiota. Eles arrastam-te até ao seu nível e depois ganham-te em experiência"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.