SQL 2008 Management Studio-- where to find table relationships? - sql-server-2008

I'm brand new to SQL Server 2008, and have some newbie questions about the diagram pane. I just dragged two tables onto it to do an inner join, and the console "knew" to create a one-to-many relationship between them. Where is this information kept in the Management Studio for me to look at closer?
Thanks!

Much of this information is actually available in system tables in the database containing the user tables.
Here are two of the available tables of interest. sys.tables contains table information, sys.foreign_keys contains relationship information via foreign key constraints.
sys.tables (Transact-SQL) # MSDN
sys.foreign_keys (Transact-SQL) #MSDN
Also handy is the following information on Pinal Dave's site on using this information for your own lookups.
Find tables with Foreign Key Constraint in Database # SQLAuthority.com
Find Relationship of Primary key and Foreign Key using T-SQL # SQLAuthority.com

One of the tables has a foreign key referencing the other table. In Object Explorer, expand the information for the tables involved and look under Keys.

Related

How to get relationship diagram of primary and foreign key in two tables of a database in sql server

I have a doubt about sql server: how to get primary and foreign keys
of relationship of 2 tables in sql server except the way sp_help table name?
You can use SchemaCrawler to generate a textual representation of your database schema including relationships indicated by foreign keys. You will need to install a Java runtime, though.
Sualeh Fatehi, SchemaCrawler

Remote foriegn key on SQL Server

I am building a database on SQL Server 2014. I have a users table and a profiles table and I need to have a relationship with both these tables. I am relating the userid (primary key on user table) to the profiles table (userid there as foreign key). This is just an example to consider.
What I need to know is, what if the profiles table is on another server instance? Is there a way with which I can link both? The reason is that I don't want to overload the sql server with too many tables and data...
Thanks,
Sarin Gopalan
It is not at all possible to create foreign key relations between databases - let alone between server instances.
You might be able to create a trigger on the Profiles table, that checks if a userid exists in the User table in the other database, but I fear the performance of this approach will be very bad.
A much better solution would be to replicate one table to the other database, and then create the foreign key relations in a normal way. How you replicate the table (SSIS, CDC, triggers, etc.) is up to you.

Access not importing relationships for MySQL linked tables

I have successfully linked my MySQL database with my Access database file. Everything is working fine except the relationships in the MySQL database are not appearing in Access.
I have made a plenty of relationships in the MySQL tables using foreign keys, but these relationships are not reflected in Access. Kindly help me to import the relationships from the MySQL database into Access.
Software I'm using: MySQL version 5, Microsoft Office 2013, Access file format: .accdb
While it is true that the MySQL foreign key constraints don't show up by default in the Relationships tab in Access, those constraints are still in place in MySQL and are still enforced for linked tables.
For example, say I have two MySQL tables, [customers] and [orders], with a foreign-key constraint on [orders]. If I link to those tables in Access and I try to insert a row into my [orders] linked table where the [customerID] does not match a [customerID] in my [customers] linked table the insert fails:
ODBC --insert on a linked table 'orders' failed.
[MySQL][ODBC 5.2(w) Driver][mysqld-5.5.29-0ubuntu0.12.04.2]Cannot add or update a child row: a foreign key constraint fails (`zzzTest`,`orders`, CONSTRAINT `orders_ibfk_1` FOREIGN KEY (`customerID`) REFERENCES `customers` (`customerID`)) (#1452)
You can go into the Relationships tab in Access and create "Access-side" relationships for the MySQL tables...
...but notice that the "Enforce Referential Integrity" options are greyed out because that is a function of the database setup at the server, not in Access. So really, the only benefits that the "Access-side" relationships would offer are:
"documentation" of the relationships (which you could get from a database diagram generated against the MySQL database), and
"automatic" joins between the linked tables in the Access query designer (which can also happen without [Access] Relationships if tables have columns with the same name).
It's up to you to decide whether it would be worth the trouble to create those "Access-side" relationships.
Since this is cross databases, it may have to recreated manually.
Check out this one, Importing .sql into MS Access using OBDC

How to 'follow' foreign keys in a SQL client

I am currently using Sequel Pro to view my database. I find much of my time spent on 'following' foreign keys. For example, if an entry in table A links to table B, I find myself writing down the id number, then clicking the other table, scrolling down to find that id, etc. It becomes quite tedious.
Is there a way in Sequel Pro or in another SQL client to link to the FK (e.g., double click the FK and it takes you to that entry)?
You can benefit from the foreign key lookup editor for easy editing of fields referencing other tables in dbForge Studio for MySQL.

how to make foreign key relationship on physically distributed data?

three servers
server 1 is central point which links the other two servers.
the other two servers have a table which has a field which should act like a foreign key
problem
well i do not know how to do this, using vs08 or sql server 08
diagram view
table on server 1
sv1pg1 id -- primary key
details
tables same schema on srvr2 and srvr3
linkedSRVid -- pk
linkedto -- fk constrain should be between (server 1 primary key and this field)
note that
"this is just a simplest! way i can think of to represent the prob, the real dbs contain
many fields and tables and the following applies"
it's not always that the network connection between the server remains up.
the link only need for "writing purpose" not viewing, as viewing done by direct
connection to the respective server.
A foreign key constraint can reference other tables only within the same database. This means that even if those databases were on the same server it still would not work.
Considering that the schemas are the same, you may want to look into replication.