How to manipulate data or values in my tables SQL Server

346360 pts.
Tags:
Database
SQL Server
A question emailed to us i can now connect the database i made (in mssql server) but the problem is i do not know how to manipulate the data or values in my tables. for example, in my login program. i do not know how to declare that the input of the user must compare first to the login_table (in my database) rows. i really need a help.

Answer Wiki

Thanks. We'll let you know when a new response is added.

To see if a value exists in a table you use a SELECT statement.

<pre>SELECT *
FROM TableName
WHERE UserName = ‘The UserName’</pre>

When building an appliction you would typically use a stored procedure to handle all data lookups and modification. You would pass the stored procedure the values you want to check. Something like this.

<pre>CREATE PROCEDURE usp_CheckLogin
@UserName nvarchar(50)
AS
IF EXISTS (SELECT * FROM TableName WHERE UserName = @UserName)
BEGIN
SELECT ‘User Exists’
END
ELSE
BEGIN
SELECT ‘User Does Not Exist’
END
GO</pre>

You can now run this procedure passing it the username you want to check.

<pre>exec usp_CheckLogin @UserName = N’mrdenny’</pre>
If there is a record in the table with the username of “mrdenny” then the response will be “User Exists”, otherwise it will be “User Does Not Exist”.

Data modification is done in a simalar way via the INSERT, UPDATE or DELETE statements depending on what operation you want to perform.

I would recommend reading up on these commands in Books OnLine (BOL). BOL is the help documentation which comes with MSDE and can provide you with more examples of the syntax of these commands.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following