11月4号的随笔

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

alter table student add CONSTRAINT PRI_id primary key(id);

alter table student alter column int identity(1,1) not null

A. 在简单的游标中使用 FETCH

下例为 authors 表中姓以字母 B 开头的行声明了一个简单的游标,并使用 FETCH NEXT 逐个提取这些行。FETCH 语句以单行结果集形式返回由 DECLARE CURSOR 指定的列的值。

USE pubs
GO
DECLARE authors_cursor CURSOR FOR
SELECT au_lname FROM authors
WHERE au_lname LIKE "B%"
ORDER BY au_lname

OPEN authors_cursor

-- Perform the first fetch.
FETCH NEXT FROM authors_cursor

-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
   -- This is executed as long as the previous fetch succeeds.
   FETCH NEXT FROM authors_cursor
END

CLOSE authors_cursor
DEALLOCATE authors_cursor  
GO
问:如何知道一个数据库中有哪些表,不包括系统表,用一条SQL表示。
答:
use databasename
go
--'U'为你所建的用户表,'S'为系统表
select * from sysobjects where xtype like 'U'
go
问:此示例假设日期是 5 月 29 日。怎么得出5月
答:SELECT DATEPART(month, GETDATE())
GO
问:什么函数可以计算两个日期之间天数??
答:select datediff(dd,'2005/1/1','2005/1/8')
问:在运行 SQL Server 的计算机之间移动数据库
答:http://support.microsoft.com/default.aspx?scid=kb;zh-cn;314546
问:如何用sql语句修改密码
答:A.无原密码的情况下更改登录密码
下面的示例将登录 Victoria 的密码更改为 ok。
EXEC sp_password NULL, 'ok', 'Victoria'
B.更改密码
下面的示例将登录 Victoria 的密码由 ok 改为 coffee。
EXEC sp_password 'ok', 'coffee'
问:怎么提取前几行的数据 用sql、
答:select top n * from 表名 Where 条件 Order By id Desc
问:怎么修改数据库的名字
答:alter database 原数据库名称
modify name=新数据名称
问:select id,sum(money) from tbl_test group by id
这个没问题,但是我想只显示sum(money)=null的值
select id,sum(money) from tbl_test where sum(money)=null group by id 就不行了.
答:select id,sum(money)
from tbl_test group by id
having sum(money) is null
问:1. 性能监视器的作用
2. sql server 的事件探查器的作用
答:前者对硬件
后者对软件等
(在服务器端和客户端软件运行的时候监视SQL Server的性能,包括使用cpu的成本、io成本和总的成本等性能参数)

posted on 2005-11-20 22:48  潘伟  阅读(289)  评论(0编辑  收藏  举报