启动sql
成都创新互联公司作为成都网站建设公司,专注网站建设公司、网站设计,有关企业网站设计方案、改版、费用等问题,行业涉及白乌鱼等多个领域,已为上千家企业服务,得到了客户的尊重与认可。
server
Net
Start
MSSqlServer
暂停sql
server
Net
Pause
MSSqlServer
重新启动暂停的sql
server
Net
Continue
MSSqlServer
停止sql
server
Net
stop
MSSqlServer
命令行方式修改sql
server
sa
的密码
一直都是使用企业管理器操作sql的,昨天帮一朋友部署网站,租的国外vps主机,登陆上去只看到sql的图标正常运行的,企业管理器和查询分析器的影都没看到,汗一个。。。空间提供商也不给技术支持,晕了,只有自己想办法了。
今天网上google一下,终于搞定。
在cmd
窗口下
复制代码
代码如下:
C:\Documents
and
Settings\Administratorosql
-E
1
sp_password
null,'abc123','sa'
2
go
Password
changed.
1
exit
大功告成,sa的密码修改成了abc123
关键是osql这个东东,具体查看
SQL
Server
命令行工具
isql
和
osql
常用命令
命令行操作有时比在图形界面下用鼠标还高效,所以高手常用命令行操作,下面简介SQL
Server
命令行工具
isql
和
osql。
isql
实用工具使您得以输入
Transact-SQL
语句、系统过程和脚本文件;并且使用
DB-Library
与
SQL
Server
2000
进行通讯。
osql
实用工具使您得以输入
Transact-SQL
语句、系统过程和脚本文件。该实用工具通过
ODBC
与服务器通讯。
◆
信任连接:
isql
-E
或
osql
-E
◆
察看所有数据库:
use
master
exec
sp_helpdb
GO
◆
察看数据库
pubs:
use
master
exec
sp_helpdb
pubs
GO
◆
察看数据库
pubs
中的对象:
USE
pubs
EXEC
sp_help
GO
相当于
Oracle
的
SELECT
table_name
FROM
user_objects;
◆
察看数据库
pubs
中的表
employee
结构:
USE
pubs
EXEC
sp_help
employee
GO
相当于
Oracle
的
SQL*PLUS
中的
DESC
employees
◆
SELECT
语句:
USE
pubs
SELECT
*
FROM
employee
GO
◆
当使用单引号分隔一个包括嵌入单引号的字符常量时,用两个单引号表示嵌入单引号,例如:
SELECT
'O''Leary'
GO
◆
用7.个双引号表示嵌入双引号,例如:
SELECT
'O"Leary'
GO
◆
SQL
Server
数据库信息查询
use
master
exec
sp_helpdb
pubs
GO
或:
use
master
SELECT
name,
dbid
FROM
sysdatabases
GO
◆
查数据库对象
(相当于
Oracle
的
SELECT
*
FROM
user_tables;)
USE
pubs
EXEC
sp_help
GO
或
use
master
SELECT
name,
id
FROM
pubs.dbo.sysobjects
WHERE
type='U'
GO
◆
查字段
(相当于
Oracle
的
SQL*PLUS
中的
DESC
employees
)
USE
pubs
EXEC
sp_help
employee
GO
◆
查看指定
USE
pubs
SELECT
name,
id,
xtype,
length
FROM
syscolumns
WHERE
id=277576027
GO
USE
pubs
SELECT
*
FROM
syscolumns
WHERE
id=277576027
GO
◆
查看数据类型名字的定义:
SELECT
name,
xtype
FROM
systypes
GO
◆
从命令行启动“查询分析器”
isqlw
◆
isql命令
描述
GO
执行最后一个
GO
命令之后输入的所有语句。
RESET
清除已输入的所有语句。
ED
调用编辑器。
!!
command
执行操作系统命令。
QUIT
或
EXIT(
)
退出
isql。
CTRL+C
不退出
isql
而结束查询。
仅当命令终止符
GO(默认)、RESET、ED、!!、EXIT、QUIT
和
CTRL+C
出现在一行的开始(紧跟
isql
提示符)时才可以被识别。isql
忽视同一行中这些关键字后输入的任何内容。
你对应了几次员工表?一次吧
有两个员工编号,应该对应两次
运行 osql -S 【数据库服务器】 -U 【登陆用户名】 -P 【登陆密码】
出现 1 表示连接成功,这时候你可以输入sql语句来进行操作了。
以CMD命令行来操作Sqlserver,DotNetGeek 觉得没有多大的用处,而且,select出来的数据排版显示不整齐美观,
如果你在一台没有Sqlserver的电脑恰巧想去操作一下公司的Sqlserver,可以使用这个方法。
package com.oa.dao.impl; import java.sql.Connection; /SPAN/liimport java.sql.PreparedStatement; /SPAN/liimport java.sql.ResultSet; /SPAN/liimport java.sql.SQLException; /SPAN/liimport java.sql.Statement; /SPAN/liimport java.util.List; /SPAN/liimport java.util.Map; /SPAN/li import org.apache.commons.logging.Log; /SPAN/liimport org.apache.commons.logging.LogFactory; /SPAN/li import com.oa.core.DynaForm; /SPAN/liimport com.oa.dao.Dao; /SPAN/liimport com.oa.jdbc.ConnectionFactory; /SPAN/liimport com.oa.jdbc.DaoAccessException; /SPAN/liimport com.oa.jdbc.DybaBean; /SPAN/liimport com.oa.jdbc.JdbcPage; /SPAN/liimport com.oa.jdbc.Page; /SPAN/liimport com.oa.jdbc.RowsDynaClass; /SPAN/li /** /SPAN/li * 基类DAO,实现一些基本共有方法 * * @author Gao_wx Mar 26, 2008 */ public class BaseDao implements Dao { /SPAN/li protected Log logger = LogFactory.getLog(BaseDao.class); /SPAN/li // 获取数据库链接 /SPAN/li protected Connection getConnection() { /SPAN/li return ConnectionFactory.getConnection(); /SPAN/li } // 在此链接上,根据sql语句获取List /SPAN/li protected ListDybaBean getList(Connection conn, String sql) /SPAN/li throws DaoAccessException { /SPAN/li try { /SPAN/li Statement st = conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs = st.executeQuery(sql); return getList(rs); /SPAN/li } catch (SQLException e) { /SPAN/li throw new DaoAccessException(sql, e); /SPAN/li } } // 根据Result获取List /SPAN/li protected ListDybaBean getList(ResultSet rs) throws SQLException { /SPAN/li RowsDynaClass rsdc = new RowsDynaClass(rs); /SPAN/li return rsdc.getRows(); /SPAN/li } // 根据sql语句获取List /SPAN/li protected ListDybaBean getList(String sql) throws DaoAccessException { /SPAN/li Connection conn = getConnection(); return getList(conn, sql); /SPAN/li } // 在此连接上,根据sql语句,id加载一条记录 /SPAN/li protected DybaBean loadById(Connection conn, String sql, int id) /SPAN/li throws DaoAccessException { /SPAN/li try { /SPAN/li PreparedStatement pst = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); pst.setInt(1, id); /SPAN/li ResultSet rs = pst.executeQuery(); List list = getList(rs); if (list.size() 1) { /SPAN/li logger.warn("加载了2条以上的记录,请检查sql:" + sql); /SPAN/li } if (list.size() == 0) { /SPAN/li logger.warn("数据库没有此记录!"); /SPAN/li return null; /SPAN/li } else { /SPAN/li return (DybaBean) list.get(0); /SPAN/li } } catch (SQLException e) { /SPAN/li throw new DaoAccessException(sql, e); /SPAN/li } } // 根据sql语句,id,加载一条记录 /SPAN/li protected DybaBean loadById(String sql, int id) throws DaoAccessException { /SPAN/li Connection conn = getConnection(); return loadById(conn, sql, id); /SPAN/li } // 在此连接上,根据Sql和id删除一条记录,返回影响行数 /SPAN/li protected int deleteById(Connection conn, String sql, int id) /SPAN/li throws SQLException { /SPAN/li PreparedStatement pst = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); pst.setInt(1, id); /SPAN/li int del = pst.executeUpdate(); /SPAN/li return del; /SPAN/li } // 根据sql语句,id删除一条记录 /SPAN/li protected int deleteById(String sql, int id) throws DaoAccessException { /SPAN/li Connection conn = getConnection(); try { /SPAN/li int del = deleteById(conn, sql, id); /SPAN/li return del; /SPAN/li } catch (SQLException e) { /SPAN/li throw new DaoAccessException(sql, e); /SPAN/li } } protected Page getPage(DynaForm form, String sql) throws DaoAccessException { /SPAN/li Connection conn = getConnection(); Page page = getPage(conn, form, sql); return page; /SPAN/li } // 获取分页对象 /SPAN/li protected Page getPage(Connection conn, DynaForm form, String sql) /SPAN/li throws DaoAccessException { /SPAN/li int p = form.getInt("p"); /SPAN/li if (p 1) { /SPAN/li p = 1; /SPAN/li } int size = form.getInt("size"); /SPAN/li if (size 10) { /SPAN/li size = 10; /SPAN/li } Page page; try { /SPAN/li page = new JdbcPage(conn, sql, p, size); /SPAN/li } catch (SQLException e) { /SPAN/li throw new DaoAccessException(sql, e); /SPAN/li } return page; /SPAN/li } }
如果只是连接SQL
Server操作,一般就是使用
SQLConnection对象,如果要连接ACCESS或Excel
就以用到OLEDBConnection对象。如果是要对SQL
Server数据库增、删、改、查的操作,就还要用到:
–
Command对象,用于执行SQL命令
–
AdapterData对象(数据适配器)
,是连接数据库与数据集的数据桥梁
–
DataSet
对象(数据集),存放数据的内存区域
–
DataReader
对象(数据阅读器)
,用于执行Command命令后高速读取数据
下面是多数据库的基本操作类,供你参考。
Imports System
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Collections.Generic
Imports System.Text
Imports System.Data
Imports System.Configuration.ConfigurationSettings
Imports System.Data.OleDb
Public Class DB
Private Shared com As OleDb.OleDbCommand
Private Shared reader As OleDb.OleDbDataReader
Private Shared adapter As OleDb.OleDbDataAdapter
Private Shared conn As OleDb.OleDbConnection
''' summary
''' 获取数据库连接
''' /summary
''' value/value
''' returns/returns
''' remarks/remarks
Public Shared ReadOnly Property NewConn() As OleDbConnection
Get
Dim connectionString As String
'connectionString = System.Configuration.ConfigurationSettings.GetConfig("Supermarket")
'连接2010数据库
'connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\GCU.accdb"
'连接03-07数据库
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\JL\GCU.MDB"
'应该在这里先判断conn是否为Nothing
If conn Is Nothing Then
conn = New OleDb.OleDbConnection(connectionString)
End If
If conn.State ConnectionState.Open Then
conn.Open()
End If
Return conn
End Get
End Property
''' summary
''' 执行增删改(无参)
''' /summary
''' param name="sql"执行的Sql语句/param
''' returns/returns
''' remarks/remarks
Public Shared Function ExecuteNonQuery(ByVal sql As String) As Integer
com = New OleDb.OleDbCommand(sql, NewConn())
Return com.ExecuteNonQuery()
End Function
''' summary
''' 执行增删改(有参)
''' /summary
''' param name="sql"/param
''' param name="para"/param
''' returns/returns
''' remarks/remarks
Public Shared Function ExecuteNonQuery(ByVal sql As String, ByVal para As OleDbParameter()) As Integer
com = New OleDb.OleDbCommand(sql, NewConn)
com.Parameters.AddRange(para)
Return com.ExecuteNonQuery()
End Function
''' summary
''' 执行增删改的存储过程
''' /summary
''' param name="para"/param
''' param name="ProcedureName"/param
''' returns/returns
''' remarks/remarks
Public Shared Function ExecuteNonQuery(ByVal para As SqlParameter(), ByVal ProcedureName As String) As Integer
Dim cmd As OleDb.OleDbCommand
cmd = New OleDb.OleDbCommand()
cmd.Connection = NewConn()
cmd.CommandText = ProcedureName
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddRange(para)
Return com.ExecuteNonQuery
End Function
''' summary
''' 执行查询(返回一个结果集,无参)
''' /summary
''' param name="sql"/param
''' returns/returns
''' remarks/remarks
Public Shared Function GetScalar(ByVal sql As String) As String
Dim dataset As DataSet
dataset = New DataSet()
com = New OleDb.OleDbCommand(sql, NewConn)
adapter = New OleDbDataAdapter(com)
adapter.Fill(dataset)
If dataset.Tables.Count 0 And dataset.Tables(0).Rows.Count 0 Then
Return dataset.Tables(0).Rows(0)(0).ToString()
End If
Return "Null"
End Function
''' summary
''' 执行查询(返回一个结果集,有参)
''' /summary
''' param name="sql"/param
''' param name="para"/param
''' returns/returns
''' remarks/remarks
Public Shared Function GetScalar(ByVal sql As String, ByVal para As SqlParameter()) As Integer
com = New OleDb.OleDbCommand(sql, NewConn)
com.Parameters.AddRange(para)
Return Convert.ToInt32(com.ExecuteScalar())
End Function
''' summary
''' 执行查询(返回一行数据,无参)
''' /summary
''' param name="sql"/param
''' returns/returns
''' remarks/remarks
Public Shared Function GetReader(ByVal sql As String) As OleDbDataReader
com = New OleDb.OleDbCommand(sql, NewConn)
reader = com.ExecuteReader()
Return reader
End Function
''' summary
''' 执行查询(返回一行数据,有参)
''' /summary
''' param name="sql"/param
''' param name="para"/param
''' returns/returns
''' remarks/remarks
Public Shared Function GetReader(ByVal sql As String, ByVal para As SqlParameter()) As OleDbDataReader
com = New OleDb.OleDbCommand(sql, NewConn)
com.Parameters.AddRange(para)
reader = com.ExecuteReader()
Return reader
End Function
''' summary
''' 执行查询(返回一个数据集,无参)
''' /summary
''' param name="sql"/param
''' returns/returns
''' remarks/remarks
Public Shared Function GetDataSet(ByVal sql As String) As DataTable
Dim dataset As DataSet
dataset = New DataSet()
com = New OleDb.OleDbCommand(sql, NewConn)
adapter = New OleDbDataAdapter(com)
adapter.Fill(dataset)
Return dataset.Tables(0)
End Function
''' summary
''' 执行查询(返回一个数据集,有参)
''' /summary
''' param name="sql"/param
''' param name="para"/param
''' returns/returns
''' remarks/remarks
Public Shared Function GetDataSet(ByVal sql As String, ByVal para As SqlParameter()) As DataTable
Dim dataset As DataSet
dataset = New DataSet()
com = New OleDbCommand(sql, NewConn)
com.Parameters.AddRange(para)
adapter = New OleDbDataAdapter(com)
adapter.Fill(dataset)
Return dataset.Tables(0)
End Function
End Class