Query Help

  • Hello,

    I have two tables linked by a foreign key:

    CREATE TABLE usuario (

    USid int IDENTITY (1,1) NOT NULL,

    usuariovarchar (40) NOT NULL,

    clave varchar (50) NOT NULL,

    tipo varchar (50) NULL,

    permisovarchar (20) NOT NULL,

    PRIMARY KEY (USid)

    )

    and

    CREATE TABLE proveedor(

    Pid int IDENTITY (1,1) NOT NULL,

    nombrevarchar (50) NOT NULL,

    lineaobjetivo money NULL,

    PRIMARY KEY (Pid),

    usuario_USid int REFERENCES usuario(USid)

    )

    Now what I want is that when I insert a new row in "proveedor" the "nombre" value become a part of all "usuario column" in the usuario table.

    So basically what I want is that when I enter a new category this category becomes available to all users registered in the user table.

  • MrCapuchino (7/17/2010)


    CREATE TABLE usuario (

    USid int IDENTITY (1,1) NOT NULL,

    usuariovarchar (40) NOT NULL,

    clave varchar (50) NOT NULL,

    tipo varchar (50) NULL,

    permisovarchar (20) NOT NULL,

    PRIMARY KEY (USid)

    )

    CREATE TABLE proveedor(

    Pid int IDENTITY (1,1) NOT NULL,

    nombrevarchar (50) NOT NULL,

    lineaobjetivo money NULL,

    PRIMARY KEY (Pid),

    usuario_USid int REFERENCES usuario(USid)

    )

    Now what I want is that when I insert a new row in "proveedor" the "nombre" value become a part of all "usuario column" in the usuario table.

    So basically what I want is that when I enter a new category this category becomes available to all users registered in the user table.

    Not sure from where the "Category" is coming from, nowhere to be seen. Where is it stored?

    Do you mean, each time a row is inserted into Proveedor table you want a row to be inserted into Usuario table?

    If that's the question a "on insert" trigger in Proveedor table would do the trick - provided all the info needed to insert the row into Usuario is somehow known by the application.

    _____________________________________
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at Amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
  • Hi,

    Well, it is kind of what you say,

    I'm sorry I put category I meant "nombre" from table "proveedor".

    So for instance,

    When I insert a new "nombre" into proveedor

    I want that this inserted value be part of all values in "usuario" from Table "usuario" automatically.

    So if usuario column has

    Jake

    Jack

    Michael

    I want that the inserted "nombre" from Proveedor be linked to all of the "usuario".

    So if the new "nombre" is FOOD

    I want that Jake, Jack and Michael be linked to FOOD, or may be it is viceversa I want FOOD to be linked to Jake, Jack and Michael.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply