当前位置: 首页 > 工具软件 > FreeTDS > 使用案例 >

unixODBC , freetds , tsql

关冠宇
2023-12-01

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 :


root@localhost:/usr/local/freetds/bin# ./tsql -S myserver -D target_db -U trace -P trace
locale is "LC_CTYPE=en_US.UTF-8;LC_NUMERIC=zh_CN.UTF-8;LC_TIME=zh_CN.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=zh_CN.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=zh_CN.UTF-8;LC_NAME=zh_CN.UTF-8;LC_ADDRESS=zh_CN.UTF-8;LC_TELEPHONE=zh_CN.UTF-8;LC_MEASUREMENT=zh_CN.UTF-8;LC_IDENTIFICATION=zh_CN.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1> select @@version
2> go


Microsoft SQL Server 2005 - 9.00.4035.00 (X64) 
Nov 24 2008 16:17:31 
Copyright (c) 1988-2005 Microsoft Corporation
Enterprise Edition (64-bit) on Windows NT 5.2 (Build 3790: Service Pack 2)


(1 row affected)
1> 



经常用的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

 类似资料: