You are here: Home >Archive for the ‘SQL Tutorial’ Category

SQL Server DATEDIFF() Function

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: , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

ALTER TABLE Statement

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: , , , , , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

SQL DROP INDEX, DROP TABLE, DROP VIEW, DROP DATABASE

บทความความนี้จะมาแนะนำวิธีการลบอินเด็กซ์ เทเบิล วิว และดาต้าเบส ด้วยรูปแบบคำสั่งของ SQL Command ง่ายๆ ครับ. Indexes, tables, view,and databases can easily be deleted/removed with the DROP statement.

Tags: , , , , , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

SQL CREATE INDEX 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: , , , , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

SQL DEFAULT Constraint

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: , , , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

SQL CHECK Constraint

SQL CHECK Constraint ใช้สำหรับกำหนดค่าของข้อมูลก่อนทำการเพิ่มหรือแก้ไข หากไม่ตรงเงื่อนไขก็ไม่สามารถเพิ่มหรือแก้ไขได้ครับ หากกำหนด CHECK constraint on a single column  จะกำหนดเพียงค่าเดียวของคอลัมน์ ก็จะทำการตรวจสอบเฉพาะคอลัมน์ที่กำหนดเท่านั้น หากกำหนด CHECK constraint on a table  จะกำหนดได้หลายค่าของคอลัมน์ในเทเบิล

Tags: , , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

SQL FOREIGN KEY Constraint

FOREIGN KEY เป็นค่าในเทเบิลที่เป็นค่าของ PRIMARY KEY อีกเทเบิลหนึ่ง A FOREIGN KEY in one table points to a PRIMARY KEY in another table.

Tags: , , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

SQL PRIMARY KEY Constraint

ข้อกำหนดห้ามซ้ำค่าหลัก PRIMARY KEY ในตารางของเทเบิลของฐานข้อมูล Primary key ต้องเป็นค่าไม่ซ้ำ Primary key จะต้องห้ามเป็นค่าว่างหรือ NULL Primary key สามารถกำหนดได้เพียงหนึ่งค่าเท่านั้นในหนึ่งเทเบิล

Tags: , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

SQL UNIQUE Constraint

คำสั่ง SQL UNIQUE Constraint ใช้สำหรับกำหนดค่าห้ามซ้ำของข้อมูลในคอลัมน์ของดาต้าเบส คำสั่ง UNIQUE and PRIMARY KEY ค่าห้ามซ้ำของข้อมูลในคอลัมน์ของดาต้าเบส คำสั่ง PRIMARY KEY constraint automatically แบบเพิ่มอัติโนมัติจะกำหนดให้เป็นค่าไม่ซ้ำอยู่แล้ว หมายเหตุ : คุณสามารถกำหนดค่า UNIQUE ได้หลายคอลัมน์ในหนึ่งตาราง แต่ค่า PRIMARY KEY จะกำให้ได้เพียงค่าเดียวเท่านั้นในหนึ่งตาราง

Tags: , , , , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

SQL NOT NULL 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: , , , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS