Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> MySQL

การป้อน MySQL Queries

ก่อนป้อน queries ต้องเชื่อมต่อ server แล้ว คิวรีให้ version และ current date:

mysql> SELECT VERSION(), CURRENT_DATE;

Note: 'VERSION()' และ 'CURRENT_DATE' case-insensitive

  • SQL query จบด้วย semicolon
  • Issue query → mysql ส่ง server execute → results displayed → 'mysql>' prompt ใหม่
  • Output = tabular (rows/columns) แถวแรก = column names
  • แสดง rows returned และ execution time (performance indicator)

Multiple statements ในบรรทัดเดียว:

mysql> SELECT VERSION(); SELECT NOW();

MySQL หาจบ query ดู terminating semicolon ไม่ใช่ end of input line:

mysql> SELECT
    -> USER()
    -> ,
    -> VERSION();

Prompt เปลี่ยน 'mysql>' → '->' ตอน multi-line query (ยังไม่เจอ semicolon)