You are here:
Home >Archive for the ‘
SQL Tutorial’ Category
Definition and Usage The DATEDIFF() function returns the time between two dates. Syntax DATEDIFF(datepart,startdate,enddate) Where startdate and enddate are valid date expressions and datepart can be one of the following: datepart Abbreviation year yy, yyyy quarter qq, q month mm, m dayofyear dy, y day dd, d week wk, ww weekday dw, w hour hh [...]
Tags: DATEDIFF, SQL DATEDIFF, SQL Server DATEDIFF
The ALTER TABLE statement allows you to rename an existing table. It can also be used to add, modify, or drop a column from an existing table. Renaming a table The basic syntax for renaming a table is: ALTER TABLE table_name RENAME TO new_table_name; For example: ALTER TABLE suppliers RENAME TO vendors; This will [...]
Tags: add a column, add multiple columns, ALTER TABLE, DROP COLUMN, modify column, modify multiple columns, sql rename table
บทความความนี้จะมาแนะนำวิธีการลบอินเด็กซ์ เทเบิล วิว และดาต้าเบส ด้วยรูปแบบคำสั่งของ SQL Command ง่ายๆ ครับ. Indexes, tables, view,and databases can easily be deleted/removed with the DROP statement.
Tags: DROP DATABASE, DROP INDEX, DROP TABLE, DROP VIEW, SQL, SQL DROP, Statement
บทความนี้จะพูดถึงการสร้าง index หรือ CREATE INDEX ก่อนอื่นต้องมาทำความเข้าใจก่อนว่า Index มีหน้าอะไร Index ก็เหมือนสารบัญของหนังสือ ที่ช่วยให้เราอ่านหรือค้นหาเนื้้อหาที่ต้องการด้วยความเร็ว และเร็วกว่าการเปิดอ่านที่ละหน้าเพื่อหาเนื้อหาที่ต้องการ หากเป็นดาต้าเบสก็เหมือนกันเราก็จะต้องไม่ต้อง Scan table ทั้งหมดนั้นเอง The CREATE INDEX statement is used to create indexes in tables. Indexes allow the database application to find data fast; without reading the whole table.
Tags: CREATE INDEX, INDEX Statement, INDEX Syntax, SQL, SQL CREATE INDEX, สร้างอินเด็กซ์
SQL DEFAULT Constraint เป็นการกำหนดค่าเริ่มต้นเวลาเพิ่มข้อมูล แล้วไม่ได้มีค่าตัวแปรในคอลัมน์นี้ ก็จะมีการนำเอาค่าเริ่มต้นมาเพิ่มลงในคอลัมน์ The DEFAULT constraint is used to insert a default value into a column. The default value will be added to all new records, if no other value is specified.
Tags: Constraint, DEFAULT, DEFAULT Constraint, SQL, SQL DEFAULT
SQL CHECK Constraint ใช้สำหรับกำหนดค่าของข้อมูลก่อนทำการเพิ่มหรือแก้ไข หากไม่ตรงเงื่อนไขก็ไม่สามารถเพิ่มหรือแก้ไขได้ครับ หากกำหนด CHECK constraint on a single column จะกำหนดเพียงค่าเดียวของคอลัมน์ ก็จะทำการตรวจสอบเฉพาะคอลัมน์ที่กำหนดเท่านั้น หากกำหนด CHECK constraint on a table จะกำหนดได้หลายค่าของคอลัมน์ในเทเบิล
Tags: CHECK, CHECK Constraint, SQL, SQL CHECK
FOREIGN KEY เป็นค่าในเทเบิลที่เป็นค่าของ PRIMARY KEY อีกเทเบิลหนึ่ง A FOREIGN KEY in one table points to a PRIMARY KEY in another table.
Tags: Constraint, FOREIGN KEY, FOREIGN KEY Constraint, SQL
ข้อกำหนดห้ามซ้ำค่าหลัก PRIMARY KEY ในตารางของเทเบิลของฐานข้อมูล Primary key ต้องเป็นค่าไม่ซ้ำ Primary key จะต้องห้ามเป็นค่าว่างหรือ NULL Primary key สามารถกำหนดได้เพียงหนึ่งค่าเท่านั้นในหนึ่งเทเบิล
Tags: PRIMARY KEY, PRIMARY KEY Constraint, SQL PRIMARY KEY
คำสั่ง SQL UNIQUE Constraint ใช้สำหรับกำหนดค่าห้ามซ้ำของข้อมูลในคอลัมน์ของดาต้าเบส คำสั่ง UNIQUE and PRIMARY KEY ค่าห้ามซ้ำของข้อมูลในคอลัมน์ของดาต้าเบส คำสั่ง PRIMARY KEY constraint automatically แบบเพิ่มอัติโนมัติจะกำหนดให้เป็นค่าไม่ซ้ำอยู่แล้ว หมายเหตุ : คุณสามารถกำหนดค่า UNIQUE ได้หลายคอลัมน์ในหนึ่งตาราง แต่ค่า PRIMARY KEY จะกำให้ได้เพียงค่าเดียวเท่านั้นในหนึ่งตาราง
Tags: add unique constraint, Constraint, SQL UNIQUE, SQL UNIQUE Constraint, UNIQUE, UNIQUE Constraint
คำสั่ง SQL NOT NULL constraint เป็นคำสั่งที่ใช้สำหรับจำกัดค่าในคอลัมน์นั้นห้ามเป็นค่าว่าง หากมีการเพิ่มข้อมูลแล้วคอลัมน์ดังกล่าวว่างหรือไม่มีข้อมูลก็จะไม่สามารถเพิ่มหรือแก้ไขให้เป็นว่างได้ The NOT NULL constraint enforces a column to NOT accept NULL values. The NOT NULL constraint enforces a field to always contain a value. This means that you cannot insert a new record, or update a record without adding a value to this field. The following SQL enforces [...]
Tags: Constraint, NOT NULL Constraint, SQL, SQL NOT NULL, SQL Query