Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Moving from a table to a view

Posted on 2011-09-26
6
Medium Priority
?
166 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
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 1

Author Comment

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

Accepted Solution

by:
JestersGrind earned 2000 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 Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

618 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