- 浏览: 163746 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (193)
- Axis2 (10)
- Andriod (2)
- Java (22)
- Eclipse (2)
- 程序人生 (3)
- Windows (1)
- Sql Server 2005/2008 (7)
- 健身 (2)
- Log4j (1)
- Ant (1)
- Fatjar (2)
- 国际化 (1)
- Linux (3)
- JDBC (1)
- Oracle (2)
- 各种报错 (4)
- SWT (5)
- Tomcat (2)
- 车辆管理 (1)
- SVN (2)
- Spring (5)
- 域名服务器 (0)
- HaoWaYa (1)
- FTP (1)
- 集散中心 (1)
- 专业知识 (1)
- 面试准备 (19)
- 设计模式 (22)
- Junit (1)
- 软件下载 (3)
- 深入理解Java虚拟机 (3)
- 数据结构 (4)
- 雅思 托福 (0)
- UML (1)
- Maven (1)
- CV (1)
- ServiceMix (1)
- 电子书 (5)
- Struts1/2 (4)
- DOM W3C DHTML (3)
- Jawr (1)
- LoadRunner (1)
- Java反编译 (0)
- 英语学习 (0)
- 技术书籍 (1)
- Cygwin (0)
- ibatis (1)
- 数据库 (1)
- jQuery (0)
- s (2)
- 源代码项目 (5)
- JSRs (0)
- JCP (0)
- XML (2)
- Dojo (3)
- Effective Java (1)
- 一站到底 (3)
- JavaScript (6)
- DB2 (1)
- 刷机 (1)
- 字符 (1)
- Dynamic Web Project (1)
- 股市日记 (1)
- 代码片段 (0)
- CSS (1)
- PDF (0)
- 英语口语 (1)
- 乒乓球 (1)
- 体检 (0)
- 送花 (0)
- 面试准备-再战江湖 (5)
- ddq (0)
- sss (0)
- ssssss (0)
- 2020面试 (0)
最新评论
-
samsongbest:
Copperfield 写道你的目标很远大,佩服~惭愧,都忘了 ...
人生目标 -
Copperfield:
你的目标很远大,佩服~
人生目标
1.create table
create table dbo.app_param(
sn int identity(1,1) not null,
type nvarchar(50) not null,
module nvarchar(50) not null,
ckey nvarchar(50) not null,
cvalue nvarchar(50) not null,
remark nvarchar(50) null,
updated_user nvarchar(20) null,
created_datetime datetime null,
updated_datetime datetime null,
constraint PK_app_param primary key nonclustered(sn asc)
)
2.create index
create unique clustered index IX_app_param on dbo.app_param
(
type asc,
module asc,
ckey asc
)
3.create foreign key
alter table dbo.app_config add constraint FK_app_config_call_center
foreign key( country_code, call_center_code)
references dbo.call_center(country_code, call_center_code)
4.set null
5. add column
alter table employee add subsidy_status smallint default 1 null
alter table employee_comp_detail add subsidy decimal(16,2) null
6.three common lines
updated_user nvarchar(20) null,
created_datetime datetime default getdate() not null,
updated_datetime datetime default getdate() not null,
7. rename column
exec sp_rename 'kpi_callcenter.active', 'is_active', 'column';
8. change column type
alter table call_center_incentive alter column is_active smallint
9.drop column
alter table employee drop column employee_name_th
10.drop PK
ALTER TABLE dbo.doc_exc DROP CONSTRAINT my_constraint
11.drop index
DROP index anp_comm_rating.IX_anp_comm_rating
7. rename table
exec sp_rename 'table1', 'table2';
8.dump_history_log table
create table if_salespermonth_dump(
employee_id nvarchar(20) null,
month_year nvarchar(20) null,
sales_per_month nvarchar(20) null
)
create table if_salespermonth_history(
sn int identity(1,1) not null,
employee_id nvarchar(20) null,
month_year nvarchar(20) null,
sales_per_month nvarchar(20) null,
created_datetime datetime default getdate() not null,
constraint PK_if_salespermonth_history primary key clustered(sn asc)
)
CREATE TABLE [dbo].if_salespermonth_log(
[sn] [int] IDENTITY(1,1) NOT NULL,
employee_id nvarchar(20) null,
month_year nvarchar(20) null,
sales_per_month nvarchar(20) null,
[transaction_date] [datetime] NOT NULL,
[batch_no] [int] NOT NULL,
[execution_date] [datetime] NOT NULL,
[error_type] [nvarchar](10) NOT NULL,
[error_msg] [nvarchar](200) NULL,
[updated_user] [nvarchar](20) NULL,
[created_datetime] [datetime] default getdate() NOT NULL,
[updated_datetime] [datetime] default getdate() NOT NULL,
CONSTRAINT [PK_if_salespermonth_log] PRIMARY KEY CLUSTERED (sn asc)
)
11.建表的4行
sn int identity(1,1) not null,
updated_user nvarchar(20) null,
created_datetime datetime default getdate() not null,
updated_datetime datetime default getdate() not null,
constraint PK_c_commission_rate primary key nonclustered(sn asc)
13.生成数据字典的sql:select tname,colid,cname,ctype,length =
case ctype
when 'nvarchar' then length/2
when 'nchar' then length/2
else length
end,
xprec,xscale,isnullable from all_col where tname not like 'if%' and tname not like 'cn%'
order by 1,2
select * from all_col order by 1,2
select row_number() over (partition by employee_id order by program_id) as row_num,
*
from employee_program
14. 日期加减
/****** Script for SelectTopNRows command from SSMS ******/
SELECT ''
, [country_code]
, [call_center_code]
, [cutoff_year]- 1
, [cutoff_month]
, DATEADD ( year ,- 1, [curr_cutoff_date])
, [last_cutoff_date]
, [updated_user]
FROM [cigna_china_tt]. [dbo]. [cutoff_period]
/****** Script for SelectTopNRows command from SSMS ******/
insert [cutoff_period]( [country_code], [call_center_code], [cutoff_year], [cutoff_month], [curr_cutoff_date],
[last_cutoff_date], [updated_user])
SELECT
[country_code]
, [call_center_code]
, [cutoff_year]- 1
, [cutoff_month]
, DATEADD ( year ,- 1, [curr_cutoff_date])
, DATEADD ( year ,- 1, [last_cutoff_date])
, [updated_user]
FROM [cigna_china_test]. [dbo]. [cutoff_period] where cutoff_year = '2010'
select * from [cutoff_period]
SELECT ''
, [country_code]
, [call_center_code]
, [cutoff_year]- 1
, [cutoff_month]
, DATEADD ( year ,- 1, [curr_cutoff_date])
, [last_cutoff_date]
, [updated_user]
FROM [cigna_china_tt]. [dbo]. [cutoff_period]
15.fe
DUMP TRANSACTION 库名 WITH NO_LOG
16. 收缩日志
ALTER DATABASE ATDB
SET RECOVERY SIMPLE;
GO
-- Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE (ETN_Log, 1);
GO
-- Reset the database recovery model.
ALTER DATABASE ATDB
SET RECOVERY FULL ;
GO
17. 行转列
select * from
(
select country_code, call_center_code, score_type, score, updated_user, updated_datetime
from kpi_score
) as k pivot ( max ( score) for score_type in( [0], [1], [2])) as t
18. convert
select CONVERT(varchar, getdate(),103)
delete t
from (select a.seller_id,a.employee_id,
row_number() over (partition by a.seller_id order by a.seller_id) as r
from if_employee_info_dump a) t
where t.r > 1
发表评论
-
CallableStatement
2012-06-21 23:04 762--JDBC调存储过程 stmt = conn.prepa ... -
分页sql
2012-06-07 11:10 686SELECT * FROM ( SELECT ... -
聚集索引
2012-03-16 16:56 678聚集索引物理排序,可以为索引设置因子,如果表的删除操作比较多, ... -
linked server
2012-02-09 11:14 546PFA... -
kb mb of db.sql
2012-02-09 11:11 670if not exists (select * from db ... -
jdbc连接数据库实例代码
2011-11-09 16:59 705jdbc.driverClassName=oracle.jdb ...
相关推荐
常用T-sql,常用T-sql,常用T-sql,常用T-sql
常用T-SQL语句的总结归纳,查询,修改,删除,权限等
SQL SERVER数据库常用T-SQL语句快速参考。
触发器使用原理和常用T-SQL截取字符串操作,经过实践操作很实用很方便
SQL Server 数据库管理常用的 SQL 和 T-SQL 语句 SQL Server 是一个强大的关系数据库管理系统,提供了许多实用的 SQL 和 T-SQL 语句来管理和维护数据库。以下是 SQL Server 数据库管理常用的 SQL 和 T-SQL 语句: ...
此文件是用与初学者,能够快速的了解数据库的基本应用
MS-SQL开发常用汇总和T-SQL技巧集锦 MS-SQL开发常用汇总和T-SQL技巧集锦 MS-SQL开发常用汇总和T-SQL技巧集锦 详尽的数据库常用开发和技巧集锦
自己多年整理的T-SQL常用语句大全 不下别后悔
T-SQL 查询 进阶 高级查询 常用查询
工作中常用的T-SQL语句,超详细。内含解释说明,使用技巧和运用规则,方便开发时随时查阅。
SQL Server 数据库管理常用的SQL和T-SQL语句,非常经典和常用的SQL
《Microsoft SQL Server 2008技术内幕:T-SQL查询》全面深入地介绍了Microsoft SQL Server 2008中高级T-SQL查询、性能优化等方面的内容,以及SQL Server 2008新增加的一些特性。主要内容包括SQL的基础理论、查询优化...
常用T-SQL,初学T-SQL下载,比如创建表、创建存储过程、创建游标等
MS-SQL开发常用汇总和t-sql技巧集锦MS-SQL开发常用汇总和t-sql技巧集锦
可快速索引到要学的T-SQL语句,查询方便,里面有常用的操作表,存储过程,事务,触发器等常用操作
T-SQL函数实战教程很多常用函数很适合初学者。
《Microsoft SQL Server 2008技术内幕:T-SQL查询》全面深入地介绍了Microsoft SQL Server 2008中高级T-SQL查询、性能优化等方面的内容,以及SQL Server 2008新增加的一些特性。主要内容包括SQL的基础理论、查询优化...
《Microsoft SQL Server 2008技术内幕:T-SQL查询》全面深入地介绍了Microsoft SQL Server 2008中高级T-SQL查询、性能优化等方面的内容,以及SQL Server 2008新增加的一些特性。主要内容包括SQL的基础理论、查询优化...
如今无论是像Oracle、Sybase、Informix、SQL server这些大型的数据库管理系统,还是像Visual Foxporo、PowerBuilder这些微机上常用的数据库开发系统,都支持SQL语言作为查询语言。SQL(结构化查询语言)是大多数...
SQL Server数据库管理常用SQL和T-SQL语句