Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
207 views
in Technique[技术] by (71.8m points)

What does the "@" symbol do in SQL?

I was browsing through the questions and noticed this:

SELECT prodid, issue
FROM Sales 
WHERE custid = @custid 
AND datesold = SELECT MAX(datesold) 
             FROM Sales s 
             WHERE s.prodid = Sales.prodid
                  AND s.issue = Sales.issue
                  AND s.custid = @custid

I was wondering what the "@" does in front of custID? Is it just a way of referencing the custID from the table being selected?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The @CustID means it's a parameter that you will supply a value for later in your code. This is the best way of protecting against SQL injection. Create your query using parameters, rather than concatenating strings and variables. The database engine puts the parameter value into where the placeholder is, and there is zero chance for SQL injection.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...