sql

来源:互联网 发布:淘宝修改差评 编辑:程序博客网 时间:2024/06/03 16:33

--创建链接服务器

exec sp_addlinkedserver  'ITSV ', ' ', 'SQLOLEDB ', '远程服务器名或ip地址 '

exec sp_addlinkedsrvlogin 'ITSV ', 'false ',null, '用户名 ', '密码 '

--查询示例

select * from ITSV.数据库名.dbo.表名

--导入示例

select * into表 from ITSV.数据库名.dbo.表名

--以后不再使用时删除链接服务器

exec sp_dropserver 'ITSV ', 'droplogins '

select substring((select name from goods where id=1),0,3)--截取字符串
select DATALENGTH((select name from goods where id=2))--查看字符串包含几个字符
select RIGHT((select name from goods where id=2),2)--截取从右边数的两个字符
EXEC master..xp_fixeddrives--查看硬盘分区
--比较两表是否相等
if (select checksum_agg(binary_checksum(*)) from goods)
     =
    (select checksum_agg(binary_checksum(*)) from sell)
print '相等'
else
print '不相等'

获取当前数据库中的所有用户表
select Name from sysobjects where xtype='u' and status>=0

select name fromsyscolumns where id in (select id fromsysobjects where type = 'u' and name = '表名')

一张表有一万多条记录,表的第一个字段 RecID 是自增长字段, 写一个SQL语句, 找出表的第31到第40个记录。

 select top 10 recid from A where recid not  in(select top 30 recid from A)

原创粉丝点击