?
Solved

MS SQL Server 2008 Data integrity FK NULL

Posted on 2008-11-02
21
Medium Priority
?
450 Views
Last Modified: 2013-12-07
I'm going to be real lame here and ask an easy question.. I think.. this is to make
up for later when I ask a reeeeaaalllllly hard question and get really fussy.  Be warned!

You see I have successfully created a couple of tables.  "Table _1 " is now called
"Sales_Rep" as I have saved it thus refreshing the name on the tab.  I need
"seller" to be a foreign key referring to the primary key "name" of Sales_Rep but
I think it is okay if it is null?  hmm.. yes.  I think an unsold Automobile (Table_2) can
be in the database.

Maybe I have to click that relationship jobbie?
seller.jpg
0
Comment
Question by:kayvey
[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
  • 18
  • 3
21 Comments
 
LVL 17

Accepted Solution

by:
HoggZilla earned 2000 total points
ID: 22864266
Question: Can a FK be NULL
Answer: Yes: A FOREIGN KEY constraint does not have to be linked only to a PRIMARY KEY constraint in another table; it can also be defined to reference the columns of a UNIQUE constraint in another table. A FOREIGN KEY constraint can contain null values; however, if any column of a composite FOREIGN KEY constraint contains null values, verification of all values that make up the FOREIGN KEY constraint is skipped. To make sure that all values of a composite FOREIGN KEY constraint are verified, specify NOT NULL on all the participating columns.
Question: How do I define a FK relationship in SQL
Answer: Several Options: http://msdn.microsoft.com/en-us/library/ms177463.aspx
 
0
 

Author Comment

by:kayvey
ID: 22864299
I'm in touchy feely Windoze moode.  I dont know where to type the SQL right now.  Can I right click on something instead?
0
 

Author Comment

by:kayvey
ID: 22864374
I press buttons dwive me kwayzey
FK-wazyzey.jpg
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:kayvey
ID: 22864378
I'm not trying to make this hard.  I think we are close this one.
0
 

Author Comment

by:kayvey
ID: 22864399
That's better. I saved with right names now. Automobile.seller must be Sales_Rep.name.  seller FK to
Sales_RepPK.name.  
sellerFKname.jpg
0
 

Author Comment

by:kayvey
ID: 22864412
Now you see Sales_Rep.  Sales_Rep (s) he have name(S)
namePK.jpg
0
 

Author Comment

by:kayvey
ID: 22864445
oh oh., bad danger. soooo many windoze i never asked for
badPKdanger.jpg
0
 

Author Comment

by:kayvey
ID: 22864536
Okay I done now with kwayzey nonsense?  i have no idea.
PKFKdone.jpg
0
 

Author Comment

by:kayvey
ID: 22864548
Can you read that? It is Foreign Key Relationships Diagalog woohaw.

-Tables and Columns Specifica
       Foreign Key Base Table         Automobile
       Foreign Key Columns             seller
       Primary/Unique Key Base Ta Sales_Rep
       Primary/Unique Key Column  name
-Identity
   (Name)                                       FK_Automobile_Sales_Rep
   
0
 

Author Comment

by:kayvey
ID: 22864594
this is kwayzey awful slow
0
 

Author Comment

by:kayvey
ID: 22864597
I mean my stooopid awful old puter running Vista.. I save I save It confused.
0
 

Author Comment

by:kayvey
ID: 22864658
Tables and Columns make me mad.  Can't change Forieng key table.

oopsie!   got it backards?
ornery.jpg
combobulate.jpg
0
 

Author Comment

by:kayvey
ID: 22864710
oooh nooo!!! bad saving.. agnrgy windowze..won't let me save now.. make
stupid system32 textfile
saveProb.jpg
systemTxt.jpg
0
 

Author Comment

by:kayvey
ID: 22864728
nooooo!  not stupid cancle!! this disaster bad wrong bad wrong wrong bad bad bad rowong
worong wong wong wrong wrong
cancel.jpg
0
 

Author Comment

by:kayvey
ID: 22864800
THIS LAST STRAW DISASTER NONSENSE>  HOW TO DROP DANG TABLES??
exErr.jpg
0
 
LVL 17

Expert Comment

by:HoggZilla
ID: 22866069
You are hilarious. I have no idea where you are now, sorry. What can I do to help. I thought you had it there but it seems you and your database are not on good terms?
0
 

Author Comment

by:kayvey
ID: 22868280
Did I do the FK right?
0
 

Author Comment

by:kayvey
ID: 22868477
Okay I guess it's fine.  Now how do I populate the tables?
0
 

Author Comment

by:kayvey
ID: 22868526
I got this stupid thing called Power Shell.. maybe that's where I type SQL? I don't want to lookup nonsense.Where is stupid spreadsheet type view of data in fields?
powerShell.jpg
0
 
LVL 17

Assisted Solution

by:HoggZilla
HoggZilla earned 2000 total points
ID: 22869235
In SQL Server management Studio, behind your above console screen, Right Click on the table and select Open Table. There you can type values into the columns directly.
0
 

Author Comment

by:kayvey
ID: 22870087
It's not Open table.  It's Edit top 200 lines..

allrighty then.  I guess that'll do it.  Thank you, sir.
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

777 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