Re: Updating linked tables

From: Wayne Snyder (wayne.nospam.snyder_at_mariner-usa.com)
Date: 08/11/04


Date: Wed, 11 Aug 2004 08:16:46 -0400

An outer join is the way to go...

I would an FK constraint on the second table as well, so no one deletes the
parent, leaving an orphan child.

Regarding the update, I would test ...
some people check for existence then do the appropriate thing Insert or
update
others simply attempt the update, and on failure do an insert,

But I don't think anyone would recommend the delete, insert option...

-- 
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"NoelH" <NoelH@discussions.microsoft.com> wrote in message
news:1B17DE38-0C74-4D6A-84D3-B2F8501D2A01@microsoft.com...
>
> I have a users table that stores basic information for all users. Then I
> created a second tables like tbl_UsersMarried to store the extra
information
> that only married users have. Only 40% of the users are married. I'm just
> using married as an example.
>
> 1) I have a few tables like tbl_UsersMarried. I can create a view that
outer
> joins those table so I can select all users and all of their information.
Is
> there a more efficient way to do this than using outer joins?
>
> 3) Every time a user updates there Married information I need to check if
a
> record in tbl_UsersMarried already exists for that user so I know if I
should
> Update the Record or Insert a new one. Would it be better to do a delete
on
> tbl_UsersMarried for that user whether they have a record or not and just
do
> an insert?
>
>
> CREATE TABLE tbl_Users (
> UserID INT IDENTITY (1, 1) NOT NULL PRIMARY KEY ,
> FirstName VARCHAR (20) NOT NULL ,
> LastName VARCHAR (20) NOT NULL ,
> Email VARCHAR (50) NOT NULL ,
> ... );
>
> CREATE TABLE tbl_UsersMarried (
> UserID INT NOT NULL PRIMARY KEY ,
> DateMarried DATETIME NOT NULL ,
> State VARCHAR (2) NOT NULL ,
> ... );
>
>
> Thanks in advance for any advise you can give me.
>


Relevant Pages

  • Re: Conversion error
    ... You canimport both types of data into a varchar column now. ... Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP) ... www.SQLDTS.com - The site for all your DTS needs. ... >>character data has to be one or the other. ...
    (microsoft.public.sqlserver.dts)
  • Re: MSDE database too big
    ... It seems strange that I have so much data ... MsgId varchar 200 ... >> Tibor Karaszi, SQL Server MVP ... >>> Guoqi Zheng ...
    (microsoft.public.sqlserver.server)
  • Re: SQL Question for Conversion
    ... SQL Server MVP ... > convert the varchar column to an integer because integer has a higher data ... > comparison rules. ... >> Error converting data type varchar to int. ...
    (microsoft.public.sqlserver.programming)
  • Re: LEFT OUTER JOIN possible in DB2?
    ... i was trying to get a customer to create a view on their IBM thingy. ... Now, OS/400 comes with its own DBMS, which I assume is at a lower level that an RDBMS, like DB2 or SQL Server. ... > Turns out a LEFT OUTER join is sorta possible in IBM/DB2/AS/400. ...
    (microsoft.public.sqlserver.programming)
  • Re: Maintaining Field Length in .txt format
    ... If the types are VARCHAR, ... converts them to CHAR types. ... >are on a SQL Server 2000 environment and I can create ... The header information for the feed to be ...
    (microsoft.public.sqlserver.programming)