|
i have two tables
ROOM(nbROOM primary key) : ML002
STUDENT(nbROOM) : ML002
How can i change the ROOM(nbROMM) : ML002 => ML003
=========> the STUDENT(nbROOM) must also change : ML002 =>ML003 ?
|
|
|
|
|
Simple - you can't.
The first problem is that you are using business data for keys. And you now know why that is a problem.
Your only solution now requires.
1. Create a new room row with ML003
2. Update STUDENT to point to MLO03.
3. Delete the existing ML002 record.
Second problem is that what you are doing isn't logical anyways. If you have a list of rooms you don't change them unless you are in fact relabeling all of the rooms themselves (ie someone is going down the hallway in the school and putting new numbers on the doors.)
In contrast if a person is assigned to the wrong room or needs to be moved then you update the person, not the room, to indicate the change. (In databases in general there is another way to do this but it wouldn't apply to room assignment.)
Your solution should be
ROOM(primary key, room label): {1, ML002}, {2, ML003}
STUDENT(room primary key): {1}
In the above you would just update '1' in the student record to be a '2'
|
|
|
|
|
^^~ u didn't understand my problem
ROOM(nuROOM primary key, nameROOM)
STUDENT(nuSTUDENT primary key,nameSTUDENT,nuROOM)
this is my database !
|
|
|
|
|
What JSchell is saying is that your database is designed WRONG and you should fix it before you get into even more trouble. Whats more he gave you the ideas of how to fix it.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
lyngocquy wrote: u didn't understand my problem
No you don't understand my reply.
1. Your database design is wrong.
2. This problem is a specific example of why it is wrong.
3. I told you how to do the update with your existing design.
|
|
|
|
|
I am assuming you have a foreign key constraint that is preventing you from modifying the primary key. In that case, insert new records that are based on the existing records, but with the new primary key, then delete the old records.
|
|
|
|
|
It's called "cascade on update", and it's a bad habit. You'd really provide an artificial key to make the reference. It'd be wise to use an alternative unique constraint for the primary identification of the BO.
Bastard Programmer from Hell
|
|
|
|
|
We have a DB that was migrated from MS Access to SQL Server 2008 R2. I wanted to continue to use Access as a front end to the DB since users are comfortable with it. But Access is unable to open the database without crashing frequently, corrupting tables, etc. etc.
There are tables that are linked to other tables (iCommodity is an int key to Commodity.ID etc.) The largest table is 250,000 records ~ 100MB.
It appears that most of the issues revolve around extended properties. Erasing them gets Access to work temporarily but it usually crashes again after re-writing the properties.
Is there any known issue that causes this behavior? What do other people do? I can write a application to get into the data but it seems ridiculous that Access can't even open a table without crashing.
Thx
Mark Jackson
|
|
|
|
|
mjackson11 wrote: Is there any known issue that causes this behavior?
Yup. Access tries to get everything into memory.
But why stick to Access? You could migrate away from a bloated client to a cleaner UX using just about any other language. I think VB3+ODBC gave better control then Access [as a UI] ever did.
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
Have a bit more patience with newbies. Of course some of them act dumb -- they're often *students*, for heaven's sake. -- (Terry Pratchett, alt.fan.pratchett)
|
|
|
|
|
Can you post a sample of the code which is causing Access to crash ?
Are you accessing the SQL tables via Access linked tables ?
Are you sure that you are fetching only the data you need and not entire tables ?
Maybe I can offer some options that can get you over these pain-points without an entire application re-write.
|
|
|
|
|
Oh so now YOU want him to snd codz plz
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
There is no source code as the tables are linked directly to the SQL server. Access crashes if you try to open the table. It works for smaller tables but once you get past 50-60 MB it gets very dicey about crashing.
I suspect it is pulling entire tables.
|
|
|
|
|
mjackson11 wrote: What do other people do?
Typically no one with any choice would use Access as a front end, you are going to have to upset your users, unless that is you want to write the UI to match the look and feel of Access. I can think of worse fates for a developer but not many.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
mjackson11 wrote: What do other people do?
Per the other suggest that MS Access attempts to load all of it....
If that is the case then create a view(s) that limits the data set greatly. And link to that.
|
|
|
|
|
Hello,
And thanks in advance for the help.
I am using this query to group exams and count:
SELECT BPG.[GroupName], COUNT(A.[ProcedureID]) AS [Count]
FROM
[DB].[dbo].[Accessions] A
INNER JOIN [DB].[dbo].[table1] BP ON A.[ProcedureID] = BP.[ProcedureID]
INNER JOIN [DB].[dbo].[table2] BPG ON BP.[ProcedureGroup] = BPG.[ProcedureGroupID]
INNER JOIN [DB].[dbo].[table3] O ON A.[OrderID] = O.[OrderID]
INNER JOIN [DB].[dbo].[table4] F ON O.[OrderingFacilityID] = F.[FacilityID]
WHERE
--XRAY,US,PICC,EKG
(BPG.[GroupName] IN ('XRAY','EKG','US','PICC'))
AND
(F.[Name] LIKE '%' + @Facility + '%')
AND
(A.[ExamDate] >= CONVERT(DATETIME, @StartDate + @Year) AND A.[ExamDate] < CONVERT(DATETIME, @EndDate + @Year)
AND
(A.[Status] != 'Cancelled' AND A.[Status] != 'ADMIN CANCEL' AND A.[Status] != 'Cancelled - Dry Run'))
GROUP BY BPG.[GroupName]
Let's say the query only returns 'XRAY' and 'EKG' with a count. How can I also return that 'US' and 'PICC' have zero count.
Thanks for the help.
|
|
|
|
|
Try to change join condition and see if you get result which you need.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.cacttus.com
|
|
|
|
|
Thank you. I am not sure what to change and that is why I asked for help.
|
|
|
|
|
RadioButton wrote: INNER JOIN [DB].[dbo].[table1] BP ON A.[ProcedureID] = BP.[ProcedureID]
I think this should be LEFT OUTER JOIN instead. Also you should change the count to be
count(nvl(a.ProcedureID,0)) so the NULL values will be counted as zero.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
I tried your suggestion and that did not change anything. I am using MS SQL 2008 and the NVL function does not appear to be avaible so I tried the ISNULL function. I believe it does the same thing.
Thanks again.
|
|
|
|
|
Connect to the BPG table and all of its inner joins first.
Then do a LEFT OUTER JOIN to your Accessions (A) table and it's joins.
This will give you all of the group names and the 0's if there is nothing for that group.
SELECT BPG.[GroupName], COUNT(A.[ProcedureID]) AS [Count]
FROM
[DB].[dbo].[table2] BPG
LEFT OUTER JOIN
([DB].[dbo].[Accessions] A
INNER JOIN [DB].[dbo].[table1] BP ON A.[ProcedureID] = BP.[ProcedureID]
INNER JOIN [DB].[dbo].[table3] O ON A.[OrderID] = O.[OrderID]
INNER JOIN [DB].[dbo].[table4] F ON O.[OrderingFacilityID] = F.[FacilityID]
)
ON BP.[ProcedureGroup] = BPG.[ProcedureGroupID]
WHERE
.....
GROUP BY BPG.[GroupName]
Brent
|
|
|
|
|
Hi
I need to write trigger for more than one table i.e single trigger for multiple tables,user can not update,delete,insert on tables.If user try to modify on sql server table need to show alert.
I tried with after trigger for single table , it works fine .please suggest me better way.
regards,
Vishnu.
|
|
|
|
|
As far as I know you can't but this thread has come up with a possible solution that you could use assuming the code in the trigger is the same for all tables
Single Trigger on multiple tables[^]
Basically the solution they are suggesting is to have the triggers call a common stored proc
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
vishnukamath wrote: user can not update,delete,insert on tables.If user try to modify on sql server table need to show alert.
Database permissions were designed specifically for what you are looking for. If you are implementing access controls using triggers, I would say that is not a good idea.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
There is table contain
ID Qty
----------
1 2
2 4
3 1
4 5
Now if i had to choose rows where sum of Qty equals to 10, How can i do this ?
like 2+4+1 = 7 but if i add 5 then 12
so ignore 2, then 4+1+5 = 10
How can i achieve this ?
I want id's of that rows which contain combination/sum equal to 10 (number i put)
|
|
|
|
|
declare @qty as decimal(18,2)<br />
set @qty=(select qty from mytable where id=4)<br />
<br />
select sum(qty)-@qty<br />
from myTable
By this example you will have result: 2+4+1=7
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.cacttus.com
|
|
|
|