|
Seems like another good answer. What is the purpose of the AttrId column in the PersonAttr table? A simple primary key? Or is it foreign key for another table?
|
|
|
|
|
EVERY table needs a primary key (in an OLTP database) so the AttrID is an IDENTITY field and is the primary key.
Note the format (int) is a convention, some like GUIDs but I can't stand them. I also insist the primary key field is the FIRST field added to the table and is the table name + 'ID' so it should have been 'PersonAttrID'
When you have 100s of table you do not want to have to chasing down the name of the PK field for each.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I am with you on the guid issue, unnecessarily complicated. I see no reason to go further than an identity field. This project is MySql and CakePHP, so it dictates it's own naming convention for tables and columns and such. Well, you can get around it but it requires unnecessary code to get around.
Anyways, thank you for the guidance I am going to go with person table, attribute table and then third table that has id, person_id, attr_id, and attr_value. Is this really a true many to many relationship, adding the attr_value column to the joining table?
|
|
|
|
|
One more question about this: for fields that are common to all role types and mandatory, would you encourage adding those to the person table? For example, email address, age?
|
|
|
|
|
Normally yes, at least for data that's directly connected to the person, such as age, weight and length and such.
But while an email address might be personal, it might also be connected to the work role, and a person might also have more than one email address. And so on.
It depends on the purpose of your application, and how it might change in the future. Always plan ahead.
<edit>fixed typo</edit>
modified 21-Jan-12 17:09pm.
|
|
|
|
|
Mycroft Holmes wrote: When you have 100s of table you do not want to have to chasing down the name of the PK field for each.
Well perhaps if you bill by the hour you might.
|
|
|
|
|
I would use you solution but with a slight change. I would include all columns common to Client and lawyer in the user class. i.e First, Last. If there are few columns that are different for Client and Lawyer, I would just role everything up to User, and allow nulls for those columns which don't apply to both client and lawyer. You will need some business rules to determine when those null fields should have a value.
|
|
|
|
|
I currently have an application that connects to a local Access 2007 database. The application itself is written within Access (VBA) and uses DAO connectivity.
I connect to the data source and work with linked tables (queries done in similar manner) so that the user interface and VBA code is separate from the data to promote sw maintainability.
What is now desired is the ability for my user to quickly change between data sources. That is, the user can browse his local machine, select an .ACCDB file, and then change his data source for my app - not exiting out of the app.
I currently have a kludgy way to do this (still all in DAO) that requires exiting out of the application for the change to take effect.
Would an ODBC configuration provide an easier solution? In ODBC, you establish the connectivity ahead of time, BUT you have the ability to change the Database (data source) under User DSN, Configure, Select Database.
FURTHERMORE, the data may migrate to a server-based repository (SQL Server, Oracle, etc...) This may/WILL dictate me switching to ADO.
Any suggestion on how to simplify the selecting of databases?
Thank you.
|
|
|
|
|
I would migrate to .net and make it DB agnostic using DBProviderFactories[^].
Then you can choose your poison in the app.config <connectionstrings> section.
|
|
|
|
|
I have purchased Visual Studio 2010 Professional.
Along with it SQL server express 2008 R2 has been installed, but I cannot find "SQL Server Management Studio". May be it may not be needed also.But for learning purpose I need it. If I download
from MSDN ,I will get SQL express 2005 and may be I will land in conflict. Please help me on this issue. Also I want to know is there
ADO.NET connectivity for VC++ also ?
Be Happy
|
|
|
|
|
adityarao31 wrote: I cannot find "SQL Server Management Studio".
Try here[^].
adityarao31 wrote: is there ADO.NET connectivity for VC++ also
It depends. If you are coding in CLI/CLR, then yes. If it's MFC, etc, no.
|
|
|
|
|
Thank you very much
Be Happy
|
|
|
|
|
I have two tables. I want to get all the rows from first table but want the where clause from another table. Here is my query. In following query I don't want any row from table tbTasks1 but the following query showing me rows from tbTasks1 also. Could u please modify this query.
select * from tbDocument,tbTasks1
where
tbTasks1.IsDelete = 0
|
|
|
|
|
There must be something that joins the two tables together... what is it? Use a join to attach the tables together like this:
select tbDocument.*
from tbDocument inner join tbTasks1 on tbDocument.FOREIGNKEY = tbTasks1.PRIMARYKEY
where tbTasks1.IsDelete = 0
|
|
|
|
|
This will give same result as op's Query...
The op's Query is using implicit inner join.
Rather than inner join, Left Or Right Join will work for op's requirement.
"Insanity is doing the same thing over and over again but expecting different results.” — Rita Mae Brown
"If you tell the truth, you don't need to remember anything" - Mark Twain
modified 19-Jan-12 3:59am.
|
|
|
|
|
V@rsh@ wrote: This will give same result as op's Query
No, it won't. There is a big difference between these two queries:
select * from tbDocument,tbTasks1
where
tbTasks1.IsDelete = 0
select tbDocument.*
from tbDocument inner join tbTasks1 on tbDocument.FOREIGNKEY = tbTasks1.PRIMARYKEY
where tbTasks1.IsDelete = 0
The first one is called a "cartesian join" and is almost always a mistake.
|
|
|
|
|
Agreed op has not used any condition to join both tables in the "Where" clause because of which it uses Cartesian product rather than Inner Join... My fault
But it will be same as
Select * from tab1
Inner Join tab2 on 1=1
where tab2.somefield=somevalue
So I think that was actually representing implicit inner join which uses cartesian product
"Insanity is doing the same thing over and over again but expecting different results.” — Rita Mae Brown
"If you tell the truth, you don't need to remember anything" - Mark Twain
|
|
|
|
|
Try this Query :
Select * from tbDocument
Left join tbTasks1 On tbDocument.Column=tbTasks1.Column and tbTasks1.IsDelete = 0
Your Query is using implicit inner join & inner Join by default applies condition (Filters) on Both tables. You need to use Left Join Or Right Join for you requirement.
"Insanity is doing the same thing over and over again but expecting different results.” — Rita Mae Brown
"If you tell the truth, you don't need to remember anything" - Mark Twain
|
|
|
|
|
I'm not sure what you mean when you say that you don't want any rows from tbTasks1. I assume that you mean that you don't want to see the tbTasks1 columns in your result set. In which case you should specify which columns you want, something like:
select tbDocument.col1, tbDocument.col2, tbDocument.col3
from tbDocument inner join tbTasks1
on tbDocument.aKey = tbTasks.aKey
where tbTasks1.IsDelete = 0
Edit: which I've just realised is exactly the same answer Damian gave earlier. Doh!
|
|
|
|
|
if both the tables having same structure
u can use
select * from tbDocument
union all
select * from tbTasks1
where
tbTasks1.IsDelete = 0
|
|
|
|
|
You could use
SELECT Col1.T1, Col2.T1, Col3.T1
FROM table1 T1 join table2 T2
ON T1.Col1=Coln.T2
OR
SELECT Col1.T1, Col2.T1, Col3.T1
FROM table1 T1
WHERE COL1 in (SELECT Col1 FROM table 2 where Coln=something1 and colm=somethingelse and yadayada)
|
|
|
|
|
Hi all,
Facing this weird error message,
---
Msg 601, Sev 12, State 3, Line 1 : Could not continue scan with NOLOCK due to data movement. [SQLSTATE 42000]
---
It happens during an insert:
INSERT INTO my_table(field1, field2)
SELECT field1, field2
FROM v_my_table WITH (NoLock)
If anyone has any insight that would be much appreciated!
Thanks for your time!
|
|
|
|
|
Wikipedia may be in a black-out but google isn't.
Anyway, I found this[^]
|
|
|
|
|
Remove the NOLOCK; the insert is messing up some reads.
Bastard Programmer from Hell
|
|
|
|
|
Hi all,
I've often wondered about this and always simply worked my way around the issue but I would be curious to know what the correct approach is.
Say I have a stored proc like so:
CREATE PROCEDURE myStoredProc
@myFirstParam INT = 0,
@mySecondParam INT = 0
AS
BEGIN
END
Now I want to call this proc, let's say from another proc where there is a local variable with the name @myLocalVar . I want to pass the value of that local variable to the second parameter of the stored proc so I call it as follows:
EXEC myStoredProc @mySecondParam = @myLocalVar
So far so good, but what if the name of that local variable was @mySecondParam (the same as the parameter name of the proc)? The following won't work:
EXEC myStoredProc @mySecondParam = @mySecondParam
So do I really have to create a new local variable with a different name so that I can pass it to the proc?
DECLARE @myNewVariable INT;
SET @myNewVariable = @mySecondParam;
EXEC myStoredProc @mySecondParam = @myNewVariable
Or is there a way I can pass a variable to a proc if the variable has the same name as the parameter name of the proc?
PS. I'm deliberately using an example where the first parameter of the proc is ommitted because I'm specifically interested in the scenario where the parameter names of a stored proc has to be specified (i.e. not inferred by their order).
|
|
|
|