‘壹’ sqlSERVER登录语句怎么写
----新建登录角色用户:
use master
exec sp_addlogin 'lx','123',['pubs']--新建登录lx,密码123, [默认数据库pubs]
use pubs
go
exec sp_grantdbaccess 'lx','slx'--为pubs添加一个用户(角色为public)
exec sp_addrolemember db_owner ,slx--将slx添加到db_owner角色组
# 注:可合并做一步 :
use pubs
exec sp_adser lx,slx,db_owner
----------另外可以搞一个sa这样的牛逼账户,权限很高,你自己测试吧
exec sp_addsrvrolemember 'lx','sysadmin'--以sa登录执行,添加登录lx到system administrators中
‘贰’ sqlserver中的作业怎么写
先打开SQL server的代理
然后在代理那里右键---新建作业--然后新建步骤--步骤里执行你需要执行的代码--新建计划,计划里写什么时候执行。
完毕
创建完成之后 一定要右键 开始执行作业
‘叁’ SQLServer 语句怎么写
嵌套比较多,你慢慢看。
select D.address, D.time, D.value
from (select A.address, A.time, A.value
from A
union
select B.address, B.time, B.value
from B) D,
(select C.Address, max(C.time) as maxTime
from (select A.address, A.time, A.value
from A
union
select B.address, B.time, B.value
from B) C
group by C.address) E
where D.address = E.address
and D.time = E.maxTime
‘肆’ 在.net上用c#编写程序用来维护和管理SQLserver数据库应该怎么编
说来话长哦~~~
最简单直接的方法有几个步骤:
一. 准备数据库的连接字符串, 可以手动写,也可以从CONFIG中读取,如手写的:
string DbConnectionString = "Server=.\SqlExpress;Database=Northwind;Integrated Security = true";
连接字符串至少要包含数据库服务器,数据库本身以及连接时的安全性三项,很多时安全性会由UID和PWD组成,另外还有超时等信息,也可在连接字符串里指定.
二.在C#的程序里指定命名空间.
using System.Data.SqlClient;
因为这个空间下的类是.NET专门为访问和维护SQLServer而量身定做的,一会就会用到.
三.利用第一步得到的连接字符串,可以声明一个SqlConnection对象,用它就可以维护一条指向所需SQLServer的连接.
SqlConnection conn = new SqlConnection(DbConnectionString);
四.打开第三步建好的连接对象.
conn.Open();
五.数据库现在已经连接成功,准备就绪,现在该干嘛干嘛,如
下代码把其中Employees表中前三条记录的City字段值改成字符串'Beijing',代码如下:
string QueryString = "Update Employees set City='Beijing' Where EmployeeID in (Select top 3 EmployeeID From Employees)";
SqlCommand cmd = new SqlCommand(QueryString, conn);
cmd.ExecuteNonQuery();
六.完成对数据库的操作之后,记得一定要把连接关闭.确保不再使用之后,有必要对连接资源进行释放.因为连接资源对数据库来说是很宝贵的.
conn.Close();
conn.Dispose();
基本上就完成了, 通过对第五步的更改, 可以实现你所问的数据库维护和管理功能. 上面的代码我在Visual Studio 2005 + SqlExpress下调试通过的,可以参考使用呵呵.
‘伍’ sqlserver怎么创建存储过程
第一步:点击数据库下的“可编程性”,选择“存储过程”,点击鼠标右键,选择“新建存储过程”
注意事项:
注意执行exec时,参数的类型,要与建立的存储过程时设置的参数类型一致。
‘陆’ 创建数据库和表的SQL脚本怎么写这是SQLserver语句吗
这就是
SQL语句
,但数据库不是SQL
Server的,而是
MYSQL数据库
的。
从SQL语句上看就是创建一个数据库为struts(表名为t_prodects,表类型为InnoDB,
字符集
:GBK)
‘柒’ SQLSERVER 增删改语句是如何写的常用的都有那些函数,具体用法简单描述下!
一、增删改查SQL语法:
1.查询语句
第一种法方:
select 列名 from table(数据库表名) where(条件)
第二种法方:
select *(表示所有的列) from table(数据库表名) where(条件)
注意:列名与列名之间用逗号分开。
eg:
1.select ProctID,ProctName,Price
from Proct
where Price>5.0
2.select * from Proct where Price>5.0
3.如何给列加汉子名称:
格式:“‘列标题’=列名” 或 “'列名'AS 列标题”
eg:
select ProctID=‘产品编号’,ProctName,Price
from Proct
where Price>5.0
select '产品编号'as ProctID,ProctName,Price
from Proct
where Price>5.0
where 语句中可以使用逻辑运算符
AND OR NOT
eg:
select ProctID,ProctName,Price
from Proct
where Price>=5.0 And Price<=10.0
2.使用字符串模糊匹配
格式:
expression[not] like 'string'(escape"换码字符")
3.使用查询列表
如果列的取值范围不是一个连续的区间,而是一些离散的值,此时就应使用 SQL Server 提供的另一个关键字 IN 。
语法格式:column_name [not] IN (value1,value2....)
eg:
select SaleID,SaleName,Sex,Birthday,HireDate,Address
form Seller
where SaleID IN('S01','S02',S07)
4.空值的判定
在SQL Server中,通过null。
5.top 和 distinct
语法:select top integer || top interger percent columnName
from tableName
eg:
分别从Customer表中检索出前5个及表中前20%的顾客信息。
select top 5 *
from Customer
select top 20 percent *
from Customer
查询Proct 表中价格最高的6种商品。
eg:
select top 6 *
from Proct
order by price desc
asc(低—>高) desc(高->低)
2.向表中插入数据
语法:insert into tableName(columnName...(要插入的数据的列名)) values(expression(与columnName相对应的值))
注意:再插入数据时,对于允许为空的列可以使用NUll插入空值;对于具有默认值的列,可使用Defaulf插入默认值。
eg:
向Seller 表中插入一行数据,其中Sex字段使用默认值为‘男’,HireDate等字段均去空值。
insert into seller(saleid,saleName,sex,birthday,hireDate,address,telephone,telephone,notes)
values('s11','赵宇飞',default,'1974-07-25',null,null,null,null)
or
insert into seller(saleid,saleName,brithday)
values('s11','赵宇飞','1974-07-25')
3.修改表中的数据
语法:update tableName
set columnName=expression(...)
where search_conditions
eg:
1.将Proct表中"啤酒"的价格改为4元
update proct
set price=4
where proctName='啤酒'(注意:一定要加条件 +“where”)
4.删除数据
语法:delete [from] tableName
where search_conditions
eg:
delete from Seller
where SaleID='s11'(注意:一定要加条件 +“where”,不然就把该表中所有的数据删除了)
‘捌’ 编写一个SQLSERVER 存储过程
代码是最好的文字,不多说,请看我的代码,并给分,呵呵。
--step1. 建表
if exists(select * from sysobjects where id=object_id('student') and objectproperty(id,'IsTable')=1)
drop table student
go
create table student
(
id int identity(100,10) not null
,sname varchar(10) not null
,sno varchar(30) not null
)
go
--step2.建存储过程
if exists(select * from sysobjects where id=object_id('proc_demo') and objectproperty(id,'IsProcere')=1)
drop procere proc_demo
go
create procere proc_demo
@o_maxid int output
as
set nocount on
--如果希望大小写敏感,使用第一句,因为SQL Server默认是大小写不敏感的
--update student set sno='cay_'+sno where ascii(substring(sname,1,1))=87 and ascii(substring(sname,2,1))=65 and sno not like 'cay_%'
update student set sno='cay_'+sno where sname like 'WA%' and sno not like 'cay_%'
print convert(varchar(10),@@rowcount)+'条记录符合条件并被处理'
select @o_maxid=max(id) from student where id>=100
if(@o_maxid is null) print '没有找到符合条件的最大记录'
set nocount off
go
--测试数据1
truncate table student
set identity_insert student on
insert into student(id,sname,sno)values(1,'WA1','1');
insert into student(id,sname,sno)values(2,'wa2','2');
insert into student(id,sname,sno)values(3,'3','3');
set identity_insert student off
go
--测试数据2
truncate table student
insert into student(sname,sno)values('WA1','1');
insert into student(sname,sno)values('wa2','2');
insert into student(sname,sno)values('3','3');
go
--测试过程
declare @maxid int
exec proc_demo @maxid out
print '最大id是'+convert(varchar(10),@maxid)
go
‘玖’ Sqlserver语句在Oracle中应该怎么写
update ufx8u6a51371991809468 set field007=(select bg.field002
from ufm2k0m61372829538562 bg,ufx8u6a51371991809468 jl
where jl.requestid=bg.field001 and bg.requestid=''),
field008=(select bg.field001
from ufm2k0m61372829538562 bg,ufx8u6a51371991809468 jl
where jl.requestid=bg.field001 and bg.requestid='');