1、通过pip在Python中安装SQLServer的驱动程序。
在cmd命令中输入:python -m pip install pymssql
2、建立数据库以及测试表。
--drop database test;
create database test;
use test;
create table app_users (
user_id int identity(1,1) not null,
user_code varchar(60) not nul [阅读全文]
企业信息化建设
1、通过pip在Python中安装SQLServer的驱动程序。
在cmd命令中输入:python -m pip install pymssql
2、建立数据库以及测试表。
--drop database test;
create database test;
use test;
create table app_users (
user_id int identity(1,1) not null,
user_code varchar(60) not nul [阅读全文]
1、检查SQL阻塞原因
select blocking_session_id, wait_duration_ms, session_id
from sys.dm_os_waiting_tasks
where blocking_session_id is not null
2、检查前10个等待资源的SQL语句
select top 10 *
from sys.dm_os_wait_stats
order by wait_time_ms desc
3、查询显示 CPU [阅读全文]
--指定当前数据库
use master
declare @dbname varchar(40)
set @dbname = 'pos'
--print @dbname
--将目标数据库置为单用户状态
exec sp_dboption @dbname, N'single', N'true'
--如果必要允许丢失数据修复
dbcc checkdb(@dbname, REPAIR_ALLOW_DATA_LOSS)
--重建索引并修复
dbcc checkdb( [阅读全文]
机型:Dell R710。数据库: SQL Server 2005 X64。操作系统:Windows Server 2003 R2 X64。安装3次 ,到最后都提示服务无法启动,安装失败。
原因:在安装SQL 2005标准版(不多于四个CPU)、开发版、企业版(无限制)时,CPU的总核数必须是2的n次方。即核心数为1,2,4,8,16,32依次类推。因 Dell R710 是6核的,2个cpu,核心数为6 x 2=12,所以不能正常安装。只有将核心数更改为2的n次方时,才能顺利完成安装。 [阅读全文]
select request_session_id as spid, object_name(resource_associated_entity_id) as tablename
from sys.dm_tran_locks where resource_type = 'object'
--spid
被锁的表的进程
--tablename
被锁的表名
--解锁
kill spid [阅读全文]
declare @err int
set @err = 0
begin
begin transaction tc
insert into TWeb_Uff_Box(BoxCode) values('1')
set @err = @err + @@error
insert into TWeb_Uff_Box(BoxCode) values('2')
set @err = @err + @@error
insert into TWeb_Uff_Box(BoxCode) [阅读全文]
查找user_code出现重复的情况
select user_code, count(user_code) as num from app_users group by user_code having count(user_code) > 1
-- % 替代 0 个或多个字符
select * from app_users where user_name like 'i%'
-- _ 替代一个字符
select * from app_users where user_name like '_dodo.xin'
1、case。
select DeptName,
isnull(sum(1),0) as cAll,
isnull(sum(case when isnull(A01072,'已审核') = '已审核' then 1 end),0) as cYes,
isnull(sum(case when isnull(A01072,'未审核') = '未审核' then 1 end),0) as cNo
from view_UserStandInfo group by DeptName [阅读全文]