|
INTERVIEW QUESTIONS
MICROSOFT
ADO.NET
DETAILS
Question: How do stored procedure look like, can you provide some sample stored procedures?
Answer: Here we are presenting a brief review of four basic type of stored procedure for SELECT, INSERT, UPDATE and DELETE operations. In SQL Server, you can create and add stored procedures to your database using the SQL Server Enterprise Manager.
UPDATE Stored Procedure A simple stored procedure to update a record is
CREATE PROCEDURE UpdateProc ( @artId as int, @title as varchar(100), @topic as varchar(100), @authorId as int, @lines as int, @dateOfPublishing as datetime) AS UPDATE Article SET title=@title, topic=@topic, authorId=@authorId, lines=@lines, dateOfPublishing=@dateOfPublishing WHERE artId=@artId GO
The name of stored procedure is UpdateProc and it has the input parameters for each of the fields of our Article table. The query to be executed when the stored procedure is run updates the record with the supplied primary key (@artId) using the supplied parameters. It is very similar to the code we have written to initialize command in the previous example and we hope you don’t have any problem in understanding this even you are not familiar with stored procedure.
INSERT Stored Procedure A simple stored procedure to insert a record is
CREATE PROCEDURE InsertProc ( @artId as int, @title as varchar(100), @topic as varchar(100), @authorId as int, @lines as int, @dateOfPublishing as datetime) AS INSERT INTO article (artId, title, topic, authorId, lines, dateOfPublishing) VALUES(@artId, @title, @topic, @authorId, @lines, @dateOfPublishing) GO
The stored procedure above is named InsertProc and is very similar to the UpdateProc except that here we are using the INSERT SQL statement instead of the UPDATE command.
DELETE Stored Procedure A simple stored procedure to delete a record is
CREATE PROCEDURE DeleteProc (@artId as int) AS DELETE FROM article WHERE artId = @artId GO
Here we have used only one parameter as to delete a record you only need its primary key value.
SELECT Stored Procedure A simple stored procedure to delete a record is
CREATE PROCEDURE SelectProc AS SELECT * FROM Article GO
This probably is the simplest of all. It does not take any parameter and only selects all the records from the Article table.
All the four stored procedures presented above are kept extremely simple so that the reader does not find any difficulty in understanding the use of stored procedure in his C#/VB.Net code. The real world stored procedures are much more complex and off course useful than these!
|
|
|
Category |
ADO.NET Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.2) By 8921 users |
Added on |
8/31/2014 |
Views |
67630 |
Rate it! |
|
|
Question:
How do stored procedure look like, can you provide some sample stored procedures?
Answer:
Here we are presenting a brief review of four basic type of stored procedure for SELECT, INSERT, UPDATE and DELETE operations. In SQL Server, you can create and add stored procedures to your database using the SQL Server Enterprise Manager.
UPDATE Stored Procedure A simple stored procedure to update a record is
CREATE PROCEDURE UpdateProc ( @artId as int, @title as varchar(100), @topic as varchar(100), @authorId as int, @lines as int, @dateOfPublishing as datetime) AS UPDATE Article SET title=@title, topic=@topic, authorId=@authorId, lines=@lines, dateOfPublishing=@dateOfPublishing WHERE artId=@artId GO
The name of stored procedure is UpdateProc and it has the input parameters for each of the fields of our Article table. The query to be executed when the stored procedure is run updates the record with the supplied primary key (@artId) using the supplied parameters. It is very similar to the code we have written to initialize command in the previous example and we hope you don’t have any problem in understanding this even you are not familiar with stored procedure.
INSERT Stored Procedure A simple stored procedure to insert a record is
CREATE PROCEDURE InsertProc ( @artId as int, @title as varchar(100), @topic as varchar(100), @authorId as int, @lines as int, @dateOfPublishing as datetime) AS INSERT INTO article (artId, title, topic, authorId, lines, dateOfPublishing) VALUES(@artId, @title, @topic, @authorId, @lines, @dateOfPublishing) GO
The stored procedure above is named InsertProc and is very similar to the UpdateProc except that here we are using the INSERT SQL statement instead of the UPDATE command.
DELETE Stored Procedure A simple stored procedure to delete a record is
CREATE PROCEDURE DeleteProc (@artId as int) AS DELETE FROM article WHERE artId = @artId GO
Here we have used only one parameter as to delete a record you only need its primary key value.
SELECT Stored Procedure A simple stored procedure to delete a record is
CREATE PROCEDURE SelectProc AS SELECT * FROM Article GO
This probably is the simplest of all. It does not take any parameter and only selects all the records from the Article table.
All the four stored procedures presented above are kept extremely simple so that the reader does not find any difficulty in understanding the use of stored procedure in his C#/VB.Net code. The real world stored procedures are much more complex and off course useful than these! Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
What is the advantage of using stored procedure over the SQL queries?
|
View Answer
|
|
What is a stored procedure?
|
View Answer
|
|
How do I write common code for different dot net framework data providers?
|
View Answer
|
|
How do I insert records using data reader?
|
View Answer
|
|
How do I read data (or records) from database using data reader?
|
View Answer
|
|
What is the architecture of connected environment of data access in ADO.Net?
|
View Answer
|
|
How do I update a record in the table using ADO.Net dataset?
|
View Answer
|
|
How do I save the changes, made in the dataset, to the database?
|
View Answer
|
|
How do I read records from the data tables?
|
View Answer
|
|
How do I define a data adapter?
|
View Answer
|
|
How do I create a command and supply the SQL query to ADO.Net? (Command object and command string)
|
View Answer
|
|
How do I find the connection string for the database server?
|
View Answer
|
|
What are the basic steps involved in data access with ADO.Net in disconnected environment?
|
View Answer
|
|
What is the Dot Net Framework data provider for OLEDB?
|
View Answer
|
|
What is the Dot Net Framework data provider for Oracle?
|
View Answer
|
|
What is the Dot Net Framework data provider for SQL Server?
|
View Answer
|
|
Why should one use a specialized data provider when the data can be accessed with general data providers?
|
View Answer
|
|
What are the standard dot net framework data providers that are shipped with the Dot Net Framework 1.1?
|
View Answer
|
|
What does it mean by Dot Net Framework Data Provider?
|
View Answer
|
|
How do different components of ADO.Net interact with each other in disconnected architecture?
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All ADO.NET Interview Questions & Answers - Exam Mode /
Learning Mode
|