473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Communication betwee two tables

Hai,

I am having a query that i want to communicate two tables that
one is school table & other is class table as shown below
school table:
Class strength
LKG 30
UKG 40
class table:(LKG)
Rollno name
1 rohit
2 baba

Now my query is that as i defined strength of the LKG class as 30, if
i insert 31st in to LKG i need to get error, that not to enter. That
implies that when i am going to enter 31 student in LKG table it should
not accept asthe data corresponding to the school table.Is it possible,
if it say the coding, as i am new to SQL plz help me in coding.

thanks,
lucky.

Mar 15 '06 #1
2 1377
lucky (j.**********@gmail.com) writes:
I am having a query that i want to communicate two tables that
one is school table & other is class table as shown below
school table:
Class strength
LKG 30
UKG 40
class table:(LKG)
Rollno name
1 rohit
2 baba

Now my query is that as i defined strength of the LKG class as 30, if
i insert 31st in to LKG i need to get error, that not to enter. That
implies that when i am going to enter 31 student in LKG table it should
not accept asthe data corresponding to the school table.Is it possible,
if it say the coding, as i am new to SQL plz help me in coding.


Wait here, you are saying that you have one table LKG, one table UKG etc?
That is not a correct design. Rather you should have a table classes
with a primary key (classcode, rollno).

Once there, you can have a trigger on the classes table:

CREATE TRIGGER class_tri ON classes FOR INSERT, UPDATE AS
IF EXISTS (SELECT *
FROM school s
JOIN (SELECT c.classcode, cnt = COUNT(*)
FROM classes c
WHERE EXISTS (SELECT *
FROM inserted i
WHERE i.classcode = c.classcode)) AS c
ON s.class = c.classcode
WHERE c.cnt > s.strength)
BEGIN
ROLLBACK TRANSACTION
RAISERROR('One or more classes are over-booked.', 16, 1)
RETURN
END
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Mar 15 '06 #2
homework.

Mar 15 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Noel | last post by:
Hi, I am a tad confused about if there are any benefits from using asynchronous vs synchronous network communication. As my example, I have been writing a dns lookup stack with a network...
1
by: alederer | last post by:
Hallo! I have the following situation: A db2 v6.1 client on AIX 4.3 (db2level reports U469703) and a OS/390 database version 6.1 . In some situations, I get the following error in my db2...
3
by: Tim Reynolds | last post by:
I support a .Net application running on a SERVER accessing MF Db2 data. Occasionally, we have some type of connection problem that we have been unable to debug up to this point. We typically...
3
by: Bryan Christopher | last post by:
Hello All! I have a rather abstract question for some genius out there to answer. I want to integrate communication tracking, for customer relations, into an existing Access DB. What I was going...
2
by: xeyder | last post by:
Hi everyone.. I need help about graph theory ( network problems) .. I have below problem . Does anyone know any existence algorithms or solutions to this problem ?? The Problems is: "...
4
by: Sačo Zagoranski | last post by:
Hi! I'm writing a simple 3D First person shooter game. It is a multiplayer game, where all the players connect to one server.
21
by: dast | last post by:
Hi, I'm having trouble letting my background thread tell my main thread what to do. I'm trying to tell my main thread to open a form, but when my background thread ends, the form that I...
2
by: xeyder | last post by:
Hi everyone.. I need help about graph theory ( network problems) .. I have below problem . Does anyone know any existence algorithms or solutions to this problem ?? The Problems is: " We...
0
by: lucky | last post by:
Hai, I am having a query that i want to communicate two tables that is one is school table & other is class table as shown below school table: Class strength LKG 30 UKG ...
0
by: mohsinnazir | last post by:
Hello Experts, I am using remote replication in sql server 2005.It is huge database some of the tables replicated ok but after one houre i received an error "TCP Provider: The specified network name...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.