Design Question, Trigger Or SP [SQL Server 2005]

May 24, 2008



[SQL Server 2005]



In our system we keep track on all changes that are made by the users.

This means that posts is never deleted, only marked as not "active".

Each table has a SP who takes care of the INSERT/UPDATE.

This SP also calls another SP, which actually does the "inactive" marking of the post.

The question is:

Would it be better (or worse) to have a TRIGGER taking care of this instead?

Occasionally there are data inserted at the "exact" same time (different input sources).
Sometimes there can be a quite heavy workload on the INSERT.



/HÃ¥kan

View 8 Replies


ADVERTISEMENT

DB Design :: View Or Trigger

Jun 10, 2015

i have a question about updating views:for example: lets assume we have a table which keep the users score and we have a view which created from so many tables and calculate the sum of the users scores. now if one of the user's score changes all the view created again or just part of the view will update?i ask this to find out how can i design my database? how can calculate users scores?i can wrote a trigger to do it or use the view. which way is faster and better in this case?

View 9 Replies View Related

Database Design In SQL Server 2005

Jan 11, 2007

HiI am facing a problem in designing a database for my project.Please help
I have hotel Information.The hotel allocates rooms for my company.This is done on weekly basis.
Now suppose in first week of a year the number of rooms allocated to the company is 3,2ndweek =5,3rdWeek=5 and so on...
So when i search based on a week i should have one result setIf i search based on MOnth i should have one result set.. in this way.
So what fields i need to take in a database table so that when i search based on week /month/quarter/year i get different resultsets.

View 6 Replies View Related

Design Question SQL Server 2005

Apr 4, 2006

I am very new to SQL Server 2005. I have a database of criminal records consisting of a master table of names where the primary key is a case number and 3 related minor tables: violations, charges, and appeals. They are linked by the case number with a one-to-many relationship. Not all of these tables have a record for every master record.

I am designing a simple lookup program in VB 2005 in which info from all tables will be on one screen. A search will be done on either name or case number.

What is the best way so set up views and/or stored procs for such a program? Do I need a stored proc for each minor table or is there a way to set up one proc to pull all of the info? Did I mention I was new at this? I have worked a lot with Access and recognize just enough things in SQL Server to be really confused.

Thanks for the help!

View 1 Replies View Related

Need Help With Trigger Sql Server 2005

Oct 16, 2006

I am trying to create this trigger

CREATE TRIGGER User_Insert ON aspnet_users AFTER UPDATE AS
IF UPDATE (UserId)
insert into users (aspnet_user_id, username)
select au.userid, au.username
from aspnet_users au
where au.userid != users.aspnet_user_id;

Whenever the aspnet_users table has a new user added I want the Userid and username fields from that table inserted into the
the aspnet_user_id and username fileds of the users table.

when creating the trigger I get the following error..

Msg 4104, Level 16, State 1, Procedure User_Insert, Line 3
The multi-part identifier "users.aspnet_user_id" could not be bound.

View 6 Replies View Related

SQL 2005 Server && CLR Trigger...

Oct 15, 2007

Hello,

I'm having problems with a CLR Trigger trying to get it to work with SQL Server... and i believe it is because permissions... basicly i want to make my trigger get the name of a newly created database and then look for
a table and then see if is empty... then add some rows... thats all...

I have set my databases as Trustworthy and also i have enabled the "clr enabled" parameter...
i mark my project as "Safe" in the Project properties... and it still doesn't work... do i need to
sign my project..? if so.. how?

i'm clueless...

Thank You.!




Code Block
'Table_1' table
- Unable to create table.
A .NET Framework error occurred during execution of user-defined routine or aggregate "Trigger1":
System.Security.HostProtectionException: Attempted to perform an operation that was forbidden by the CLR host.
The protected resources (only available with full trust) were: All
The demanded resources were: UI
System.Security.HostProtectionException:
at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed)
at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object assemblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed)
at System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Object assemblyOrString, SecurityAction action, Boolean throwException)
at System.Security.CodeAccessSecurityEngine.CheckSetHelper(CompressedStack cs, PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Assembly asm, SecurityAction action)
at Triggers.Trigger1()
.
The statement has been terminated.


View 3 Replies View Related

Does SQL Server 2005 Exsit The Trigger ?

Jan 15, 2007

When the database starts,I want to startup a trigger to do something,how can I do ?
I know there are two kinds of trigger in SQL Server 2005 ,one is DML trigger and the another is DDL trigger
Could you tell me ,Is there a trigger for database level in SQL Server 2005 ?
I know there is this kind of trigger in oracle .

View 3 Replies View Related

How Can I Debug A Trigger In SQL Server 2005?

Jan 10, 2008

Hello,I have a form in a web application. When I submit the form it inserts the record into the SQL Server 2005 database. I have an insert trigger. My question is how can i debug the trigger? the trigger then calls a CLR based stored procedure, again how can i debug this CLR stored procedure which gets called by the trigger. Thanks...kindly advice. 

View 2 Replies View Related

Sql Server 2005 + Row Level Trigger

Jul 18, 2006

hi
i want to know if row level trigger works with sql 2005.
because in 2000.. only statement level trigger was used.

Thks in advance.

View 3 Replies View Related

Sql Server 2005 + Row Level Trigger

Jul 19, 2006

hi
actually i have a temporay table wich has four columns
say col_1,col_2,col_3,col_4.
so firstly i wud bulk insert from a text file wich mite contain thousands of rows.
then from this temp table col_1 and col_2 shd go to master_a.wich has an identiy column as primary key.
say id,col_1, col_2.

i will have another table detail_b where in there is a foreign key to the table master_a for id.
so it will have f_id, col_3,col_4.

so i am riting a trigger on master_a. so whenver row is inserted in master_a. coresponding id and col 3 col4 shd be inserted into detail_b.

For this in oracle we have row level trigger. where in for each insertion in master a .. correspoding trigger will fire but in sql 2000..
but i wud like to implemtn row level trigger..
can u hlep me out..

View 1 Replies View Related

SQL Server 2005: TRIGGER AFTER INSERT

Mar 22, 2006

Hello,I am learning SQL Server 2005.I need to create a trigger which increments number of book'spublications:CREATE TRIGGER InsertPublicationON PublicationsAFTER INSERTASBEGINSET NOCOUNT ON;DECLARE @Num smallintSET @Num = SELECT NumPublications FROM Books WHERE ISBN IN(SELECT ISBN FROM inserted);UPDATE BooksSET NumPublications = @Num + 1WHERE ISBN IN(SELECT ISBN FROM inserted);ENDUnfortunately I receive a message:Incorrect syntax near the keyword 'SELECT'.Could you explain me please how to correct the code?I am new to SQL Server.Thank you very much./RAM/

View 2 Replies View Related

SQL SERVER 2005 INSTED OF Trigger

Jun 23, 2005

Hi.

View 4 Replies View Related

(SQL Server 2005) Instead Of Delete Trigger

May 31, 2006

Hi,

I simply need a trigger to delete some datasets from a view but have some trouble writing an adequate trigger. Here is my attempt:

Use myDB;
Go
CREATE TRIGGER IO_Trig_Del_myView ON myView
INSTEAD OF Delete
AS
BEGIN
SET NOCOUNT ON
-- Check for dataset, if present delete.
IF (EXISTS (SELECT Z.[myPk]
FROM myTable t, deleted
WHERE t.[myPk] = deleted.[myPk]))
Delete From myTable
Where myTable.[myPk] = deleted.[myPk]...

This causes the following failure:

Msg 4104, Level 16, State 1, Procedure IO_Trig_Del_myView, Line 11
The multi-part identifier "deleted.myPK" could not be bound.

Can somebody explain the reason to me? myPk is part of the View I created. Since I do have three tables in myView so I get that message three times, once per table.

View 5 Replies View Related

SQL Server 2005 Query/trigger/function (whatever It Is That I Need)

Dec 8, 2006

Hey guys maybe you can help me out, been trying to figure this one out all day at work. I know how to use columns in a table to calculate another column in that same table. But I need to do some math on columns from a totally seperate table. Here is my scenario
 table 1 = stock table
 table 2 = Purchase order table
 in table 2 there are line items that have ordered quantities for parts that we have ordered
 in table 1 under each part number is a field for "quantity on order"
I need to compute the "quantity on order" in table 1 by summing all of the quantities in table 2 where the partnumber = the partnumber from table 1
 
quantity on order (table 1) = sum of all quantities (table 2) where the part numbers match
so for part number 516 i have this
 
table 2
poNumber             partNumber                 quantity
1                             516                             1
2                             516                             12
3                             516                             4
 
table 1
partNumber            inStock              onOrder
516                          0                        17(this is what i am trying to figure out how to compute)
 
any help on this qould be appreciated. I would like the database to automatically do this itself if at all possible.

View 3 Replies View Related

Possible Trigger Problem SQL Server 2005 Express

Apr 7, 2008

 Hey guys,

I have a problem regarding (if it’s the
right way to go about it) triggers in SQL Server 2005 Express. I have already finished
my application but wanted to add this in. My system is a shipping system which
allows users to add data about ships, orders etc. In order for a order to be “put
on� a ship I have created a form which first allows users to select what order
and what ship and then creates a new entry on a table called OrdersonShip. What
I would like my code to do is first check that there is space on the ship (Each
ship has a maxCargo and a currentCargo) and then when the new entry on the
OrdersonShip table is produced I would like the numberofitems field on the
order to be associated with the ship to be added to the currentCargo on the
ship table. How would I go about this?

 Many
thanks for any help you can give me.

Peter

 

View 7 Replies View Related

Simple Trigger For SQL Server Express 2005

Jun 12, 2008

I've this tableCREATE TABLE [dbo].[Attivita]( [IDAttivita] [int] IDENTITY(1,1) NOT NULL, [IDOwner] [int] NULL, [IDAttivitaStato] [varchar](1) COLLATE Latin1_General_CI_AS NULL, [IDAttivitaTipo] [varchar](2) COLLATE Latin1_General_CI_AS NULL, [IDAnagrafica] [int] NULL, [Data] [datetime] NULL CONSTRAINT [DF_Attivita_Data] DEFAULT (getdate()), [Descrizione] [varchar](max) COLLATE Latin1_General_CI_AS NULL, [Privato] [bit] NULL, [LastUpdate] [datetime] NULL CONSTRAINT [DF_Attivita_LastUpdate] DEFAULT (getdate()), CONSTRAINT [PK_Attivita] PRIMARY KEY CLUSTERED ( [IDAttivita] ASC)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]) ON [PRIMARY]How Can I create a trigger for modify the IDAttività Stato field in specific situaion: if IDAttivitaTipo ==  OK or  == NOIDAttivitaStato must be set to CPlease note that I can write in the IDAttivitaStato field (during my code operation).... but I would like also automatic update if the IDAttivitaTipo is OK or NO Can you help me for create this with a trigger?Thanks 

View 2 Replies View Related

SQL Server 2005 Trigger Or Stored Procedure

Apr 10, 2008

I need to create either a trigger or stored procedure in SQL server 2005(hopefully someone can tell me).. Here is what I need to happen: I have a table with orders that are generated from a website. After the transaction is completed, I need have the record that was just created also copy to another table. There is a field called flag and the values in this field are either 1 or 2. Imediatly after the transaction occurs, I need the records where flag = 1 to copy to this other table. How would I go about doing this?

View 10 Replies View Related

How Can A Trigger Act Asynchronously To The Event That Fired It In Sql Server 2005?

Sep 12, 2007

if service broker is not an option, how can the trigger and sp(s) called by our trigger act asynchronously to the event that fired the trigger in the first place. We are more concerned with the original event being committed than the actions that follow via the trigger.

View 4 Replies View Related

SQL Server 2005 Trigger Fires Per Statement Or Per Record

May 3, 2006

Hi

In SQL Server 2005, does TRIGGER for DML fire per statement or per Record ?

If both, can we define the way it should fires.

thanks / ramanuj

View 11 Replies View Related

Crear Archivo De Texto Desde Trigger En SQL SERVER 2005

Jan 16, 2008



Necesito crear un archivo .txt con cierto texto cada vez que se ejecuta el trigger. Quisiera saber como hacerlo.
Gracias

View 5 Replies View Related

MS SQL 2005 Express DB Design Question. Please Help.

Dec 8, 2005

Hi all! I was given the task by my father who wants me to create an appointment DB for his new law firm and I can't seem to figure out what to do with the Appointment table. I've been stuck on this problem for well a week trying to google the answer to no avail.

Here's my design so far:
I have created 3 tables. One for Employees, one for Clients and one for Appointments(going to trials, meeting with the clients etc). The Employees table has the EmployeeID as the primary key and the Clients table has the Telephone as the Primary Key. The Appointment table has two foreign keys and no Primary key with one FK linking to the Clients_Telephone and the other FK linking to the Employee_EmployeeID.

What I want to accomplish:
A client calls and wants to set an appointment, the receptionist will take the information and query the appointment table to see if one of the partner named Anderson is busy at, say, 3:00PM to 4:00PM on a certain day. If he is then the information will not be applied and my GUI interface will display an error, if he is available then the information is set into the table.

I think I'm to use Domain Constraint, but the logic is very fuzzy to me. Thanks!

View 4 Replies View Related

SQL 2005 Database Design (Table Names)

Apr 14, 2006

In the past, we had table names such as:
PurchaseOrders
SalesOrders

Now with SQL 2005, you can use schema namespaces, so it could become:
Purchasing.Orders
Sales.Orders

So essentially you can use exactly the SAME table names, in different schemas.

So... would you recommend to change to the last model, or just stay with the old way?
What is best practice?



One of the reasons why I ask this question is that I looked at the AdventureWorks sample database included with SQL Server 2005, and Microsoft is using:

Sales.SalesOrderDetail
Purchasing.PurchaseOrderDetail
etc...

Why not:
Sales.OrderDetail
Purchasing.OrderDetail
etc...

????????

View 1 Replies View Related

Error During Setup Of Microsoft Sql Express 2005 Edition For Visual Web Design?

Oct 11, 2006

error saying disk compressed or encryted, choose another drive?

how should i t-shoot !!!!!

View 1 Replies View Related

Sql 2005 Trigger - Newbie

Jul 10, 2006

I have two tables "Inventory" and "Product". User creates a product then assignes inventory to that product.
The product table and the inventory table both have the same two fields, "GDS" and "prodID" and both share the same field and value of ProductID.
I'm trying to create a trigger for the Inventory table so when the Inventory table has an update or insert,
the values from Product.GDS and Product.prodID values go into the Inventory's record for Inventory.GDS and Inventory.prodID

I an having problems with the trigger as this is my first attempt in creating a trigger.
I have the trigger on the Inventory table and this is what I so far which does not seem to be working, any suggestions (thanks0:


Code:

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER TRIGGER [inv]
ON [dbo].[Inventory]
AFTER INSERT,UPDATE
AS
BEGIN
SET NOCOUNT ON;

Update Inventory
Set GDS = i.GDS, prodID = i.prodId
From Inserted i
Inner Join Inventory inv ON i.ProductID = inv.ProductID
END

View 3 Replies View Related

SQL 2005 : AFTER INSERT - Trigger

Jun 7, 2007

Is it possible to create a trigger in one database, that after aninsert, will update a database on a different server?If so, how would I do this?Thanks.Bill

View 1 Replies View Related

Email Trigger In SQL 2005

Jun 2, 2006

I am new to developing as will be evident from this post. Your help will be greatly appreciated.

I am developing an intranet for our company using ASP.NET with a SQL backend. I am currently working on a suggestion box form.

I would like to have an email sent to specific persons when a new entry is made in the suggestion table. I have been able to configure the trigger and generate the email (This was easy). Formatting the email has proven more difficult to resolve.

The format I would like is somewhat as follows:

F_NAME L_NAME submitted the following suggestion:

IDEA

BENEFIT

APPROVE | DECLINE

The items in RED are columns in the table and the Blue Underlines are hyperlinks to change the Status column in the table.

How can I generate the email to contain the data from the inserted record and in the above format.

Being new at this I only now how to send a static email advising that the entry has been made.

Any help creating the dynamic email form for this trigger will be greatly appreciated.

Lastly, what books are most helpful for SQL, ASP.NET, and VBScript referencing and examples?

Thanks

View 4 Replies View Related

How To Call TRIGGER In VB.net 2005

Sep 26, 2007

i hav written a trigger in SQLEXPRESS DB but i dnt knw how to call in vb.net 2005...

View 2 Replies View Related

Sqlserver 2005 Trigger Error

Oct 17, 2007

hi.......
i create a trigger after delete which work perfactly fine on one sqlserver2005 machine but not at another.......machine having sqlserver2005
this trigger effect 15 tables from which i am deleting data...when trigger fires.....
now it cause following error when i fire ir on another machine
error source: .net sql client data provider
error message:maximun stored procedure,triggers,functions,or view nesting level exceeded (limit 32)
plzzzz give da solution.....its really frustrating me....
thanks in advance

View 5 Replies View Related

How To Save Trigger Into Table In Sql 2005

Dec 22, 2007

I have found the node for Triggers in SQL Server 2005's Management Studio and tried to create a 'New Trigger...' but when I save, it saves it to an .sql file but do not attach it to the table.What am I doing wrong here? I can't seem to attach it. And where is this Assisted Editor ...i can't seem to find it anywhere

View 2 Replies View Related

Sql 2005 Trigger Insert And Dbmail

Apr 23, 2008

I have a stored proc that inserts records into a table, gets the identity, and uses that identity on a .net webpage. The page retrieves that identity key and processes some stuff on the page.

Everything was working fine until I tried to enable sql mail with triggers. I wanted to double-check some stuff, so I requested an sql email be sent whenever an insert occurs on the table above. Here's what I think is happening --- please correct and/or help me out with a work around?

I use the stored proc to insert a record.
I select the @@identity.
The trigger fires but uses select to retrieve the latest insert - thereby replacing the @@identity number returned to the page?

If this is true, could I do something like the following in the original stored proc? Is this a good idea or bad idea?

BEGIN
Declare @myID as int, @myBody1 as varChar(200)
Set @myID=0
INSERT INTO table (fields) VALUES (@PID, more stuff);
Set @myID = SELECT @@IDENTITY As [Identity];
If @myID<>0
Begin
Set @body1='<br />pid=' + more stuff.....
Exec msdb.dbo.sp_send_dbmail
@profile_name='profileName',
@recipients='email@email.com',
@subject='Temp History Insert',
@body=@body1,
@body_format= 'HTML' ;
End
END

View 3 Replies View Related

Why This Trigger Doesn't Work In Sql 2005

Mar 28, 2008

hi eveyrone,

I have an after insert trigger that works in sql2000 but not in sql2005. Can you please help me!!

CREATE trigger dbo.trUPS_tbl_I
on dbo.UPS_tbl
After Insert --For insert
as
declare @Tracking varchar(800),
@UPSID varchar(10),
@Cmmd varchar(800)

select @UPSID = cast(inserted.UPSID as varchar)
from inserted

commit

set @Cmmd = 'c:TasksUpdTrackingUpdateTrackingCS ' + @UPSID + ' ' + 'UPS1'
EXEC master.dbo.xp_cmdshell @Cmmd


The UpdateTrackingCS program will call a stored procedure to get the inserted data and update other databases. And the reason to put the commit statement in sql2000 is to have sql commit the transaction, so the store procedure in UpdateTrackingCS can query thtat inserted records.

When I use the same code in SQL2005, no matter what I do the UpdateTrackingCS program cannot query the data by the UPSID. It always says record not found.

I have tried to change commit to begin trans ... commit trans. But nothing works. Please help!

Thanks in advance.

lyw

View 1 Replies View Related

Why This Trigger Doesn't Work In Sql 2005

Mar 28, 2008

hi eveyrone,

I have an after insert trigger that works in sql2000 but not in sql2005. Can you please help me!!

CREATE trigger dbo.trUPS_tbl_I
on dbo.UPS_tbl
After Insert --For insert
as
declare @Tracking varchar(800),
@UPSID varchar(10),
@Cmmd varchar(800)

select @UPSID = cast(inserted.UPSID as varchar)
from inserted

commit

set @Cmmd = 'c:TasksUpdTrackingUpdateTrackingCS ' + @UPSID + ' ' + 'UPS1'
EXEC master.dbo.xp_cmdshell @Cmmd


The UpdateTrackingCS program will call a stored procedure to get the inserted data and update other databases. And the reason to put the commit statement in sql2000 is to have sql commit the transaction, so the store procedure in UpdateTrackingCS can query thtat inserted records.

When I use the same code in SQL2005, no matter what I do the UpdateTrackingCS program cannot query the data by the UPSID. It always says record not found.

I have tried to change commit to begin trans ... commit trans. But nothing works. Please help!

Thanks in advance.

lyw

View 8 Replies View Related

AFTER INSERT Trigger Not Firing In SQL 2005

Jul 28, 2006

Nothing fancy; just a trigger on a sharepoint table that supposed towrite a record to another SQL table.set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgoALTER TRIGGER [TV_UpdateFileSyncProgress]ON [dbo].[Docs]AFTER INSERTASBEGINSET NOCOUNT ON;BEGINIF EXISTS (SELECT null FROM inserted WHERE DirName like'csm/%/Shared Documents')BEGINIF NOT EXISTS (SELECT null FROM inserted INNER JOINTV_FileSyncProgress fp ON LOWER(RTRIM(fp.LeafName)) =LOWER(RTRIM(Replace(Replace(inserted.DirName,'csm/',''),'/SharedDocuments','') + '' + inserted.LeafName)))BEGININSERT INTO TV_FileSyncProgress (InternalOrigin, ExternalOrigin,ChangeType, SiteId, DirName, LeafName, FlagForDelete)SELECT0,1,1,SiteId,'F:commonExtranet',Replace(Replace (DirName,'csm/',''),'/SharedDocuments','') + '' + LeafName,0 FROM insertedENDENDENDEND

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved