SQL日常积累
1、判断是否末级科目
select (case when exists(select 1 from GLAcct where FAcctID like a.FAcctID +'_%') then '不是' else '是' end) from GLAcct a
2、SQL Server2000修改sa密码
输入:osql -E (回车键)
sp_password @new='',@loginame='sa' (回车键) 如果要设置密码,就在@new=''的引号中输入对应的值即可
go (回车键)
3、在安装SQL Server 2008 R2 提示创建usersettings/microsoft.sqlserver.configuration.landingpage.properties.se....
造成这个原因是由于先装了VS开发环境造成的
解决方法:
删除下面文件;
路径为 C:\Users\rwx\AppData\Local\Microsoft_Corporation\LandingPage.exe_StrongName_ryspccglaxmt4nhllj5z3thycltsvyyx\10.0.0.0
注意:rwx 是当前登录的用户名称
4、SQLSERVER查询整个数据库中某个特定值所在的表和字段的方法
CREATE PROCEDURE [dbo].[SP_FindValueInDB]
(
@value VARCHAR(1024)
)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @sql VARCHAR(1024)
DECLARE @table VARCHAR(64)
DECLARE @column VARCHAR(64)
CREATE TABLE #t (
tablename VARCHAR(64),
columnname VARCHAR(64)
)
DECLARE TABLES CURSOR FOR
SELECT o.name, c.name FROM syscolumns c
INNER JOIN sysobjects o ON c.id = o.id
WHERE o.type = 'U' AND c.xtype IN (167, 175, 231, 239)
ORDER BY o.name, c.name
OPEN TABLES
FETCH NEXT FROM TABLES
INTO @table, @column
WHILE @@FETCH_STATUS = 0
BEGIN
SET @sql = 'IF EXISTS(SELECT NULL FROM [' + @table + '] '
SET @sql = @sql + 'WHERE RTRIM(LTRIM([' + @column + '])) LIKE ''%' + @value + '%'') '
SET @sql = @sql + 'INSERT INTO #t VALUES (''' + @table + ''', '''
SET @sql = @sql + @column + ''')'
EXEC(@sql)
FETCH NEXT FROM TABLES
INTO @table, @column
END
CLOSE TABLES
DEALLOCATE TABLES
SELECT * FROM #t
DROP TABLE #t
End
5、库中每张表的记录数
select b.name as tablename ,
a.rowcnt as datacount
from sysindexes a ,
sysobjects b
where a.id = b.id
and a.indid < 2
and objectproperty(b.id, 'IsMSShipped') = 0 order by 1 desc
select * from TZ_ZD_KMDM
select * from Tb0001_form
select * from tz0001_kmdm
select * from tz0001_pzgl_m
select * from tz0001_pzgl_d
6、如何解决sqlserver 2005 备份的时候无法选择除系统盘外的其他盘符?
在SQL server configuration manager中将sql server 服务的登录账户修改为local system即可