C# 用SQL新建数据库
1. 程序如下:
string str = "Create Database " + "DBname";
string con = "Data Source=10.0.0.249\\sql2005;Initial Catalog=master;Persist Security Info=True;User ID=sa;Password=sa";
SqlConnection myConn = new SqlConnection(con);
SqlCommand myCommand = new SqlCommand(str, myConn);
try
{
myConn.Open();
myCommand.ExecuteNonQuery();
Console.WriteLine("SQL 语句执行完成。", "MyProgram");
}
catch (System.Exception ex)
{
Console.WriteLine(ex.ToString(), "MyProgram");
}
finally
{
if (myConn.State == ConnectionState.Open)
{
myConn.Close();
相关文档:
-- 查看当前db的登陆
select * from sys.sql_logins
-- 审核登陆数据库的用户
sql server managerment studio中,右键点开服务器的属性,在安全性页签中, 选中审核“成功和失败的登陆”,所有登陆都会在..MSSQL\Log\ERRORLOG中记录一条记录。
如果勾选“启用C2审核跟踪”,将会在..MSSQL\Log\目录 ......
SQL语句的优化就是将性能较低的SQL语句转换达成同样目的性能优异的SQL语句
下面我们一起来看看一些可以优化SQL的方法,希望大家多提出意见我们共同学习或者是大家有什么好的优化方法可以提出来共享一下。
第一种优化(使用指定列代替”*”)
使用“*”可以降低编写SQL语 ......
本文来自:http://hi.baidu.com/darkroot/blog/item/7b74be2cf06d76e78b139903.html
declare @tbName nvarchar(500)
declare @ct int
declare @csql nvarchar(500)
declare &n ......
2008数据库附加
/*
网上看到的整理了一下。
原文地址http://database.51cto.com/art/201003/190984.htm
在SQL Server 7.0中,微软推出了sp_attach_db和sp_attach_single_file_db系统存储过程。
它对于SQL Server数据库管理员执行下面的任务是非常方便的:
1 使用sp_attach_d ......
有执行sql条件语句where id in(@参数)的时候,如果处理不当,就会出现问题:
如下面这个存储过程:
alter proc Web_gettwtwgoldgameserverGoldSell
@ID int
as
declare @twgoldsellID nvarchar(1000)
select @twgoldsellID=twgoldsellID from twgoldgameserver where ID=@ID
set @twgoldsellID=replace(@twgoldsell ......