By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,688 Members | 1,738 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,688 IT Pros & Developers. It's quick & easy.

sql query for store procedure

P: 2
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
Expand|Select|Wrap|Line Numbers
  2. @Id int
  3. ,@LogInName varchar(50)
  4. ,@FirstName varchar(50)
  5. ,@LastName varchar(50)
  6. ,@EmailAddress varchar(50)
  7. ,@Password varchar(50)
  9. AS
  10. BEGIN
  11. INSERT 
  12. INTO [tUserInfom]
  13. (
  14. Id
  15. ,LogInName
  16. ,FirstName
  17. ,LastName
  18. ,EmailAddress
  19. ,Password
  20. )
  21. VALUES
  22. (
  23. @Id
  24. ,@LogInName
  25. ,@FirstName
  26. ,@LastName
  27. ,@EmailAddress
  28. ,@Password
  29. )
  30. END
Sep 15 '14 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 10K+
P: 12,430
I have no idea what your question is. Please try to explain in more detail.
Sep 15 '14 #2

Expert Mod 5K+
P: 9,731
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:
Expand|Select|Wrap|Line Numbers
  3. @Id int
  4. ,@LogInName varchar(50)
  5. ,@FirstName varchar(50)
  6. ,@LastName varchar(50)
  7. ,@EmailAddress varchar(50)
  8. ,@Password varchar(50)
  10. AS
  11. BEGIN
  13. INSERT INTO [tUserInfom] (Id,LogInName,FirstName,LastName,EmailAddress,Password)
  14. VALUES (@Id,@LogInName,@FirstName,@LastName,@EmailAddress,@Password);
  16. Insert Into tUserRoles (RoleID, UserID) Values("ViewContent",@ID);
  18. --....etc....--
  20. END
Sep 16 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.