SQL Server 2000 重命名数据库
某项目之前的数据库有变化,但是以前写的程序是支持老数据库的,新数据库有一些问题,需要修改,但是数据库就重复了,于是就要把开发机上之前的数据库重新命名。
这里记录一下步骤(旧名称:MobileMsg,新名称:MobileMsg_old):
1、关掉企业管理器,打开查询分析器;
2、修改数据库名称:
EXEC sp_dboption 'MobileMsg', 'Single User', 'TRUE'
Go
EXEC sp_renamedb 'MobileMsg', 'MobileMsg_old'
Go
EXEC sp_dboption 'MobileMsg_old', 'Single User', 'FALSE'
Go
3、修改修改数据库的逻辑名称:
alter database MobileMsg_old modify file(name='MobileMsg_Data', newname='MobileMsg_old_Data')
alter database MobileMsg_old modify file(name='MobileMsg_Log', newname='MobileMsg_old_Log')
Go
4、关闭SQL Server服务,修改物理名称:
C:\Program Files\Microsoft SQL Server\MSSQL\Data\MobileMsg_old_Data.MDF
C:\Program Files\Microsoft SQL Server\MSSQL\Data\MobileMsg_old_Log.MDF
5、重命名数据库物理文件:
exec xp_cmdshell 'rename C:\Program Files\Microsoft SQL Server\MSSQL\Data\MobileMsg_Data.MDF C:\Program Files\Microsoft SQL Server\MSSQL\Data\MobileMsg_old_Data.MDF'
exec xp_cmdshell 'rename C:\Program Files\Microsoft SQL Server\MSSQL\Data\MobileMsg_Log.LDF C:\Program Files\Microsoft SQL Server\MSSQL\Data\MobileMsg_old_Log.LDF'
go
相关文档:
在Visual Studio 2008 中使用O/R设计器:
点添加项目,选择创建Linq to SQL项目,使用服务器资源管理器连接Northwind数据库,将Customers和Orders两个表拖到设计界面上,系统会自动创建app.config和Northwid.designer.cs,前者是配置连接数据库的连接字串;后者会生成一个继承自DataContext的类:NorthwindDataContext。
......
--1.关于where筛选器中出现指定星期几的求解
SQL code
--环境
create table test_1
(
id int,
value varchar(10),
t_time datetime
)
insert test_1
select 1,'a','2009-04-19' union
select 2,'b','2009-04-20' union
select 3,'c','2009-04-21' union
select 4,'d','2009-04-22' union
s ......
1 避免无计划的全表扫描
如下情况进行全表扫描:
- 该表无索引
- 对返回的行无人和限制条件(无Where子句)
- 对于索引主列(索引的第一 ......
merge [target] t
using [source] s on t.id = s.id
when matched then update t.name = s.name, t.age = s.age -- use "rowset1"
when not matched then insert values(id,name,age) -- use "rowset2"
when source not matched then delete; -- use "rowset3"
MERGE dbo.table AS im ......
在网上看到一个很好的例子讲解in和exists的区别,这里备忘下。
本示例所示查询查找由位于以字母 B 开头的城市中的任一出版商出版的书名:
USE pubs
SELECT title
from titles WHERE EXISTS
(SELECT *
from publishers
WHERE pub_id = titles.pub_id ......