sql query for store procedure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Amit1989
    New Member
    • Sep 2014
    • 2

    sql query for store procedure

    i have four table
    table user info = there are 6 columns one is primary key
    tables user roles = two columns one is primary key
    table user dep = two fields one is primary key
    table user profile = there are four fields one is primary key
    others fields are foreign keys(table info,table roles,table dep)

    questions is of which table we have to make a store procedure and what is query for that
    i wrote for table info m right or not
    Code:
    CREATE PROCEDURE [USERINFORMATION]
    @Id int
    ,@LogInName varchar(50)
    ,@FirstName varchar(50)
    ,@LastName varchar(50)
    ,@EmailAddress varchar(50)
    ,@Password varchar(50)
    
    AS
    BEGIN
    INSERT 
    INTO [tUserInfom]
    (
    Id
    ,LogInName
    ,FirstName
    ,LastName
    ,EmailAddress
    ,Password
    )
    VALUES
    (
    @Id
    ,@LogInName
    ,@FirstName
    ,@LastName
    ,@EmailAddress
    ,@Password
    )
    END
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    I have no idea what your question is. Please try to explain in more detail.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Stored procedures are not associated with any database tables. They are just procedures that exist in the database that do "Things". The things that they do might involve one table, several tables or no tables at all.

      The stored procedure you posted simply inserts a record into the tUserInfom table; however it should probably be expanded upon to also insert rows into the other 3 tables that depend on the record inserted....

      For example:
      Code:
      CREATE PROCEDURE [USERINFORMATION]
      @Id int
      ,@LogInName varchar(50)
      ,@FirstName varchar(50)
      ,@LastName varchar(50)
      ,@EmailAddress varchar(50)
      ,@Password varchar(50)
       
      AS
      BEGIN
      
      INSERT INTO [tUserInfom] (Id,LogInName,FirstName,LastName,EmailAddress,Password)
      VALUES (@Id,@LogInName,@FirstName,@LastName,@EmailAddress,@Password);
      
      Insert Into tUserRoles (RoleID, UserID) Values("ViewContent",@ID);
      
      --....etc....--
      
      END
      Last edited by Frinavale; Sep 16 '14, 04:52 PM.

      Comment

      Working...