<0> . DNS的使用!起初连不上不服务的数据库,是因为没有加入域, sql 基础类的使用
1.连上数据库,我晕了,,表真多,,,,查询所有表名|视图
select * from information_schema.tables where table_type='BASE TABLE'
select * from information_schema.tables where table_type='VIEW'
查询视图
select * from information_schema.views --261个
查询存储过程 (注:xtype = p , v )
select * from sysobjects a where a.xtype = 'p'
Account
Activity
Annotation
Appointment
AttributeMapBase
BL_IT_CWRDown
BL_IT_CWB
Build**
Bulk**
Business**
Calendar**
Campaign**
Competitor
Contact
Contract
Customer
Discount
DisplayString
DocumentIndex
EmailBase
EmailExtensionBase
entityMapBase
EquipmentBase
EquipmentExtensionBase
Account视图 accountclassificationcode,
{
AccountBase 客户信息
AccountExtension
TerritoryBase
ServiceBase
ContactBase
LeadBase
EquipmentBase
CustomerAddressBase
CustomerAddressExtensionBase
SystemUserBase fch_developroute
PriceLevelBase
}
Activity视图{
ActivityBase
SystemUserBase
TeamBase
CompetitorBase
}
ActivityAttachment视图
{
ActivityMimeAttachment
ActivityPointerBase
}
ActivityParty视图
{
ActivityPartyBase
AccountBase
ContactBase
LeadBase
ActivityPointerBase
ResourceSpecBase
}
SystemUser 视图 fch_developroute开发路区
{
SystemUserBase
SystemUserExtensionBase
InternalAddressBase
AddressNumber
InternalAddressBase
BusinessUnitBase
FCH_agentrouteBase
FCH_collectrouteBase
FCH_developrouteBase
FCH_MaintenanceRouteBase
FCH_SubCompanyBase
OrganizationBase
SiteBase
TerritoryBase
FCH_agentrouteExtensionBase
FCH_collectrouteExtensionBase
FCH_developrouteExtensionBase
FCH_MaintenanceRouteExtensionBase
FCH_SubCompanyExtensionBase
}
WF**
systemuserroles
FCH 啥意思
FCH_maintenancebudget_detailExtensionBase 路区维护 ,fch_maintenancebudget_detail,fch_saleamount_my,fch_weight_ft,fch_piece_it
FCH_maintenancebudgetExtensionBase fch_salestatics,fch_weightstatics,fch_piecestatics,FCH_maintenancebudgetId
lead 公司
Incident 维护案例
OCS_TB_SalesCalcQueue 公司三字码:BranchCom_SZMCode
FCH_SubCompanyExtensionBase
fch_salesdeveloper 开发人员 fch_salesdeveloper_lk 客户uid
FCH_agentbudget_detailExtensionBase
FCH_agentbudgetExtensionBase
fch_collectroute
FCH_collectrouteExtensionBase
OCS_MS_SystemConst 类似字典表
OCS_MS_DsctCategory 折扣模板
OCS_TB_AcctDsctCategory 客户折扣关系
OCS_MS_SchgCategory
OCS_TB_AcctSchgCategory
OCS_MS_DsctRule 折扣规则
OCS_MS_DsctBandDetail
OCS_MS_DsctRuleDetail 折扣规则详细
OCS_VW_ActiveService 服务类别
OCS_VW_ActiveToZone 目的区域
OCS_VW_ActiveCompany
OCS_MS_FromZone
OCS_MS_SERVICE
OCS_MS_RateCategory
OCS_MS_RateDetail
OCS_MS_ToZone
OCS_MS_FromZone 始发区域
OCS_VW_Refered_OrigZone
OCS_MS_SZM 城市三字码
RoleBase
SystemUserBase
SystemUserRoles
fch_subcompany
OCS_MS_BudgetImportUser
2.Uniqqueidentifier 是全局唯一的标识
3.表连接:内部外部::比如SELECT * FROM emp, dept;数据库如何执行呢?他把emp的每一行和dept每一行连接,假设emp有20个记录,dept有5个记录,这样总共有得到20*5个记录,实际是得到两个子集的笛卡尔乘积。
所谓内部连接实际很简单,就是在这些得到的新的记录中选择那些满足连接条件的记录,所谓外部连接实际也很简单,同样在笛卡尔乘积中剔出不满足连接条件的记录,得到的新的集合。如果是右外部连接,那么把右面的表在新的集合没有的记录也增加进来,这时因为在左面的表中没有与他相匹配的记录,所以以NULL代替。
4。当时money型时:SELECT SUM(fch_saleamount_my) FROM FCH_maintenancebudget_detailExtensionBase WHERE fch_maintenancebudget_detail = 'd85b8ff9-c85e-dd11-8b92-001708576698'..是几位小数(4位?2位??);
//将取得的值保留两位小数;
sum1 = sum1.Substring(0, sum1.Length - 2); 这样对吗??
5。 string sql = "SELECT fch_incidenttype2_pl "+
" FROM Incident "+
" WHERE CONVERT(nvarchar(100),incidentid) = @guid 啥意思? 防止出现将字符串转换为 uniqueidentifier 时失败。incidentid的类型是uniqueidentifier
6。ALTER PROCEDURE [dbo].[sp_GetSequence]
@SEQ_TYPE NVARCHAR(10)=null,
@SEQ_NAME NVARCHAR(20)=null,
@SEQ_ID bigint =-1 output
AS
BEGIN TRY
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Declare the return variable here
DECLARE @START_WITH bigint --获取前的值
DECLARE @INCREMENT int --增量
DECLARE @MIN bigint --最小值
DECLARE @MAX bigint --最大值
DECLARE @CYCLE int --是否循环
DECLARE @NOW bigint ----当前值
BEGIN TRANSACTION
UPDATE OCS_MS_SEQUENCE SET Update_On=GETDATE()
WHERE SEQ_TYPE=@SEQ_TYPE AND SEQ_NAME=@SEQ_NAME
SELECT
@START_WITH =START_WITH ,
@INCREMENT=INCREMENT ,
@MIN=MIN ,
@MAX=MAX ,
@CYCLE=CYCLE
FROM OCS_MS_SEQUENCE
WHERE SEQ_TYPE=@SEQ_TYPE AND SEQ_NAME=@SEQ_NAME
--如果超过最大值
IF (@START_WITH+@INCREMENT>@MAX)
BEGIN
--设为最小值
SET @NOW=@MIN
END
ELSE
BEGIN
SET @NOW=@START_WITH+@INCREMENT
END
UPDATE OCS_MS_SEQUENCE SET START_WITH=@NOW
WHERE SEQ_TYPE=@SEQ_TYPE AND SEQ_NAME=@SEQ_NAME
COMMIT TRANSACTION
SET @SEQ_ID=@NOW
SELECT 'return' RETURN(@NOW )
END TRY
--捕获错误
BEGIN CATCH
SELECT ERROR_MESSAGE() AS ERROR_MESSAGE;
SELECT ERROR_LINE() AS EERROR_LINE;
ROLLBACK TRANSACTION
return(-1)
END CATCH;
获取序列号,<1。存储过程,若有输入项:如@SEQ_ID bigint =-1 output . 带上 =-1 即给一个默认值,这样的话,避免在调用时,必须赋值.否则的话必须给输出项传入一个值.
<2. 存储过程,有可能出现异常的用BEGIN TRY ***** END TRY --捕获错误 BEGIN CATCH *** END CATCH;
<3. 存储过程,使用事务:BEGIN TRANSACTION ***** COMMIT TRANSACTION ROLLBACK TRANSACTION 回滚一般放在begin catch end catch 之间...也可以为事务起一个名字
区分多个事务的情况BEGIN TRANSACTION PPP(在对应transaction 关键字后加名字ppp
<4。SELECT 'return' RETURN(@NOW ) 啥意思??
<5。用一个表OCS_MS_SEQUENCE 存放序列号,表结构(SEQ_TYPE,SEQ_NAME,START_WITH,INCREMENT,MIN,MAX,CYCLE,CREATE_ON,CREATE_By,Update_On,update_by. 主键为:seq_type 和 seq_name,其余为开始值(最后一次的值,递增量,最小,最大,是否循环)
7. insert into #CustomerIds (ParentId, ChildId)
(
select ri.ParentId, a.AccountId
from AccountBase a (NOLOCK)
join #CustomerIds ri on
(
a.ParentAccountId = ri.ChildId
)
where
not exists(
select ParentId, ChildId from #CustomerIds
where ri.ParentId = ParentId
and a.AccountId = ChildId
)
)
<1从一个表里面提取数据插入另外一张表. ,<2 ,nolock 什么意思?? <3 .以not exists 为查询条件.where not exists (select * * from )
8 . while (@acctDepth > 0)
begin
****
if ( @@rowcount = 0)
begin
break
end
set @acctDepth = @acctDepth - 1
end
<1。存储过程,while 语句
9。.异常的定义和抛出
-- 定义异常的参数
DECLARE @ErrorSeverity int; -- 异常级别
DECLARE @ErrorState int; -- 异常状态
DECLARE @ErrorMessage nvarchar(2000); -- 异常消息
BEGIN TRY
*******
END TRY
BEGIN CATCH
-----------------------------------------------------------
-- 捕获异常,获得异常参数
SET @ErrorMessage='实际结算日期计算,' + ERROR_MESSAGE();
SET @ErrorSeverity=ERROR_SEVERITY();
SET @ErrorState=ERROR_STATE();
-- 抛出异常
RAISERROR(@ErrorMessage,
@ErrorSeverity,
@ErrorState
);
END CATCH
10。 CAST(AccountId AS varchar(50)) ; cast 转换数据类型. 与convert 类似!
DATEADD(MONTH,-1,@Balance_Datetime) ; dateadd 将@Balance_Datetime 的日期的MONTH[或年,天等] 加 -1[或其他int型数]
DATEPART(YEAR,dt) ;DATEPART 提起时间类型dt的对应值,如dt的年份
ISDATE(dt) ;判断dt 是否是时间类型,是返回1,否则返回0
ISDATE(CAST(DATEPART(YEAR,DATEADD(MONTH,-1,@Balance_Datetime)) AS nvarchar) + '/' + CAST(DATEPART(MONTH,DATEADD(MONTH,-1,@Balance_Datetime))AS nvarchar) + '/' +CAST(@v_fch_monthbalbegin_it AS nvarchar))
来源:https://www.cnblogs.com/9421/archive/2010/04/14/1712046.html