subject:CREATE TABLE
syntax:CREATE TABLE database_name.owner_name.tbl_name
(
column_name datatype [ IDENTITY | CONSTRAINT | NULL | NOT NULL ]
| column_name AS computed_column_expression
)
[ ON { filegroup | DEFAULT } ]
content:ใช้ในการสร้าง table
โดย computed_column_expression คือ column ที่เกิดจากการคำนวณของ column อื่น
โดย computed_column_expression มีข้อจำกัด ดังนี้
1) column ที่นำมาคำนวณต้องเป็น column จาก table เดียวกัน
2) column นี้จะเป็น INDEX, Primary Key, Foreign Key ไม่ได้
3) ไม่สามารถกำหนด DEFAULT ของข้อมูลได้
4) ไม่สามารถเปลี่ยนแปลงข้อมูลโดยจะ INSERT หรือ UPDATE ได้
example:CREATE TABLE tbl_orders
(
id int IDENTITY NOT NULL,
price money NOT NULL,
discount int NOT NULL,
price_net AS ( price * ( 100 - discount ) ) / 100
)
ON CustomerGroup