June 18, 2013 at 5:40 am
CREATE TABLE [dbo].[patient](
[pid] [nvarchar](50) NOT NULL,
[name] [varchar](50) NOT NULL,
[varchar](50) NOT NULL,
[password] [varchar](50) NOT NULL,
[createdon] [datetime] NOT NULL,
[modifiedon] [datetime] NOT NULL,
[rowstate] [tinyint] NOT NULL,
[Address] [varchar](100) NULL,
[dob] [datetime] NULL,
[phone] [varchar](12) NULL,
CONSTRAINT [PK_patient] PRIMARY KEY CLUSTERED
(
[pid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
)
table2
CREATE TABLE [dbo].[pstatus](
[pstatus] [varchar](50) NOT NULL,
[docstatus] [varchar](50) NOT NULL,
[disease] [varchar](50) NOT NULL,
[bedno] [varchar](3) NOT NULL,
[drugs] [varchar](50) NULL
) ON [PRIMARY]
new table
CREATE TABLE [dbo].[searchp](
[pid] [nvarchar](50) NOT NULL,
[name] [varchar](50) NOT NULL,
[docstatus] [varchar](50) NOT NULL,
[disease] [varchar](50) NOT NULL,
[bedno] [varchar](3) NOT NULL,
[drugs] [varchar](50) NULL,
[docname] [varchar](50) NOT NULL
) ON [PRIMARY]
i want to create a trigger when the values are inserted into the first 2 tables the new table will be automatically updated
thanks in advance
immad
June 18, 2013 at 5:57 am
You will have to create 2 separate triggers on the 2 tables
Inside the trigger you can write the code to update the new table
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
June 18, 2013 at 5:59 am
how i can create a trigger
immad
June 18, 2013 at 6:44 am
immaduddinahmed (6/18/2013)
how i can create a trigger
Its not possible to explain this in a forum post
Please check for articles on Google or Books Inline and I am sure you will get loads of them, I have attached one for your reference
http://msdn.microsoft.com/en-us/library/ms189799.aspx
If you need some real code, we would need more details on how the new table will be updated inside the trigger
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
June 18, 2013 at 6:47 am
Thanks for the help
immad
June 18, 2013 at 6:59 am
I don't think you've provided everything you need, anyway;
i don't see any relationship for the table [pstatus] table to your [patient] table.
your [patient] table should have separate fields for firstname/middle initial/lastname/suffix; it looks like you plan on stuffing it all in a single field right now.
'
that table has a [bedno] table, that should be related to a patient,right? maybe with a start and stop date?
patients often get more than one drug, so i think the [drugs] columns should be a separate table,
right now it looks like whoever sits in a bedno gets the drugs, and not the patient(at least the way i read your schema)
if you are just echoing out whatever is in the two tables your third table should be eliminated completely, and replaced witha view that contains the query to join the two tables together; then the view is always correct, and eliminates a trigger completely.
Lowell
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply