add a foreing key to an existing table

0

I have to create a column in an existing table and at the same time create a foreing key with another table using this column that was created, and this foreing key by default must be null. The way I'm doing is

 IF NOT EXISTS (SELECT * FROM SYSCOLUMNS C INNER JOIN SYSOBJECTS T ON C.id = T.id WHERE C.name = ('IdSetorPreparo') AND T.name = 'Produto')

    BEGIN
    ALTER TABLE Produto  
            ADD IdSetorPreparo int     
    END 

    ALTER TABLE Produto 
        ADD CONSTRAINT FK_Produto_IdSetorPreparo FOREIGN KEY(IdSetorPreparo) REFERENCES OrgSetor(id)  

Well, I wanted to know if it's possible at the same time to create the column already creating the foreing key.

    
asked by anonymous 08.07.2015 / 21:09

1 answer

2

In SQL Server you can do this:

ALTER TABLE Produto
    ADD IdSetorPreparo INTEGER,
    FOREIGN KEY(IdSetorPreparo) REFERENCES OrgSetor(id);

If you want the column to support NULLs, you just have to set it to NULL.

ADD IdSetorPreparo INTEGER NULL

In this particular case the constraint will not be verified.

    
08.07.2015 / 21:36
______ qstntxt ___

I searched the net but found nothing to upload a file and converted it to %code% and then search the text inside it for results.

/ p>

Someone knows how this is done so I can leave some links for me to study the case.

    
______ azszpr73152 ___

Converting binary files to %code% will not make a search work, each file has its own format.

For each file type you will have to use a method to extract the data and save it in a %code% , some example:

  • XML use link

    Example:

    %pre%
  • CSV use link

    %pre%
  • XLS will probably have to use a library to facilitate such as link or link

  • These are just a few examples, for each format you implement in your application you will have to use a new script.

    I believe that there is no "magic" solution ready for this, you will have to take what exists and create an application based on it.

    To make the query, let's suppose that you saved all %code% to a folder, so you should do a search similar to this:

    %pre%     
    ______ azszpr73192 ___

    I do not know if I understand your question right, but if you want the list of files listed in a txt file, use the following command:

    %pre%

    I hope I have helped.

    Embrace

        
    ___ How to track the execution of php file by console?