</>
Skip to content
ASP lessons (24/40)

ASP — SQL

SELECT

<%
sql = "SELECT * FROM users WHERE active = 1"
Set rs = conn.Execute(sql)

Do While Not rs.EOF
    Response.Write(rs("name") & "<br>")
    rs.MoveNext
Loop
%>

INSERT

<%
sql = "INSERT INTO users (name, email) VALUES ('John', 'john@example.com')"
conn.Execute(sql)
%>

UPDATE

<%
sql = "UPDATE users SET email = 'new@email.com' WHERE id = 1"
conn.Execute(sql)
%>

DELETE

<%
sql = "DELETE FROM users WHERE id = 1"
conn.Execute(sql)
%>

Parameterized Queries

<%
Set cmd = Server.CreateObject("ADODB.Command")
cmd.ActiveConnection = conn
cmd.CommandText = "SELECT * FROM users WHERE name = ?"
cmd.Parameters.Append cmd.CreateParameter("name", 200, 1, 50, Request.QueryString("name"))
Set rs = cmd.Execute
%>

Mini Practice

  1. Execute SELECT
  2. Execute INSERT
  3. Execute UPDATE
  4. Use parameterized queries

Up Next

Continue with Authentication — user authentication.

Related Topics

Frequently Asked Questions about SQL

What is SQL in ASP?

SQL is a fundamental concept in ASP. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn SQL?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn SQL.

Why is SQL important in ASP?

SQL is essential for ASP development. Understanding this concept will help you write better code and solve real-world problems more effectively.