freetds安装好之后可以查看配置:
root@localhost:/usr/local/freetds/bin# ./tsql -C
Compile-time settings (established with the "configure" script)
Version: freetds v0.91
freetds.conf directory: /usr/local/freetds/etc
MS db-lib source compatibility: no
Sybase binary compatibility: no
Thread safety: yes
iconv library: yes
TDS version: 7.0
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: no
freetds中配置以下内容:
vim /usr/local/freetds/etc/freetds.conf
[myserver]
host = mdb.zz.51fanli.it
port = 1433
tds version = 7.0
unixODBC中配置:
/usr/local/unixODBC/etc/odbc.ini
为以下内容:
[TEST1dsn]
Driver = mssql
Description = DSN
Trace = No
Servername = myserver
Database = testdb
UID = trace
测试freetds :
经常用的tsql语法如下:
1
2
3
4
5
|
说明:列出数据库里所有的表名
select
name
from
sysobjects
where
type=
'U'
说明:列出表里的所有的列
select
name
from
syscolumns
where
id=object_id(
'TableName'
)
|
1
|
select
name
from
sys.objects
where
type=
'U'
|
其中:
U 指的是用户创建的表。
S 指的是系统表。
TR 指的是触发器,
select * from sys.databases
go
select name from sys.databases
go
select * from sys.tables
go
其他可参考:
http://www.cnblogs.com/joeyupdo/archive/2012/11/09/2762823.html
http://blog.csdn.net/tsangchoonhsia/article/details/6606983