Solved

Moving from a table to a view

Posted on 2011-09-26
6
161 Views
Last Modified: 2012-05-12
I have a table that contains user info.  It has a primary key of userid.  I have foreign key constraints in various other tables that reference the userid.   These tables and database are for new applications.

Now, there are legacy apps also use a table of users.  I need to make the legacy apps and new apps use the same list of users.  The legacy apps use one database and the new apps use another, though on the same server.  So, I've created a view in the new apps database that pulls in the necessary user columns from the legacy apps database.  

Now, prior to this, and for development purposes only, I had a temp user table in the new apps database, and I had created foreign key constraints.  Now, if I go with the view idea that I describe above, and remove the users table in the new apps database, I lose referential integrity enforced by the foreign keys, correct?

Questions:  Is this a reasonable approach, to get the two sets of app to use the same set of user data?  If I name the view the same as the user table and use the same column names, will this change be transparent?   Is the loss of referential integrity a small price to pay?  Any suggestions on how to better handle this?  
0
Comment
Question by:HLRosenberger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 36671471
I am not sure that I completely understand your question.  Referential integrity is enforced at the table level, and I don't quite understand what changes you would be making to the tables.
0
 
LVL 1

Author Comment

by:HLRosenberger
ID: 36674470
I would lose the Referential integrity for the userid's in the new database because I'd now create a view in the new database that would pull in the data from the old database.

The new database has other tables that currently have foreign keys to the temporary user table - which would go now go away and be replaced by the new view.  

Did I articulate this properly?

 
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 36675203
Are you saying that you have a linked server, and the view would be referencing data from both databases, without foreign key relationships?
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 1

Author Comment

by:HLRosenberger
ID: 36678363
Not linked.  Two databases on the same server.
0
 
LVL 21

Accepted Solution

by:
JestersGrind earned 500 total points
ID: 36709143
It's not a bad way to go.  It would also be nice if you could have cross database foreign key relationships, then you wouldn't need the view, but that's not an option.  You're exactly right, though.  You are sacrificing referential integrity.  To know the impact of this, you would have to look at everything that references the view.  The danger is that something could be modified that would violate that constraint.  Like a using a userid that isn't in the view.  Most likely, you are probably safe.

Another way to go is to make the view a table so that you can still have referential integrity.  To implement this, you would have to create a stored procedure to synch up the data.  And then run that procedure periodically through a job.  If you only insert and update data in the original users table, this should be fairly easy.  I'm assuming that you set some sort of active flag instead of deleting.  That's always how I setup my users tables because you can't delete users without deleting all of the data associated with them.

Hope this makes sense.  If not, please ask questions.

Greg
0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 36893424
Thanks!
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question