當前位置:首頁 » 編程語言 » sqlserver怎麼編寫
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sqlserver怎麼編寫

發布時間: 2022-05-09 14:26:43

『壹』 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='');