Sql数据库杂谈

 

Sql数据库杂谈

1、TFDConnection.GetRDBMSKind: TFDRDBMSKind;//:能获取当前所使用的数据库类型

TFDRDBMSKinds = class
  public const
    Unknown = 0;
    Oracle = 1;
    MSSQL = 2;
    MSAccess = 3;
    MySQL = 4;
    DB2 = 5;
    SQLAnywhere = 6;
    Advantage = 7;
    Interbase = 8;
    Firebird = 9;
    SQLite = 10;
    PostgreSQL = 11;
    NexusDB = 12;
    DataSnap = 13;
    Informix = 14;
    Teradata = 15;
    MongoDB = 16;
    Other = 17;
  end;
  TFDRDBMSKind = type Integer;

-- 查所有用户表的字段总数:
select count(*) as 所有用户表的字段总数 from syscolumns s  where s.id in
(
  SELECT id
  FROM SysObjects
  WHERE  (XType='U') --用户表
  and name <> 'dtproperties'
)
go

-- 查用户表总数:
SELECT count(*) as 用户表总数
  FROM SysObjects
  WHERE  (XType='U') --用户表
  and name <> 'dtproperties'
go

-- 查所有用户表的字段的详情: 
SELECT TOP 100 PERCENT (CASE WHEN a.colorder = 1 THEN d.name ELSE d.name END) 
      AS 表名, a.colorder AS 字段序号, a.name AS 字段名, 
      (CASE WHEN COLUMNPROPERTY(a.id, a.name, 'IsIdentity') 
      = 1 THEN 'IDENTITY' ELSE '' END) AS 标识, (CASE WHEN
          (SELECT COUNT(*)
         FROM sysobjects
         WHERE (name IN
                   (SELECT name
                  FROM sysindexes
                  WHERE (id = a.id) AND (indid IN
                            (SELECT indid
                           FROM sysindexkeys
                           WHERE (id = a.id) AND (colid IN
                                     (SELECT colid
                                    FROM syscolumns
                                    WHERE (id = a.id) AND (name = a.name))))))) AND 
               (xtype = 'PK')) > 0 THEN 'primary key' ELSE '' END) AS 主键, 
      b.name AS 类型, a.length AS 占用字节数, COLUMNPROPERTY(a.id, a.name, 
      'PRECISION') AS 长度, ISNULL(COLUMNPROPERTY(a.id, a.name, 'Scale'), 0) 
      AS 小数位数, (CASE WHEN a.isnullable = 1 THEN 'NULL' ELSE 'not null' END) 
      AS 允许空, ISNULL(e.text, '') AS 默认值
FROM dbo.syscolumns a LEFT OUTER JOIN
      dbo.systypes b ON a.xtype = b.xusertype INNER JOIN
      dbo.sysobjects d ON a.id = d.id AND d.name <> 'dtproperties' LEFT OUTER JOIN
      dbo.syscomments e ON a.cdefault = e.id
WHERE (b.name IS NOT NULL) AND (d.status >= 0) AND (d.xtype = 'U')
ORDER BY d.xtype, d.name, a.id, a.colorder
go

-- 查用户表CtL00001的列的系统属性:
select * from syscolumns s  where s.id = object_id('CtL00001')
go

-- 查系统用户表的系统属性:
SELECT name 表名,info as 字段数,crdate 产生日期,refdate 参照日期,*
FROM SysObjects
WHERE  (XType='U')  -- 用户表
  and name <> 'dtproperties'
order by name 
go

-- 查用户表CtL00001的字段数:
select count(*) as 字段数 from syscolumns s  where s.id = object_id('CtL00001')
-- :等价于:

SELECT info as 字段数
FROM SysObjects
WHERE  (XType='U')  
        and  (name='CtL00001')    -- XType用户表
go

-- 获取当前数据库中的所有数据表对象  数据表对象:包含数据表Table、数据视图View、存储过程Procedure  ) :

--   and ( (XType='U')  -- 用户表 
--     or (XType='V')  -- 用户视图 
--     or (XType='P')  -- 用户存储过程 
--     or (XType='TR') -- 用户触发器 
--     or (XType='FN') -- 用户自定义函数

SELECT name 表名,info as 字段数,crdate 产生日期,refdate 参照日期,*
FROM SysObjects
WHERE  (XType='U')  -- 用户表
order by name 

-- 获取某个数据表对象的字段数  数据表对象:包含数据表Table、数据视图View、存储过程Procedure  )  :

select count(*) as 字段数 from syscolumns s  where s.id = object_id('CtL00001')
-- :等价于:

SELECT info as 字段数
FROM SysObjects
WHERE  (XType='U')  
        and  (name='CtL00001')    -- XType用户表

-- 查看系统中所有包含在某个表中的数据类型,其它哪些数据表对象也存在这些数据类型,它们的数据类型有哪些,数据类型、长度、字段名是什么:

select st.name as 'TypeName',sc.name,sc.length,* from syscolumns sc,systypes st 
where sc.xtype=st.xtype
and sc.id =(
select id from sysobjects where xtype='U' and name='ctl03001')

-- 查看某个表中,包含datetime数据类型的字段有哪些:

select sc.name as 字段名,sc.length as 字段长度,sc.xtype as 字段类型内部整数值,* from syscolumns sc
where sc.xtype <>61 -- 61:datetime
and sc.id =(
select id from sysobjects where xtype='U' and name='ctl03001')

-- 查询系统数据表的视图:

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[VIEW_Database_Table]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[VIEW_Database_Table]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

-- sql2000数据库系统查询
CREATE VIEW dbo.VIEW_Database_Table
AS
SELECT myID, totalRecord, status, category, type, XType, Name
FROM (SELECT TOP 1000
                  (SELECT COUNT(*)
                 FROM SysObjects
                 WHERE (status >= 0) AND ((XType = 'U')) AND Name <= a.Name) AS myID,
                  (SELECT COUNT(*)
                 FROM SysObjects
                 WHERE (status >= 0) AND ((XType = 'U'))) AS totalRecord, status, category, 
              type, XType, Name
        FROM SysObjects AS a
        WHERE (a.status >= 0) AND ((a.XType = 'U'))
        ORDER BY a.XType, a.Name, myID) b
WHERE (myID >= 1) AND (myID <= 1000)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

-- sql2000数据库系统查询
select status,category,type,XType,Name FROM SysObjects 
where ( status>=0 )
  and ( (XType='U')  -- 用户表 
--     or (XType='V')  -- 用户视图 
--     or (XType='P')  -- 用户存储过程 
--     or (XType='TR') -- 用户触发器 
--     or (XType='FN') -- 用户自定义函数

       ) 
order by XType,Name
-- 其中 type 或 xtype 值:U = 用户表 S = 系统表 V = 视图 FN = 标量函数 TF = 表函数 P = 存储过程  TR = 触发器
-- D = 默认值或 DEFAULT 约束 PK = PRIMARY KEY 约束 F = FOREIGN KEY 约束 UQ = UNIQUE 约束
go
-- 或 这样查表:
select * from dbo.sysobjects where OBJECTPROPERTY(id, N'IsUserTable') = 1 and name<>'dtproperties' order by XType,Name
go
-- select * from systypes where xtype<>xusertype and usertype>100  -- 用户自定义的数据类型
-- go
-- select * from sys.types where is_user_defined=1  -- sql2005
-- go
-- select * from systypes where usertype>100  -- 用户自定义的数据类型
-- go
-- select * from systypes where usertype<100  -- 系统的数据类型
-- go

-- 获取系统对象的定义 
select (case when a.colorder=1 then d.name else d.name end) 表名, 
a.colorder 字段序号,a.name 字段名,
(case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then 'IDENTITY'else '' end) 标识, 
(case when (SELECT count(*) FROM sysobjects 
where (name in (SELECT name FROM sysindexes 
where (id = a.id) AND (indid in 
(select indid FROM sysindexkeys 
where (id = a.id) AND (colid in 
(SELECT colid FROM syscolumns where (id = a.id) AND (name = a.name))))))) 
AND (xtype = 'PK'))>0 then 'primary key' else '' end) 主键,b.name 类型,a.length 占用字节数, 
COLUMNPROPERTY(a.id,a.name,'PRECISION') as 长度, 
isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0) as 小数位数,(case when a.isnullable=1 then 'null'else 'not null' end) 允许空, 
isnull(e.text,'') 默认值 --,isnull(g.[value], ' ') AS [说明]
from syscolumns a 
left join systypes b on (a.xtype=b.xusertype) 
inner join sysobjects d on a.id=d.id 
and d.name<>'dtproperties' 
left join syscomments e on a.cdefault=e.id 
--left join sys.extended_properties g on a.id=g.major_id AND a.colid=g.minor_id
--left join sys.extended_properties f on d.id=f.class and f.minor_id=0
where b.name is not null
and ( d.status>=0 )
and 
(
--     d.XType='U'         -- 用户表
--     or (d.XType='V')  -- 用户视图 
--     or 
(d.XType='P')  -- 用户存储过程 
--     or (d.XType='TR') -- 用户触发器 
)
-- and d.name='要查询的表' -- 如果只查询指定表等对象,加上此条件
 and d.name='sp_Clerk_idAppend' -- 如果只查询指定表等对象,加上此条件
order by d.XType,d.Name,a.id,a.colorder
go
-- 上面的视图:获取系统对象的定义
select * from VIEW_Table_Struct 
order by 表名,标识 desc,主键 desc 

-- 程序定制系统表CtL00001
select * from CtL00001 order by c_tablename

-- 查询数据库中系统级别的 用户表说明
select name, 
 ( select value from sysproperties where id = sysobjects.id and smallid=0) as 用户表说明 -- smallid=0 :用户表
from sysobjects
where ( status>=0 )
  and ( (XType='U')  -- 用户表 
--     or (XType='V')  -- 用户视图 
--     or (XType='P')  -- 用户存储过程 
--     or (XType='TR') -- 用户触发器 
--     or (XType='FN') -- 用户自定义函数
       ) 
order by XType,Name
go

-- 查询某张表的表字段系统说明 
select name, 
(select value from sysproperties where id = syscolumns.id and smallid=syscolumns.colid) as 表字段系统说明 
from syscolumns where id=object_id('CtL00001')
go

-- sql2000给表加说明
EXECUTE sp_addextendedproperty 'MS_Description', '数据字典表', 'user', 'dbo', 'table', 'CtL00001', NULL;
go
-- sql2000给表的字段加说明
select name, 
(select value from sysproperties where id = syscolumns.id and smallid=syscolumns.colid) as 描述 
from syscolumns where id=object_id('CtL00001')
go
-- 没有就增加:增加表CtL00001中列c_tableTitle的描述属性:MS_Description =  '表的中文含义'
EXECUTE sp_addextendedproperty N'MS_Description', '表的中文含义', 'user', 'dbo', 'table', 'CtL00001', 'column', 'c_tableTitle'
go
-- 有就更新:更新表CtL00001中列c_tableTitle的描述属性::MS_Description =  '表的中文含义'
EXEC sp_updateextendedproperty 'MS_Description','表中文含义','user',dbo,'table','CtL00001','column',c_tableTitle
go

select * from sysobjects where OBJECTPROPERTY(id, N'IsUserTable') = 1 order by XType,Name -- 查询系统对象
select name from syscolumns where ID=OBJECT_ID('CtL00001') -- 查询系统列
select * from sysproperties -- 查询系统的对象说明(附属属性)

-- 将牵引软件“系统对象视图VIEW_Table_Struct”中表对象列表写入到系统用户表类型(基础资料or业务数据)及状态表CtL00001中:

insert into CtL00001
select name as c_tablename,
null as c_tableTitle,
null as c_type,
null as c_use,
null as LastTime_UpdateData,
null as LastTime_UpdateStruct,
null as LastTime_Product
from VIEW_Database_Table
where  (status >= 0) and (XType = 'U')
and name not in
(
select c_tablename from CtL00001
)
order by name
 

/* -- 牵引软件所使用的SQL2000的数据类型:
bigint
char
datetime
decimal
image
int
numeric
numeric
nvarchar
smallint
tinyint
uniqueidentifier
varchar
    -- 所有SQL2000的数据类型:
bigint
binary
bit
char
datetime
decimal
float
image
int
money
nchar
ntext
numeric
nvarchar
real
smalldatetime
smallint
smallmoney
sql_variant
text
timestamp
tinyint
uniqueidentifier
varbinary
varchar

  TmyDBFieldsType =
  ( // SQL2000的25中数据类型枚举:
    binary, varbinary,              //可设置长度
    char, nchar, varchar, nvarchar, //可设置长度 ,可设置排序规则COLLATE NOCASE
    numeric, decimal,              //可设置精度和小数位,精度最大38
    bit,  datetime, smalldatetime,  timestamp,
    real,  float, bigint, int,  tinyint, smallint,
    money,  smallmoney,
    text, ntext, sql_variant,  image,
    uniqueidentifier
  );
*/

-- 查询系统用户表的数据结构的视图:

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[VIEW_Table_Struct]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[VIEW_Table_Struct]
GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO 
-- 查询系统用户表的数据结构
CREATE VIEW dbo.VIEW_Table_Struct
AS 
SELECT TOP 100 PERCENT (CASE WHEN a.colorder = 1 THEN d.name ELSE d.name END) 
      AS 表名, a.colorder AS 字段序号, a.name AS 字段名, 
      (CASE WHEN COLUMNPROPERTY(a.id, a.name, 'IsIdentity') 
      = 1 THEN 'IDENTITY' ELSE '' END) AS 标识, (CASE WHEN
          (SELECT COUNT(*)
         FROM sysobjects
         WHERE (name IN
                   (SELECT name
                  FROM sysindexes
                  WHERE (id = a.id) AND (indid IN
                            (SELECT indid
                           FROM sysindexkeys
                           WHERE (id = a.id) AND (colid IN
                                     (SELECT colid
                                    FROM syscolumns
                                    WHERE (id = a.id) AND (name = a.name))))))) AND 
               (xtype = 'PK')) > 0 THEN 'primary key' ELSE '' END) AS 主键, 
      b.name AS 类型, a.length AS 占用字节数, COLUMNPROPERTY(a.id, a.name, 
      'PRECISION') AS 长度, ISNULL(COLUMNPROPERTY(a.id, a.name, 'Scale'), 0) 
      AS 小数位数, (CASE WHEN a.isnullable = 1 THEN 'NULL' ELSE 'not null' END) 
      AS 允许空, ISNULL(e.text, '') AS 默认值
FROM dbo.syscolumns a LEFT OUTER JOIN
      dbo.systypes b ON a.xtype = b.xusertype INNER JOIN
      dbo.sysobjects d ON a.id = d.id AND d.name <> 'dtproperties' LEFT OUTER JOIN
      dbo.syscomments e ON a.cdefault = e.id
WHERE (b.name IS NOT NULL) AND (d.status >= 0) AND (d.xtype = 'U')
ORDER BY d.xtype, d.name, a.id, a.colorder
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

-- 产生随机数:

select cast( ceiling(rand() * 100) as int) -- 就会生成1至100之间任一整数
select cast( floor(rand() *100) as int) -- 就会生成0至99之间任一整数
select right('0000'+cast(12345.55 as varchar) ,11) --    共11位,前面不足位补齐0

select * from ctl03001
go
select * from ctl00701
go
select * from ctl00801
go
select 'E'+  right( '00000'+cast( cast( ceiling(rand() * 100) as int ) as varchar ),6 )
go
select mainten_clerk_id,clerk_id,* from PosBill
go

select * from sdf00504
go

-- 随机更新业务单据中的基础资料:-- 需多执行几次! 1、PosBill主表
--------------------------------------------------------开始
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO
declare @Aclerk_id varchar(50),@Acustomer_id varchar(30)
declare @ivt_oper_listing varchar(30) 
declare @ARandNumer int
select @ARandNumer=count(*) from sdf00504 

declare mycur  CURSOR FOR 
select ivt_oper_listing from PosBill  
OPEN mycur
FETCH NEXT FROM mycur 
  INTO @ivt_oper_listing
WHILE @@FETCH_STATUS = 0
begin
-- 1、更新PosBill主表的:员工及维护人员编码:
  -- select @Aclerk_id='E'+  right( '00000'+cast( cast( ceiling(rand() * 100) as int ) as varchar ),6 )   -- @ARandNumer: 10 :随机发生基数:视基础资料表的记录数做相应调整
  select @Aclerk_id='E'+  right( '00000'+cast( cast( ceiling(rand() * @ARandNumer) as int ) as varchar ),6 )   -- @ARandNumer: 10 :随机发生基数:视基础资料表的记录数做相应调整
  update b  set b.mainten_clerk_id=@Aclerk_id,b.clerk_id=@Aclerk_id
  from ctl00801 a,PosBill b 
  where ltrim(rtrim(coalesce(a.clerk_id,''))) = @Aclerk_id
    and a.com_id=b.com_id 
    and ltrim(rtrim(coalesce(b.ivt_oper_listing,''))) = ltrim(rtrim(coalesce(@ivt_oper_listing,'')))
-- 2、更新PosBill主表的:该员工所在的部门编码:
  update b set b.dept_id=ltrim(rtrim(coalesce(a.dept_id,'')))
  from ctl00801 a,PosBill b 
  where a.com_id=b.com_id and ltrim(rtrim(coalesce(b.clerk_id,''))) = ltrim(rtrim(coalesce(a.clerk_id,'')))  
    and ltrim(rtrim(coalesce(b.ivt_oper_listing,''))) = ltrim(rtrim(coalesce(@ivt_oper_listing,'')))
-- 3、更新PosBill主表的:客户名称:
  select @Acustomer_id='C'+  right( '00000'+cast( cast( ceiling(rand() * 100) as int ) as varchar ),6 )
  update b  set b.corp_name = ltrim(rtrim(coalesce(a.corp_sim_name,'')))
  from sdf00504 a,PosBill b 
  where ltrim(rtrim(coalesce(a.customer_id,''))) = @Acustomer_id
    and a.com_id=b.com_id 
    and ltrim(rtrim(coalesce(b.ivt_oper_listing,''))) = ltrim(rtrim(coalesce(@ivt_oper_listing,'')))

FETCH NEXT FROM mycur 
  INTO @ivt_oper_listing
end
CLOSE mycur
DEALLOCATE mycur 
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
--------------------------结束  ---  验证结果:::
select corp_name,dept_id,clerk_id,mainten_clerk_id,* from PosBill
go

-- 随机更新业务单据中的基础资料:-- 需多执行几次! 2、PosDetail从表:
--------------------------------------------------------开始
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO
declare @Aitem_id varchar(40)
declare @ivt_oper_listing varchar(30),@item_id varchar(40) 
declare @ARandNumer int
select @ARandNumer=count(*) from ctl03001 

declare mycur  CURSOR FOR 
select ivt_oper_listing,item_id from PosDetail  
OPEN mycur
FETCH NEXT FROM mycur 
  INTO @ivt_oper_listing,@item_id
WHILE @@FETCH_STATUS = 0
begin
-- 4、更新2、PosDetail从表的:物品内码及物品编码:
  select @Aitem_id='CP'+  right( '0000000'+cast( cast( ceiling(rand() * @ARandNumer) as int ) as varchar ),8 )  -- @ARandNumer: 6000 :随机发生基数:视基础资料表的记录数做相应调整
  update b  set b.item_id=@Aitem_id,b.peijian_id=@Aitem_id
  from ctl03001 a,PosDetail b 
  where ltrim(rtrim(coalesce(a.item_id,''))) = @Aitem_id
    and a.com_id=b.com_id 
    and ltrim(rtrim(coalesce(b.ivt_oper_listing,''))) = ltrim(rtrim(coalesce(@ivt_oper_listing,'')))
    and ltrim(rtrim(coalesce(b.item_id,''))) = ltrim(rtrim(coalesce(@item_id,'')))

FETCH NEXT FROM mycur 
  INTO @ivt_oper_listing,@item_id
end
CLOSE mycur
DEALLOCATE mycur 
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
--------------------------结束  ---  验证结果:::
select item_id,peijian_id,* from PosDetail
go


-- 随机更新业务单据中的基础资料:-- 需多执行几次! 2、PosDetail从表  (范围替换):
--------------------------------------------------------开始
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO
declare @Aitem_id varchar(40)
declare @ivt_oper_listing varchar(30),@item_id varchar(40) 
declare @ARandNumer int

select @ARandNumer=0

declare mycur  CURSOR FOR 
select ivt_oper_listing,item_id from PosDetail  
OPEN mycur
FETCH NEXT FROM mycur 
  INTO @ivt_oper_listing,@item_id
WHILE @@FETCH_STATUS = 0
begin
-- 5、更新2、PosDetail从表的:物品内码及物品编码  (物品内码是一个范围): 
  while not ( (@ARandNumer>2907) and (@ARandNumer<6090)   )
  begin
    select @ARandNumer=(ceiling(rand() * 6090)-ceiling(rand() * 2907))
  end

  if ( (@ARandNumer>2907) and (@ARandNumer<6090)   )
  begin
    select @Aitem_id='CP'+  right( '0000000'+cast( cast( @ARandNumer as int ) as varchar ),7 )  -- @ARandNumer: 是一个范围>2907且<6090 :随机发生基数:视基础资料表的记录范围做相应调整
    update b  set b.item_id=@Aitem_id,b.peijian_id=@Aitem_id
    from ctl03001 a,PosDetail b 
    where ltrim(rtrim(coalesce(a.item_id,''))) = @Aitem_id
      and a.com_id=b.com_id 
      and ltrim(rtrim(coalesce(b.ivt_oper_listing,''))) = ltrim(rtrim(coalesce(@ivt_oper_listing,'')))
      and ltrim(rtrim(coalesce(b.item_id,''))) = ltrim(rtrim(coalesce(@item_id,'')))
  end
  select @ARandNumer=0

FETCH NEXT FROM mycur 
  INTO @ivt_oper_listing,@item_id
end
CLOSE mycur
DEALLOCATE mycur 
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
--------------------------结束  ---  验证结果:::
select item_id,peijian_id,* from PosDetail
go

-- 随机取得表中的30条记录:
select top 30 * from ctl03001 order by newid() 

-- 查指定表中某Varchar字段列各行次所占的字节长度:

select c_tablename,(len( ltrim(rtrim(coalesce(DMLcreateForSqlite3,''))) )) as  DMLcreateForSqlite3 from CtL00001 
group by c_tablename,len( ltrim(rtrim(coalesce(DMLcreateForSqlite3,''))) ) 
order by len( ltrim(rtrim(coalesce(DMLcreateForSqlite3,''))) ) desc

-- 查数据库素有用户类型表的字段数:

SELECT info as 字段数,name
FROM SysObjects
WHERE  (XType='U') order by info desc

8、关于并发访问:

-- 下面的T-SQL 语句可以配置SQL Server 允许用户连接的并发数目:
exec sp_configure 'show advanced options', 1  -- 第一句用以表示显示sp_configure 系统存储过程高级选项,使用user connections 时,要求show advanced options 值为1。
go
exec sp_configure 'user connections', 100  -- 第二句配置并发连接数为100,0 表示不限制,但不表示无限:最大值:32767
go
exec sp_configure 'user connections', 0  -- 第二句配置并发连接数为100,0 表示不限制,但不表示无限:最大值:32767
go
-- 它总是返回32767,它并不是指上面设置的user connections,实际上它表示user connections 最大可设置为多少。默认情况下user connections 值是0,也就是说默认情况下SQL Server 的最大连接数是32767。 
select @@max_connections
go
-- 查询当前配置的并发连接数value:
select value,* from master.dbo.sysconfigures where [config]=103
go
-- 查询为当前登录账户的当前所有连接数: 
select loginame,count(1) as Nums
from master.dbo.sysprocesses
group by loginame
order by 2 desc
go
-- 如何监测SQLServer的连接数:
  -- 方法1: 
  -- 查询sql账户'sa'且主机为'YLMF-1806061359'的当前的所有连接:
select --* --  
  spid,kpid,ecid,status,loginame,hostname,cmd,dbid,program_name 
from master.dbo.sysprocesses where loginame='sa' and hostname='YLMF-1806061359'
go
  -- 方法2: 
  -- 查询sql账户sa当前的所有连接:
SP_WHO 'sa'
go
 

9、64位系统,APP运行时Odbc里面找不到Microsoft Access Driver(*.mdb)问题解决:

提示:[FireDAC][Phys][ODBC][Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序

通过C:\Windows\SysWOW64\odbcad32.exe启动32位版本ODBC管理工具即可。

10、sql server2000 查询版本号,是否打补丁

版本信息如下:

8.00.194 SQL Server 2000 RTM
8.00.384 SQL Server 2000 SP1
8.00.534 SQL Server 2000 SP2 November 30th, 2001
8.00.760 SQL Server 2000 SP3
8.00.2039 SQL Server 2000 SP4

在查询分析器中输入:select serverproperty('productlevel') 
如果没有打过SP,则为RTM,否则显示的是SP版本。

发布了61 篇原创文章 · 获赞 6 · 访问量 5571

猜你喜欢

转载自blog.csdn.net/pulledup/article/details/100786153
今日推荐