如何修改前n条记录数据库教程
“josonzcg”通过精心收集,向本站投稿了5篇如何修改前n条记录数据库教程,下面是小编精心整理后的如何修改前n条记录数据库教程,仅供参考,大家一起来看看吧。
篇1:如何修改前n条记录数据库教程
update ... where 主键列 in(select top 100 主键列 from table1)
或者
set rowcount 100
update 表 set ....
set rowcount 0
篇2:如何随机选取n条记录或者对记录作随机排序?数据库教程
排序|随机
. 如何得到随机排序结果?A. 要得到随机排序的列,或者返回x条随机选择的列,你可以使用随机数,但是RAND函数在一个查询中只能返回一个结果。你可以在NOWID函数返回的列上做ORDER BY。请看示例:
SELECT *
FROM Northwind..Orders
ORDER BY NEWID
SELECT TOP 10 *
FROM Northwind..Orders
ORDER BY NEWID()
这段话翻译得真是费劲,干脆不管原文,直接意译了。
不过提醒大家注意,这种方法是要对整个表扫描,然后产生一个计算列再排序的,最好不要对大的表作这样的操作,否则会很慢的。
Q. How can I randomly sort query results?
A. To randomly order rows, or to return x number of randomly chosen rows, you can use the RAND function inside the SELECT statement. But the RAND function is resolved only once for the entire query, so every row will get same value. You can use an ORDER BY clause to sort the rows by the result from the NEWID function, as the following code shows:
SELECT *
FROM Northwind..Orders
ORDER BY NEWID()
SELECT TOP 10 *
FROM Northwind..Orders
ORDER BY NEWID()
―SQL Server MVPs
篇3:用于查询当前数据库中所有表格的记录条数的脚本数据库教程
脚本|数据|数据库
--==========================================================================
-- 说明: 本脚本用于查询当前数据库中所有表格的记录条数
-- 并将结果存入TableInfo表中,不会删除以备用户再做处理与分析
-- 不过,最后请用户删除此表,
--==========================================================================
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TableSpace]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[TableSpace]
go
create table TableSpace
(
TableName varchar(20),
RowsCount char(11),
Reserved varchar(18),
Data varchar(18),
Index_size varchar(18),
Unused varchar(18)
)
go
declare @sql varchar(500)
declare @TableName varchar(20)
declare Cursor1 Cursor
for
select name from sysobjects where xtype='U'
open Cursor1
fetch next from Cursor1 into @TableName
while @@fetch_status = 0
begin
set @sql = 'insert into TableSpace '
set @sql = @sql + ' exec sp_spaceused '''+ @TableName + ''' '
exec (@sql)
fetch next from Cursor1 into @TableName
end
close Cursor1
deallocate Cursor1
go
--显示结果
select * from TableSpace
--order by TableName
--order by TableName ASC --按表名称,用于统计表
--order by RowsCount DESC --按行数量,用于查看表行数
--order by Reserved DESC, Data DESC --按占用空间
--order by Index_size DESC, Reserved DESC --按索引空间查看
go
--查看库的使用状况,可以随时执行的,
--exec sp_spaceused
--go
篇4:用Visual C#来修改和删除数据库记录.net
作者:王天 在以前的一篇文章《Visual C#中轻松浏览 数据库 记录》中,我们介绍了用Visual C#如何把数据表中的字段值绑定到文本框的属性上和如何操作数据记录指针,随意浏览数据表中的记录,本文就接着上一篇的内容,来介绍用Visual C#如何来修改和删除数据
作者:王天
在以前的一篇文章《Visual C#中轻松浏览数据库记录》中,我们介绍了用Visual C#如何把数据表中的字段值绑定到文本框的属性上和如何操作数据记录指针,随意浏览数据表中的记录。本文就接着上一篇的内容,来介绍用Visual C#如何来修改和删除数据记录。
一.程序设计和运行的环境设置:
(1).视窗服务器版
(2).Microsoft Aclearcase/“ target=”_blank“ >ccess Data Component 2.6 以上版本 ( MADC 2.6 )
(3).本文程序使用的数据库的介绍:
为了方便起见,在选用数据库方面选用了本地数据库Access 2000,当然你也可以选用其他类型的数据库,只需要更改文章后面的程序源代码中数据库的引擎,并更改对应的代码就可以了。本程序中使用的数据库名称为sample.mdb,在此数据库中有一张数据表books。此数据表的结构如下:
字段名称 字段类型 代表意思
Bookid 数字 序号
booktitle 文本 书籍名称
bookauthor 文本 书籍作者
bookprice 数字 价格
bookstock 数字 书架号
二.程序设计难点和应该注意的问题:
在程序设计中的重点和难点就是如何用Visual C#删除记录和如何修改记录。下面就这二个问题进行必要的论述:
(1).如何用Visual C#正确删除数据表中的记录:
在用Visual C#删除记录的时候要注意的是:必须从二个方面彻底删除记录,即从数据库和用Visual C#编程时产生的一个DataSet对象中彻底删除。在程序设计的时候,如果只是删除了DataSet对象中的记录信息,这种删除是一种伪删除。这是因为当他退出程序,又重新运行程序,会发现,那个要删除的记录依然还存在。这是因为DataSet对象只是对数据表的一个镜像,并不是真正的记录本身。但如果只是从数据库中删除记录,因为我们此时程序用到的数据集合是从DataSet对象中读取的,子DataSet对象中依然保存此条记录的镜像。所以就会发现,我们根本没有删除掉记录,但实际上已经删除了。此时只有退出程序,重新运行,才会发现记录已经删除了。本文使用的方法是删除以上二个方面的记录或记录镜像信息。当然你也可以使用其他的方法,譬如:首先从数据库中删除记录,然后重新建立数据连接,重新创建一个新的DataSet对象。这种方法虽然也可以达到相同目的,但显然相对繁杂些,所以本文采用的是第一种方法--直接删除。在程序中具体的实现语句如下:
//连接到一个数据库
string strCon = ” Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = sample.mdb “ ;
OleDbConnection myConn = new OleDbConnection ( strCon ) ;
myConn.Open ( ) ;
string strDele = ”DELETE FROM books WHERE bookid= “ + t_bookid.Text ;
OleDbCommand myCommand = new OleDbCommand ( strDele , myConn ) ;
//从数据库中删除指定记录
myCommand.ExecuteNonQuery ( ) ;
//从DataSet中删除指定记录信息
myDataSet.Tables [ ”books“ ] . Rows [ myBind.Position ] . Delete ( ) ;
myDataSet.Tables [ ”books“ ] . AcceptChanges ( ) ;
myConn.Close ( ) ;
(2).用Visual C#来修改数据表中的记录:
在用Visual C#修改记录和删除记录,在程序设计中大致差不多,具体的实现方式也是通过SQL语句调用来实现的。下面就是在程序中修改记录的具体语句:
//连接到一个数据库
string strCon = ” Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = sample.mdb “ ;
OleDbConnection myConn = new OleDbConnection ( strCon ) ;
myConn.Open ( ) ;
//从数据库中修改指定记录
string strUpdt = ” UPDATE books SET booktitle = '“
+ t_booktitle.Text + ”' , bookauthor = '“
+ t_bookauthor.Text + ”' , bookprice = “
+ t_bookprice.Text + ” , bookstock = “
+ t_bookstock.Text + ” WHERE bookid = “ + t_bookid.Text ;
OleDbCommand myCommand = new OleDbCommand ( strUpdt , myConn ) ;
myCommand.ExecuteNonQuery ( ) ;
myConn.Close ( ) ;
(3).在了解了如何用Visual C#删除和修改记录以后,结合《Visual C#中轻松浏览数据库记录》文的内容,就可以得到用Visual C#完成删除和修改数据记录的比较完整程序代码,以下是本文中介绍程序的运行后的程序界面:
点击小图放大,本文中程序运行后的界面
三.用Visual C#实现删除和修改数据库记录的完整源程序代码:
using System ;
using System.Drawing ;
using System.ComponentModel ;
using System.Windows.Forms ;
using System.Data.OleDb ;
using System.Data ;
public class DataEdit : Form. { private System.ComponentModel.Container components ;
private Button delete ;
private Button update ;
private Button lastrec ;
private Button nextrec ;
private Button previousrec ;
private Button firstrec ;
private TextBox t_bookstock ;
private TextBox t_bookprice ;
private TextBox t_bookauthor ;
private TextBox t_booktitle ;
private TextBox t_bookid ;
private Label l_bookstock ;
private Label l_bookprice ;
private Label l_bookauthor ;
private Label l_booktitle ;
private Label l_bookid ;
private Label label1 ;
private System.Data.DataSet myDataSet ;
private BindingManagerBase myBind ;
private bool isBound = false ;
//定义此变量,是判断组件是否已经绑定数据表中的字段
public DataEdit ( ) {
// 对窗体中所需要的内容进行初始化
InitializeComponent ( ) ;
//连接到一个数据库
GetConnected ( ) ;
}
//清除程序中用到的所有资源
public override void Dispose ( ) {
base.Dispose ( ) ;
components.Dispose ( ) ;
}
public void GetConnected ( )
{
try{
//创建一个 OleDbConnection对象
string strCon = ” Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = sample.mdb “ ;
OleDbConnection myConn = new OleDbConnection ( strCon ) ;
string strCom = ” SELECT * FROM books “ ;
//创建一个 DataSet对象
myDataSet = new DataSet ( ) ;
myConn.Open ( ) ;
OleDbDataAdapter myCommand = new OleDbDataAdapter ( strCom , myConn ) ;
myCommand.Fill ( myDataSet , ”books“ ) ;
myConn.Close ( ) ;
//判断数据字段是否绑定到 TextBoxes
if ( !isBound )
{
//以下是为显示数据记录而把数据表的某个字段绑定在不同的绑定到文本框”Text“属性上
t_bookid.DataBindings.Add ( ”Text“ , myDataSet , ”books.bookid“ ) ;
t_booktitle.DataBindings.Add ( ”Text“ , myDataSet , ”books.booktitle“ ) ;
t_bookauthor.DataBindings.Add ( ”Text“ , myDataSet , ”books.bookauthor“ ) ;
t_bookprice.DataBindings.Add ( ”Text“ , myDataSet , ”books.bookprice“ ) ;
t_bookstock.DataBindings.Add ( ”Text“ , myDataSet , ”books.bookstock“ ) ;
//设定 BindingManagerBase
//把对象DataSet和”books“数据表绑定到此myBind对象
myBind = this.BindingContext [ myDataSet , ”books“ ] ;
isBound = true ;
}
}
catch ( Exception e )
{
MessageBox.Show ( ”连接数据库发生错误为:“ + e.ToString ( ) , ”错误!“ ) ;
}
}
public static void Main ( ) {
Application.Run ( new DataEdit ( ) ) ;
}
private void InitializeComponent ( )
{
this.components = new System.ComponentModel.Container ( ) ;
this.t_bookid = new TextBox ( ) ;
this.previousrec = new Button ( ) ;
this.l_bookauthor = new Label ( ) ;
this.delete = new Button ( ) ;
this.t_booktitle = new TextBox ( ) ;
this.t_bookauthor = new TextBox ( ) ;
this.t_bookprice = new TextBox ( ) ;
this.l_bookprice = new Label ( ) ;
this.t_bookstock = new TextBox ( ) ;
this.l_bookstock = new Label ( ) ;
this.l_booktitle = new Label ( ) ;
this.update = new Button ( ) ;
this.nextrec = new Button ( ) ;
this.lastrec = new Button ( ) ;
this.firstrec = new Button ( ) ;
this.label1 = new Label ( ) ;
this.l_bookid = new Label ( ) ;
t_bookid.Location = new System.Drawing.Point ( 184 , 56 ) ;
t_bookid.Size = new System.Drawing.Size ( 80 , 20 ) ;
t_booktitle.Location = new System.Drawing.Point ( 184 , 108 ) ;
t_booktitle.Size = new System.Drawing.Size ( 176 , 20 ) ;
t_bookauthor.Location = new System.Drawing.Point ( 184 , 160 ) ;
t_bookauthor.Size = new System.Drawing.Size ( 128 , 20 ) ;
t_bookprice.Location = new System.Drawing.Point ( 184 , 212 ) ;
t_bookprice.Size = new System.Drawing.Size ( 80 , 20 ) ;
t_bookstock.Location = new System.Drawing.Point ( 184 , 264 ) ;
t_bookstock.Size = new System.Drawing.Size ( 80 , 20 ) ;
//以下是设定在程序中使用到的Label属性
l_bookid.Location = new System.Drawing.Point ( 24 , 56 ) ;
l_bookid.Text = ”序 号:“ ;
l_bookid.Size = new System.Drawing.Size ( 142 , 20 ) ;
l_bookid.Font = new System.Drawing.Font ( ”宋体“ , 12f ) ;
l_bookid.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ;
l_booktitle.Location = new System.Drawing.Point ( 24 , 108 ) ;
l_booktitle.Text = ”书 名:“ ;
l_booktitle.Size = new System.Drawing.Size ( 142 , 20 ) ;
l_booktitle.Font = new System.Drawing.Font ( ”宋体“ , 12f ) ;
l_booktitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ;
l_bookauthor.Location = new System.Drawing.Point ( 24 , 160 ) ;
l_bookauthor.Text = ”作 者:“;
l_bookauthor.Size = new System.Drawing.Size ( 142 , 20 ) ;
l_bookauthor.Font = new System.Drawing.Font ( ”宋体“ , 12f ) ;
l_bookauthor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ;
l_bookprice.Location = new System.Drawing.Point ( 24 , 212 ) ;
l_bookprice.Text = ”价 格:“ ;
l_bookprice.Size = new System.Drawing.Size ( 142 , 20 ) ;
l_bookprice.Font = new System.Drawing.Font ( ”宋体“ , 12f ) ;
l_bookprice.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ;
l_bookstock.Location = new System.Drawing.Point ( 24 , 264 ) ;
l_bookstock.Text = ”书 架 号:“ ;
l_bookstock.Size = new System.Drawing.Size ( 142 , 20 ) ;
l_bookstock.Font = new System.Drawing.Font ( ”宋体“ , 12f ) ;
l_bookstock.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ;
//以下设定程序中用到的功能按钮的属性及对应的事件
delete.Location = new System.Drawing.Point ( 104 , 352 ) ;
delete.ForeColor = System.Drawing.Color.Black ;
delete.Size = new System.Drawing.Size ( 80 , 24 ) ;
delete.Font = new System.Drawing.Font ( ”宋体“ , 9f ) ;
delete.Text = ”删除记录“ ;
delete.Click += new System.EventHandler ( GoDelete ) ;
update.Location = new System.Drawing.Point ( 204 , 352 ) ;
update.ForeColor = System.Drawing.Color.Black ;
update.Size = new System.Drawing.Size ( 80 , 24 ) ;
update.Font = new System.Drawing.Font ( ”宋体“ , 9f ) ;
update.Text = ”修改记录“ ;
update.Click += new System.EventHandler ( GoUpdate ) ;
firstrec.Location = new System.Drawing.Point ( 64 , 312 ) ;
firstrec.ForeColor = System.Drawing.Color.Black ;
firstrec.Size = new System.Drawing.Size ( 40 , 24 ) ;
firstrec.Font = new System.Drawing.Font ( ”宋体“ , 9f ) ;
firstrec.Text = ”首记录“ ;
firstrec.Click += new System.EventHandler ( GoFirst ) ;
previousrec.Location = new System.Drawing.Point ( 136 , 312 ) ;
previousrec.ForeColor = System.Drawing.Color.Black ;
previousrec.Size = new System.Drawing.Size ( 40 , 24 ) ;
previousrec.Font = new System.Drawing.Font ( ”宋体“ , 9f ) ;
previousrec.Text = ”上一条“ ;
previousrec.Click += new System.EventHandler ( GoPrevious ) ;
nextrec.Location = new System.Drawing.Point ( 208 , 312 ) ;
nextrec.ForeColor = System.Drawing.Color.Black ;
nextrec.Size = new System.Drawing.Size ( 40 , 24 ) ;
nextrec.Font = new System.Drawing.Font ( ”宋体“ , 9f ) ;
nextrec.Text = ”下一条“ ;
nextrec.Click += new System.EventHandler ( GoNext ) ;
lastrec.Location = new System.Drawing.Point ( 280 , 312 ) ;
lastrec.ForeColor = System.Drawing.Color.Black ;
lastrec.Size = new System.Drawing.Size ( 40 , 24 ) ;
lastrec.Font = new System.Drawing.Font ( ”宋体“ , 9f ) ;
lastrec.Text = ”尾记录“ ;
lastrec.Click += new System.EventHandler ( GoLast ) ;
label1.Location = new System.Drawing.Point ( 60 , 20 ) ;
label1.Text = ”用Visual C#来修改和删除数据库中的记录“ ;
label1.Size = new System.Drawing.Size ( 296 , 24 ) ;
label1.ForeColor = System.Drawing.SystemColors.Desktop ;
label1.Font = new System.Drawing.Font ( ”宋体“ , 14f ) ;
//设定程序的主窗体的属性
this.Text = ”用Visual C#来修改和删除数据库中的记录!“ ;
this.AutoScaleBaseSize = new System.Drawing.Size ( 5 , 13 ) ;
this.FormBorderStyle. = FormBorderStyle.FixedSingle ;
this.ClientSize = new System.Drawing.Size ( 394 , 425 ) ;
//在主窗体中加入组件
this.Controls.Add ( delete ) ;
this.Controls.Add ( update ) ;
this.Controls.Add ( lastrec ) ;
this.Controls.Add ( nextrec ) ;
this.Controls.Add ( previousrec ) ;
this.Controls.Add ( firstrec ) ;
this.Controls.Add ( t_bookstock ) ;
this.Controls.Add ( t_bookprice ) ;
this.Controls.Add ( t_bookauthor ) ;
this.Controls.Add ( t_booktitle ) ;
this.Controls.Add ( t_bookid ) ;
this.Controls.Add ( l_bookstock ) ;
this.Controls.Add ( l_bookprice ) ;
this.Controls.Add ( l_bookauthor ) ;
this.Controls.Add ( l_booktitle ) ;
this.Controls.Add ( l_bookid ) ;
this.Controls.Add ( label1 ) ;
}
//”删除记录“对应的事件
protected void GoDelete ( object sender, System.EventArgs e )
{
try{
//连接到一个数据库
string strCon = ” Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = sample.mdb “ ;
OleDbConnection myConn = new OleDbConnection ( strCon ) ;
myConn.Open ( ) ;
string strDele = ”DELETE FROM books WHERE bookid= “ + t_bookid.Text ;
OleDbCommand myCommand = new OleDbCommand ( strDele , myConn ) ;
//从数据库中删除指定记录
myCommand.ExecuteNonQuery ( ) ;
//从DataSet中删除指定记录
myDataSet.Tables [ ”books“ ] . Rows [ myBind.Position ] . Delete ( ) ;
myDataSet.Tables [ ”books“ ] . AcceptChanges ( ) ;
myConn.Close ( ) ;
}
catch ( Exception ed )
{
MessageBox.Show ( ”删除记录错误信息: “ + ed.ToString ( ) , ”错误!“ ) ;
}
}
//”修改记录“按钮对应的事件
protected void GoUpdate ( object sender , System.EventArgs e )
{
int i = myBind.Position ;
try{
//连接到一个数据库
string strCon = ” Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = sample.mdb “ ;
OleDbConnection myConn = new OleDbConnection ( strCon ) ;
myConn.Open ( ) ;
//从数据库中修改指定记录
string strUpdt = ” UPDATE books SET booktitle = '“
+ t_booktitle.Text + ”' , bookauthor = '“
+ t_bookauthor.Text + ”' , bookprice = “
+ t_bookprice.Text + ” , bookstock = “
+ t_bookstock.Text + ” WHERE bookid = “ + t_bookid.Text ;
OleDbCommand myCommand = new OleDbCommand ( strUpdt , myConn ) ;
myCommand.ExecuteNonQuery ( ) ;
myConn.Close ( ) ;
}
catch ( Exception ed )
{
MessageBox.Show ( ”修改指定记录错误: “ + ed.ToString ( ) , ”错误!“ ) ;
}
myBind.Position = i ;
}
//”尾记录“按钮对应的事件
protected void GoLast ( object sender , System.EventArgs e )
{
myBind.Position = myBind.Count - 1 ;
}
//”下一条“按钮对应的事件
protected void GoNext ( object sender , System.EventArgs e )
{
if ( myBind.Position == myBind.Count - 1 )
MessageBox.Show ( ”已经到尾记录!“ ) ;
else
myBind.Position += 1 ;
}
//”上一条“按钮对应的事件
protected void GoPrevious ( object sender , System.EventArgs e )
{
if ( myBind.Position == 0 )
MessageBox.Show ( ”已经到首记录!“ ) ;
else
myBind.Position -= 1 ;
}
//”首记录"按钮对应的事件
protected void GoFirst ( object sender , System.EventArgs e )
{
myBind.Position = 0 ;
}
}
四.编译源程序代码,生成执行文件:
得到了Data.cs源程序代码以后,经过下面编译命令编译成功后,即可得到执行文件data.exe:
csc /t:winexe /r:system.windows.forms.dll /r:system.data.dll data.cs
五.总结:
本文主要介绍了如何用Visual C#来删除和修改记录,
以及在处理这些操作的时候,应该注意的一些重要问题及处理的方法。如果你的机器已经满足本文要求的运行环境,那么在生成的执行文件目录中建立一个sample.mdb数据库,在数据库中创建一个books数据表,数据表的结构可按照本文上面提供的结构来建立,在这一切都完毕后,就可以运行程序,享受Visual C#给我们带来的数据操作的快感了。
原文转自:www.ltesting.net
篇5:9I中如何修改Ddid和Dbname方法测试小结数据库教程
测试环境:Windows2000 + Oracle 9.2.0.1
具体操作如下:
一、NID工具使用:(oracle工具,数据库安装完成后,就自动安装了),具体用法如看;
C:\>nid
DBNEWID: Release 9.2.0.1.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
Keyword Description (Default)
----------------------------------------------------
TARGET Username/Password (NONE)
DBNAME New database name (NONE)
LOGFILE Output Log (NONE)
REVERT Revert failed change NO
SETNAME Set a new database name only NO
APPEND Append to output log NO
HELP Displays these messages NO
用法举例:
Changing Only the DBID
The following example connects with operating system authentication and changes only the DBID:
% nid TARGET=/
Changing the DBID and Database Name
The following example connects as user SYS and changes the DBID and also changes the database name to test2:
% nid TARGET=SYS/oracle@test1 DBNAME=test2
Changing Only the Database Name
The following example connects as user SYSTEM and changes only the database name, and also specifies a log file for the output:
% nid TARGET=SYSTEM/manager@test2 DBNAME=test3 SETNAME=YES LOGFILE=dbid.out
二、修改步骤如下:
1)、SQL>conn sys/admin@test as sysdba
Connected.
SQL>shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
SQL>startup mount
ORACLE instance started.
Total System Global Area 101784276 bytes
Fixed Size 453332 bytes
Variable Size 75497472 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes
Database mounted.
SQL>host nid target=sys/admin@test dbname=testdb
DBNEWID: Release 9.2.0.1.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
Connected to database TEST (DBID=1835076349)
Control Files in database:
C:\ORACLE\ORADATA\TEST\CONTROL01.CTL
C:\ORACLE\ORADATA\TEST\CONTROL02.CTL
C:\ORACLE\ORADATA\TEST\CONTROL03.CTL
Change database ID and database name TEST to TESTDB? (Y/[N]) =>y
Proceeding with operation
Changing database ID from 1835076349 to 2321050327
Changing database name from TEST to TESTDB
Control File C:\ORACLE\ORADATA\TEST\CONTROL01.CTL - modified
Control File C:\ORACLE\ORADATA\TEST\CONTROL02.CTL - modified
Control File C:\ORACLE\ORADATA\TEST\CONTROL03.CTL - modified
Datafile C:\ORACLE\ORADATA\TEST YSTEM01.DBF - dbid changed, wrote new name
Datafile C:\ORACLE\ORADATA\TEST\UNDOTBS01.DBF - dbid changed, wrote new nam
Datafile C:\ORACLE\ORADATA\TEST\INDX01.DBF - dbid changed, wrote new name
Datafile C:\ORACLE\ORADATA\TEST\TOOLS01.DBF - dbid changed, wrote new name
Datafile C:\ORACLE\ORADATA\TEST\USERS01.DBF - dbid changed, wrote new name
Datafile D:\DATAFILE\PORMALS_SPA.DBF - dbid changed, wrote new name
Datafile C:\ORACLE\ORADATA\TEST\OEM_REPOSITORY.DBF - dbid changed, wrote ne
name
Datafile D:\DATAFILE\PORMALS_SPA_01.DBF - dbid changed, wrote new name
Datafile C:\ORACLE\ORADATA\TEST\TEMP01.DBF - dbid changed, wrote new name
Control File C:\ORACLE\ORADATA\TEST\CONTROL01.CTL - dbid changed, wrote new
name
Control File C:\ORACLE\ORADATA\TEST\CONTROL02.CTL - dbid changed, wrote new
name
Control File C:\ORACLE\ORADATA\TEST\CONTROL03.CTL - dbid changed, wrote new
name
Database name changed to TESTDB.
Modify parameter file and generate a new password file before restarting.
Database ID for database TESTDB changed to 2321050327.
All previous backups and archived redo logs for this database are unusable.
Shut down database and open with RESETLOGS option.
Succesfully changed database name and ID.
DBNEWID - Completed succesfully.
2)立即关闭数据库,修改db_name参数
SQL>shutdown immediate
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
在spfile文件里作相应修改,数据库db_name
SQL>startup mount;
SQL>alter system set db_name=testdb scope=spfile;
System altered.
注:如果是pfile文件,需手工修改db_name参数值
3)重新创建密码文件
SQL>host orapwd file=c:\oracle\ora92\database\pwwdtestdb.ora password=admin entries=8
SQL>conn sys/admin@test as sysdba
Connected to an idle instance.
4)、以Resetlogs选项打开数据库
SQL>startup mount
ORACLE 例程已经启动,
9I中如何修改Ddid和Dbname方法测试小结数据库教程
,
Total System Global Area 135338868 bytes
Fixed Size 453492 bytes
Variable Size 109051904 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes
数据库装载完毕。
SQL>alter database open resetlogs;
数据库已更改。
5)、查看修改是构成功
SQL>select dbid,name from v$database;
DBID NAME
---------- ---------
2321050327 TESTDB
SQL>
注意:2、3不能颠倒,否则,重建口令文件是不可用的
参考文档:download-west.oracle.com/ ... 52/ch14.htm#1004918
【如何修改前n条记录数据库教程】相关文章:
8.任前谈话记录范文
9.任前廉政谈话记录






文档为doc格式