First are the keywords `CREATE TABLE` followed by the table name. This is a perfect example of the SQL simplicity and similarity with English language. Keywords are followed by an open parenthesis, where additional parameters are defined, column name and column data type, followed by a closing parenthesis. It is important to note that all SQL statements should end with a `;`.
There are few rules that need to be followed. The table and column names must start with a letter and can be followed by letters, numbers, or underscores. They must not exceed a total of 30 characters in length. SQL reserved keywords as names for tables or column names (such as `select`, `create`, `insert`, etc.) are forbidden.
In our example, the most simple column names would be `TEXT`, `CHARACTER`, `MOVIE`, and `YEAR`. But the problem is that most of those names are reserved words. To avoid any possible conflicts, in our example we will create column names with a prefix `Q_`.
Data types differentiate between different databases, but here are the most common ones for MySQL. They can be grouped into three main categories, Numeric, Date and String.
แรกสร้างตารางคำหลัก ` ` ตามด้วยชื่อตาราง นี้เป็นตัวอย่างที่สมบูรณ์แบบของ SQL ที่เรียบง่ายและความคล้ายคลึงกับภาษา คำหลักจะตามด้วยวงเล็บเปิดที่พารามิเตอร์เพิ่มเติมมีการกำหนดคอลัมน์ชื่อคอลัมน์ประเภทข้อมูลและตามด้วยวงเล็บปิด . มันเป็นสิ่งสำคัญที่จะทราบว่า งบ SQL ทั้งหมดควรจะจบลงด้วย ` ; ` .
มีกฎที่ต้องทำตาม ชื่อตารางและคอลัมน์จะต้องเริ่มต้นด้วยตัวอักษร และสามารถตามด้วยตัวอักษร ตัวเลข หรือเครื่องหมาย พวกเขาต้องไม่เกิน 30 ตัวอักษรในความยาว SQL สงวนคำหลักเป็นชื่อตารางหรือชื่อคอลัมน์ ( เช่น " เลือก ` ` ` ` ` สร้าง , แทรก , ฯลฯ ) จะห้าม
ในตัวอย่างของเรา ชื่อคอลัมน์ที่ง่ายที่สุดจะได้รับข้อความ ` ` ,` ` ` ` ละคร , ภาพยนตร์ และปี ` ` แต่ปัญหาคือว่าส่วนใหญ่ของชื่อที่สงวนคำ เพื่อหลีกเลี่ยงความขัดแย้งที่เป็นไปได้ใด ๆ ในตัวอย่างของเรา เราจะสร้างชื่อคอลัมน์ที่มีคำนำหน้า q_ ` ` .
ชนิดข้อมูลความแตกต่างระหว่างฐานข้อมูลที่แตกต่างกัน แต่ที่นี่มีอยู่ทั่วไปมากที่สุดสำหรับ MySQL พวกเขาสามารถแบ่งออกเป็นสามประเภทหลัก , ตัวเลข , วันที่และสตริง
การแปล กรุณารอสักครู่..
