最近在寫程式時有用到,主要是因為對方的資料庫不給還原、附加,只他X的給你個SQL 語法介面,要麻你就執行SQL插入,要麻你就等對方幫你匯入,

不過對方說要排隊,所以乾脆自己些產生資料表資料插入語法,引此找了一些特殊的SQL語法:

1.取得資料庫表單數量
select count(*) as totaltablenumber from sysobjects where xtype = 'U';

2.取得資料表名稱(tablename)及欄位數量(columnnumber)
select name as tablename, info as columnnumber from sysobjects where xtype = 'U';

3.取得某一資料表內所有欄位名稱
select b.name from sysobjects as a, syscolumns as b where a.xtype = 'U' and a.id = b.id and a.name='資料表單名稱';

3.1 取得某一資料表內所有欄位名稱
EXEC sp_columns 表單名稱
4.另外3的話不會照欄位順序排,請加入: order by b.colorder
5.取得資料庫所有資料表名稱
select * from sysobjects where xtype = 'U'
以上為SQL 2000 OK 2005請使用下列語法
6.在SQL SERVER 2005抓取資料庫的SQL語法

select name from master.dbo.sysdatabases

7.抓取資料表的SQL語法

select Table_name from INFORMATION_SCHEMA.TABLES order by Table_name

8.抓取欄位的SQL語法
select column_name from INFORMATION_SCHEMA.COLUMNS where table_name='TableName'

以上1~3.1 引用自 泰德的部落格
6~7 引用自威爺Plurk
arrow
arrow
    全站熱搜

    法蘭克不要怕 發表在 痞客邦 留言(0) 人氣()