Thursday, July 9, 2009

SQL Command for dispaly table on database

SQL Command สำหรับแสดงชื่อตารางทั้งหมดใน Database

EXEC sp_tables


ถ้าจะให้แสดงเฉพาะ Table ให้ใช้ Parameter @table_type
EXEC sp_tables @table_type = "'TABLE'"


เรียกใช้ Paremeter ตามลำดับ
EXEC sp_tables Customers, dbo, Northwind, "'TABLE'"

ผลลัพธ์


หรือใช้ Command นี้
SELECT name
FROM sys.tables

ผลลัพธ์



สามารถใช้ Command นี้แสดง Column ของ Table ที่ต้องการได้
ตัวอย่างแสดง Column ของ Table Customers ของ Database Northwind
SELECT name
FROM sys.syscolumns
WHERE (id = OBJECT_ID('Customers'))

ผลลัพธ์

No comments:

Post a Comment