Question about scripting of foreign keys

When I script FK_SalesOrderHeader_Address_BillToAddressID key from AdventureWorks.[Sales].[SalesOrderHeader] I get this:
ALTER TABLE [Sales].[SalesOrderHeader] WITH CHECK ADD CONSTRAINT [FK_SalesOrderHeader_Address_BillToAddressID] FOREIGN KEY([BillToAddressID])
REFERENCES [Person].[Address] ([AddressID])
GO
ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_Address_BillToAddressID]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Foreign key constraint referencing Address.AddressID.' , @level0type=N'SCHEMA',@level0name=N'Sales', @level1type=N'TABLE',@level1name=N'SalesOrderHeader', @level2type=N'CONSTRAINT',@level2name=N'FK_SalesOrderHeader_Address_BillToAddressID'
GO
What is second ALTER statement for (the one highlighted with bold font)? First ALTER statement already includes WITH CHECK, so isn't the second one redundant?

The 2nd Statement enables the Foreign Key.
I think it is redundant because FOREIGN KEY is enabled by default when you execute the 1st statement.
This script is generated by SSMS (Yes?), This is added just to ensure that CONSTRAINT is enabled.
- Vishal
SqlAndMe.com
Yes, it is generated by SSMS 2008.

Similar Messages

  • Questions about creating a foreign key on a large table

    Hello @ll,
    during a database update I lost a foreign key between two tables. The tables are called werteart and werteartarchiv_pt. Because of its size, werteartarchiv_pt is a partitioned table. The missing foreign key was a constraint on table werteartarchiv_pt referencing werteart.
    Some statistics about the sizes of the mentioned tables:
    werteart 22 MB
    werteartarchiv_pt 223 GB
    werteartarchiv_pt (Index) 243 GB
    I tried to create the foreign key again, but it failed with the following error (Excuses for the german error message):
    sqlplus ORA-00604: Fehler auf rekursiver SQL-Ebene 1
    sqlplus ORA-01652: Temp-Segment kann nicht um 128 in Tablespace TEMPS00 erweitert
    The statement I used:
    alter table werteartarchiv_pt
    add constraint werteartarchiv_pt_fk1
    foreign key (schiene, werteartadresse, merkmale)
    references werteart (schiene, werteartadresse, merkmale)
    on delete cascade
    initially deferred deferrable;
    So the problem seems to be, that Oracle needs a lot of temporary tablespace to generate the foreign key and I do not know how much and why.
    My questions now are, and hopefully someone is here, who can answer all or a part of it:
    1) Why does Oracle need temporary tablespace to create the foreign key? The foreign key uses the same columns like the primary key.
    2a) Is it possible to tweak the statement without using the temporary tablespace?
    2b) If it is not possible to avoid the usage of the temporary tablespace, is there a formula how to calculate the needed temporary tablespace?
    3) Is it possible to modify data in the tables while the foreign key is created or is the whole table locked during the process?
    Any help or hint is appreciated.
    Regards,
    Bjoern

    RollinHand wrote:
    My questions now are, and hopefully someone is here, who can answer all or a part of it:
    1) Why does Oracle need temporary tablespace to create the foreign key? The foreign key uses the same columns like the primary key.Because it's validating the data to ensure the foreign key won't be violated. If you had specified ENABLE NOVALIDATE when creating it then the existing data in the table wouldn't need to be checked and the statement should complete instantly (future data added would be checked by the constraint).
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28310/general005.htm
    Search for "Enable Novalidate Constraint State"

  • ABAP question: define a custom foreign key for a standard field??

    Hi,
    I want to use the field ADDR1_DATA-STR_SUPPL3 for customer use. I must to define a foreign key against a Ztable (as verification table) for this standard field. Also I must to define a custom search help.
    To defining a foreign key for this field, I must be in change mode, so the system ask to me for registering the object. That means this action is a modification. My question is the following: is there any way to do so without SAP standar modification??
    For instance, using BDT events...but how?
    Thanks in advance.
    Regards,
    Rosa

    Hi Rosa,
    Changing SAP Standard dictionary elements is not possible with out changing the same. To change these elements, we dont have any other method apart from SAP standard modification.
    Cheers
    Pavan

  • Beginner's question about scripting and deployment automation

    I am new to the SAP and BusinessObjects world.  I do production support for BusinessObjects XI R3.1.  One of my functions is to deploy Universe.unv and WEBI Report files from development into QA and production.  This is currently a manual process involving downloading files and lots of key strokes and mouse clicks using the BusinessObjects Client Tools.  My question ->:  is there a way to automate this process?  Can I do this with the SAP scripting wizard?  I am familiar with many different scripting and programming languages, I just need to be pointed in the right direction.
    Thanks for your help!

    I would take a step back and learn more about the fundamentals of Flash before going farther. In the Welcome Screen of Flash Profressional there is a "Learn" section. Here are some links from it:
    Introducing Flash: http://www.adobe.com/go/fl_learn1
    Symbols: http://www.adobe.com/go/fl_learn2
    Timelines and Animation: http://www.adobe.com/go/fl_learn3
    Instance Names: http://www.adobe.com/go/fl_learn4
    Simple Interactivity: http://www.adobe.com/go/fl_learn5
    ActionScript: http://www.adobe.com/go/fl_learn6

  • Question about scripts in repeatbel sub-form objects

    Hi,
      I am working on creating a form which has a sub-form that can be repeated as many times as the user wants to. There is an ‘Add’ button which creates an instance of the sub-form on the form, when clicked.
    On the sub-form I have 5 numeric fields say a1-a5 and 1 field say b1 which is the sum of all these 5 fields.
    On the Main form I have a 2 fields - say t1 and f1.
    The requirement is t1=f1+b1+(sub-form instance 2’s b1)+(sub-form instance 3’s b1)+ and so on …depending on as many sub-form instances there are that the user adds.
    I have created Actions using the Action Builder such that when any of a1 to a5 fields are exited, b1 will be updated with the sum of a1-a5. At the same time t1 will be updated with sum of f1 and b1.
    This works great for 1 instance of the sub-form. But when ‘Add’ is clicked and a second instance of the sub-form is added, then the script does not work as it did for the first instance of the sub-form. So for any instances of the sub-form added, when values are added to a1-a5 and the fields are existed, b1 does not get updated.
    How can I fix this?
    See attached form that I am creating for clarity.
    ‘Total Hours worked this week’ is the t1 I was talking about. See how it gets updated when values are entered in any of the hour fields. It works fine with the default instance of the T100/Strategic/Advantage Customer Information sub-form as well. But when I click on ‘Add Customer’ button to add another instance of the sub-form, it does not work as expected.
    Please let me know if it is still not clear and I can explain the issue.

    Vjay's solution works great! Essentially, take out all of your other programming on the individual fields, and hard script the field you want the sum to show on. By directly referencing the fields, Adobe is able to tell the difference between one instance and another and doesn't get them mixed up. (I have found for some of these dynamic functions, the Action Builder doesn't really work, so you need to code by hand)
    My only suggestion, would be to perhaps modify Vjay's code a little, and use Javascript instead of Formcalc. We have run into the problem where if a user is using the form from a webserver or something and hasn't actually been saved to the user PC, the Formcalc scripts won't run, only Javascript. But it all depends on how you are using your forms.
    Here is your line of code changed to Javascript, in case you want to make that change. (there's really not much difference at all)
    this.rawValue = sum(CustomerTimeBD.Row1.Cell1.rawValue + CustomerTimeBD.Row1.Cell2.rawValue + CustomerTimeBD.Row2.Cell1.rawValue + CustomerTimeBD.Row2.Cell2.rawValue + CustomerTimeBD.Row3.Cell1.rawValue + CustomerTimeBD.Row3.Cell2.rawValue + CustomerTimeBD.Row4.Cell1.rawValue + CustomerTimeBD.Row4.Cell2.rawValue + CustomerTimeBD.Row5.Cell1.rawValue);

  • Question about script in sun studio creator2 and netbean6.1

    Hi, I have a quick question
    I have started a project by using sun studio creator2, the main page contains following script, it works perfectly fine.
    <script type="text/javascript">
    function getUser()
    var net = new ActiveXObject("wscript.network");
    document.getElementById('form1:hiddenField1').value = net.UserName;
    </script>
    And then I bind the field to a managed bean's property.
    However, because I need to use netbean6.1 to continue this project. I find previous script doesn't work any more. (I can get net.UserName, but I can't store the value to hiddenfield)
    I checked woodstock documentation, and guess following will do the same job
    <webuijsf:script>
    function getUser() {
    var net = new ActiveXObject("wscript.network");
    var domNode = document.getElementById('_form1:hiddenField1');
    domNode.setProps({value:net.UserName});
    </webuijsf:script>
    Once run the getUser() function, I got an "object doesn't support this property or method".
    It looks like IE security level setting problem. If it is so, because it is company setting. There is nothing I can do here.
    Any one knows workaround to store the retrived userName into hiddenfield?
    Thanks in advance!!!

    any help is appreciated

  • Mac Mini w/ Apple USB keyboard - question about home and end keys

    I purchased a USB white Apple keyboard to go with my Mac mini.
    My question concerns the home and end keys. When I put the cusor focus in a text field or text area, I would expect that hitting the home key would take me to the beginning of the line and hitting the end key would take me to the end of the line.
    That's not the case?
    If a vertical scrollbar is used in the window, then the home key takes me to the top of the window and the end key takes me to the bottom of the window.
    Please forgive me, I've been on a PC for the last 10+ years, so I thought I should ask.
    What key or key combo moves you to the start and end of a text in a text field or text area?
    Thanks,

    923/3369
    Hi Todd,
    Use the arrow keys with the command key (⌘):
    command + left arrow -> beginning of the line
    command + right arrow -> end of the line
    command + arrow up -> beginning of the text
    command + arrow down -> end of the text
    Explore also the option key (⌥) possibilities, with the arrow keys:
    very handy too.
    Yes, the Home, End, Pageup and Pagedown keys are for controlling the whole document, not the text itself.
    HTH
    Axl

  • Questions about scripts

    Hello,
    I'm recently learning computer science in school and I am learning how to create some scripts. I'm having trouble in creating some type of script and I was wondering if someone could help me out on it. I'm not asking for you guys to write the whole script for me but some tips on what I should look for, etc. I know most of the terminology.
    scripts with problems:
    1) Write a program that calculates n!
    2)Write a program that determines whether a given natural number is prime or composite.
    3)Write a program with three integer variables, n1, n2, and n3. Initialize two of those variables, i.e. n1 and n2, with input from the user. Then swap the values of these two variables so that the value that was originally in n1 winds up in n2 and the value that was originally in n2 winds up in n1. Note: The third variable plays an important role. If you are having trouble, first try the next problem below involving the two balls and the three boxes.
    Thanks Alot. I appreciate the help.

    1) Popular example which people would suggest you use recursion. If you want it simpler, use for loop. Google gives you tons of example.
    2) Prime is only divisible by 1 and itself. So you would look for "%" operator for finding the remainder.
    3) I think this one is pretty straight forward.
    Actually, before posting these question, any idea in your mind ?

  • Question about kicker and best keying greenscreen techniques for removing small artifacts

    Hi,
    At the moment I'm doing some green screen shootings.
    The only problem I encounter is the fact that when I make a total shot from a actor the backlighting stand is visible between their legs.
    I have no possibility to hang the backlighting above the actors.
    What is the best technique to remove such small artifacts?!
    Thanks! David

    It sounds like a simple mask drawn around the stand will do the trick. A screenshot would help but from your description I'd just use the pen tool to draw around the offending object then set the mask mode to subtract. If the actors move you'll have to animate the mask position. The only critical part of the mask would be right next to the actors legs. You can leave lots of room around the object.

  • Data modeler: (non) mandatory foreign keys???

    Hi there,
    can anybody explain what the difference between mandatory and non-mandatory FKs, as displayed in the data modeler???
    There is this check box and the documentation does not really explain, what database feature this non-mandatory FK corresponds to... It is certainly not about a deferred foreign key and also not about a deactivated one. So what is this?

    Philip Stoyanov wrote:
    non-mandatory FK will constitute non-mandatory FK columns, hence you cannot have non-mandatory FK if FK columns are part of primary key.
    PhilipHi,
    thanks but...I don't understand your point.
    Do you agree, with the following:
    1.non-mandatory means optional right?
    2.Foreign key constraints are always optional from a physical model point of view.
    3.FKs always point on PKs
    An additional comment: I just had used the data modeler plugin of the sql developer and reverse engineered some tables from our schema.
    So in this case, all information must come from the database. I wonder, what is the reason for marking one FK as mandatory and the other as optional...
    I could find any physical difference with other FKs in user_constraints etc.
    Thanks in advance,
    Xenofon

  • Confusion On Creating Foreign Key

    I'm confused about creating a foreign key in my table since two tables in the schema will hold identical info:
    EMP_ID
    EMP_NAME
    EMP_MANAGER
    DEPT_ID
    DEPT_NAME
    DEPT_MANAGER
    Now my 1st confusion is if I'm creating a foreign key, do I point EMP_MANAGER to DEPT_ID or DEPT_MANAGER? How can I configure the EMPLOYEES.EMP_MANAGER to pull the values from DEPARTMENT.DEPT_MANAGER? Would I need to point it to DEPT_ID for any reason or would it be a direct link between the two _MANAGER columns?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    >
    the two column names have to be exact
    >
    No! The data in the columns needs to be exact. It doesn't matter what the column names are.
    The column names you provided appear to show that YOUR emp table is denormalized. It has an EMP_MANAGER column which presumably contains the NAME of the manager, rather than the DEPT_ID of the manager. If it actually contains the NAME and the DEPT_MANAGER column of the other table has names you could create a foreign key between them.
    But that means you are duplicating the manager name in both tables. If the EMP_MANAGER column actually contains the DEPT_ID of the employees manager then create a foreign key between EMP_MANAGER and DEPT_ID.

  • [PHP-MYSQL] tutorial on using ADDT and dynamic list/form with self-foreign keys?

    Hi all,
    I have a 3 levels catagoris product catalog and would like to manage it
    using dynamic list/forms.
    I'm searching info about using self-foreign keys on dynamic list/forms.
    Is there any tutorial on how to manage this kind of tables using addt?
    tia
    tony

    Hello Tom,
    You were offered the solution on the InterAKT forums, I am not sure why you are posting this problem again. There's also another thread here that presents the same issue and solution:
    http://www.adobeforums.com/cgi-bin/webx/.3bc42a90/0
    Regards,
    Ionut

  • A question about foreign key to multiple tables

    Hello everybody,
    I have a question about creating foreign key and I would appreciate if you could kindly give me a hand. Here are my tables:
    CREATE TABLE TEAM1(team_id VARCHAR2(20), project_id VARCHAR2(20));
    ALTER TABLE TEAM1 ADD CONSTRAINT PK_TEAM1 PRIMARY KEY(team_id);
    CREATE TABLE TEAM2(team_id VARCHAR2(20), project_id VARCHAR2(20));
    ALTER TABLE TEAM2 ADD CONSTRAINT PK_TEAM2 PRIMARY KEY(team_id);although the structure of both the tables is exactly the same, the values (in particular team_id) in both tables are different.
    Also I have another table named AGENT
    CREATE TABLE AGENT(agent_id VARCHAR2(20), team_id VARCHAR2(20));
    ALTER TABLE AGENT ADD CONSTRAINT PK_AGENT PRIMARY KEY(agent_id)Now the problem is that the column team_id in AGENT table is actually a foreign key, but the value can be in either TEAM1 or TEAM2. As far as I know a foreign key points only to one table.
    How can I deal with this problem? Whenever there is an INSERT or UPDATE I have to make sure that the value of the column "team_id" in the table "AGENT" is a valid value either in "TEAM1" or "TEAM2"
    Thanks in advance,
    Kind Regards,
    Dariyoosh

    Do you have the ability to change the data model? If so a more appropriate structure may be something like this:
    CREATE TABLE TEAM(team_id VARCHAR2(20), team_name VARCHAR2(20));
    ALTER TABLE TEAM ADD CONSTRAINT PK_TEAM PRIMARY KEY(team_id);
    ALTER TABLE TEAM ADD CONSTRAINT UK_TEAM UNIQUE (team_name);
    CREATE TABLE TEAM_PROJECT(team_id VARCHAR2(20), project_id VARCHAR2(20));
    ALTER TABLE TEAM ADD CONSTRAINT PK_TEAM_PROJECT PRIMARY KEY(team_id, project_id);
    ALTER TABLE AGENT ADD CONSTRAINT FK_TEAM_PROJECT1 FOREIGN KEY (team_id) REFERENCES TEAM(team_id);
    CREATE TABLE AGENT(agent_id VARCHAR2(20), team_id VARCHAR2(20));
    ALTER TABLE AGENT ADD CONSTRAINT PK_AGENT PRIMARY KEY(agent_id);
    ALTER TABLE AGENT ADD CONSTRAINT FK_TEAM FOREIGN KEY (team_id) REFERENCES TEAM(team_id);Edited by: Centinul on Jun 25, 2010 10:50 AM

  • Urgent expalantion reqired about foreign keys

    we are doing data migration project and we have get data from different regions data in flat files, but we have problem below like:
    i am facing a problem to declare unique constraints, because in some files column should be in number data type and same file from some other region is varchar2 but these two columns are unique ,these two columns don't having the any duplicate values.
    can i take this column data type in varchar2?
    why because if i am taking number type it cant accept varchar2
    any suggestions.................
    Regards,
    sh

    sh wrote:
    we are doing data migration project and we have get data from different regions data in flat files, but we have problem below like:
    i am facing a problem to declare unique constraints, because in some files column should be in number data type and same file from some other region is varchar2 but these two columns are unique ,these two columns don't having the any duplicate values.
    can i take this column data type in varchar2?
    why because if i am taking number type it cant accept varchar2
    any suggestions.................
    Regards,
    shNot really sure i understand your question. If you have 2 data sources and 2 different data types for the same type of data then you'd want to ensure you do a TO_NUMBER on the character representation of the data to ensure you strip out any non-printing characters like tabs or spaces.
    If that's not your problem, please try to be a little more clear. Your subject mentions you have an urgent problem about foreign keys and i find nothing to support your claim of urgency, nor foreign keys, within the subject of your question.
    Cheers,

  • Some basic questions about foriegn key , and relationships.

    Hi
    Thank you for reading my post
    I read some documents about foreugn key and tables relation ships.
    but i still can not understnad some stuff.
    1-when we have a foreign key , we have two tables that we want to relate them together
    in a way that one of ? table columns forced to be a value from ?? table column.
    what is name of those two tables , i saw , child-parent , ..... which confuse me.
    can some one please tell me correct name of those two tables ?
    2-some times we need some kind of master details relation like :
    one-to-many : i this case MANY table will have a column to point a record in ONE table , can this relation be a foreign key relation ?
    3-we can achieve many-to-many relation only by using a helper table to host both tables primary keys in a record to relate them together.
    can you point me to some resources that help me to find answers to this questions ?
    or explain them to me ?
    thank you for your time.

    These are critical database basics that you need to understand. I would seriously recommend getting some study in, because proper relational database design relies on the basic principle of data and relationships and a process called normalization.
    In reality, you only really need one gigantic table to host data. It would include everything you would want to know about something - let's take a sales order for example. You would have to record the customer's name, address, etc. along with every item they ordered, etc. You would have a HUGE table full of data that appeared over and over and over again. This is bad design for two basic reasons: it is difficult to query, and it is very easy to have minor mistakes like capitalization or alternate spellings that prevent things from matching up properly. For example, let's say Bob orders 40 widgets and 40 digits. In our hypothetical table, we could put it in as Bob - 40 widgets and Robert - 40 digits. See how confusing this can get even in a simple example? And let's say you wanted to correct all of Robert's orders to say Bob and you found out there were 40 orders from "Robert" How would you know which ones to change?
    The process of normalization helps to reduce the chance for these types of errors in addition to creating a good basis for indexes. You normalize the data by creating sets of parent/child tables with a "key" value to match them. In our hypothetical situation, you could create a table for orders and a table for customers. In the customers table you give all the detail for the customer in one place, and you assign each customer a unique number or ID. In the orders table we add the customer ID (NOT the name) and we ensure that we are getting the customer we want, in addition to saving a lot of space and eliminating redundancy. In our example, the customers table is the "parent" table and the orders table is the "child" table. The child table references the unique entries in the parent table via that id. That reference is referred to as a foreign key. The foreign key in the child table points back to the original and complete record in the parent table and eliminates the redundancy of keeping all that extra data for every order. Foreign keys in child tables always refer to a primary/unique key in the parent field.
    That help?

Maybe you are looking for