SQLServer
Farmwang
博采众长,兼收并蓄!
展开
-
sqlserver没有ldf附加数据库
alter database AmazonDB set emergency 设定Test状态为紧急模式sp_dboption 'AmazonDB','single user','false' 设定数据库模式为"单一使用者"ALTER DATABASE AmazonDB SET EMERGENCYDBCC checkdb(AmazonDB)ALTER DATABASE AmazonDB SET SINGLE_USER WITH ROLLBACK IMMEDIATEDBCC CheckDB (.原创 2021-12-12 15:29:36 · 602 阅读 · 0 评论 -
SQL Server 是否激活
sp_configure 'show advanced options', 1;RECONFIGUREGOsp_configure 'Agent XPs', 1;RECONFIGUREGODECLARE @daysleft intDECLARE @instancename sysnameSELECT @instancename = CONVERT(sysname, SERVE...转载 2019-06-26 11:09:03 · 4105 阅读 · 0 评论 -
Sql Update Alter Rename
EXEC sp_rename 'Menu.group' , 'batch'增加列alter table Menu add batch varchar(30) alter table Menu alter column batch varchar(4000) 3.删除列:alter table Menu drop column batch ...原创 2019-05-22 11:36:18 · 427 阅读 · 0 评论 -
TableSchema search the whole database
create table TT(tablename nvarchar(128),columnname nvarchar(128),columndata nvarchar(max)); use MES; --使用数据库declare @t11 varchar(50) declare @c1 varchar(50) declare @b1 varchar(10)declare...原创 2018-05-22 19:40:29 · 156 阅读 · 0 评论 -
Sqlserver table schema
SELECT * FROM INFORMATION_SCHEMA.TABLESselectsys.schemas.name, sys.objects.namefrom sys.objects,sys.schemaswhere sys.objects.type='U'and sys.objects.schema_id=sys.schemas.schema_id原创 2018-05-22 19:31:01 · 3693 阅读 · 0 评论 -
Check Main Line
CREATE TABLE "t6" ( "AuftrREFID" VARCHAR(50) NULL DEFAULT NULL, "Auftr_ID" VARCHAR(50) NULL DEFAULT NULL); CREATE TABLE "t3" ( "Auftr_ID" VARCHAR(50) NULL DEFAULT NULL, "auftrrefid" VARCH原创 2018-04-25 10:59:36 · 207 阅读 · 0 评论 -
SQL server 日期函数
SQL SERVER 提供了一些时间函数:取当前时间:select getdate()取前一个月的时间:SELECT DATEADD(MONTH,-1,GETDATE()) 月份减一个月取年份:SELECT YEAR( DATEADD(MONTH,-1,GETDATE())),Year 取年份取月份:SELECT MONTH( DATEADD(MONTH,-1,GETDATE())) ,month...转载 2018-04-10 20:46:57 · 309 阅读 · 0 评论 -
sqlserver 追加数据
concat()函数 --用于将多个字符串连接起来,形成一个字符串 update form_approve set status='HOLD',memo=CONCAT(memo,' --- ',' 群群群') where form_id='18041513551556358' and approve_id='pd100' and seq=100...原创 2018-04-15 14:11:50 · 2343 阅读 · 0 评论 -
SQL关键字冲突
比如最常见的USER作为表名,用SQL语句“select * from USER”查询就会出现如下错误:在关键字 'USER' 附近有语法错误 可以用[ ]避免出现这样的错误,即:将SQL语句改正这样“select * from [USER]”...转载 2018-03-21 16:18:32 · 991 阅读 · 0 评论 -
SQL 遍历整个数据库查询字符串
create table TT(tablename nvarchar(128),columnname nvarchar(128),columndata nvarchar(max)); use test; --使用数据库declare @t11 varchar(50) declare @c1 varchar(50) declare @b1 varchar(10)declar...原创 2018-03-30 15:27:19 · 3664 阅读 · 0 评论 -
create refid identity
CREATE TABLE "form_pd300item" ( "refid" bigint identity(1,1) not null, "form_id" VARCHAR(20) NULL DEFAULT NULL, "item" VARCHAR(20) NULL DEFAULT NULL, "item_desc" NVARCHAR(100) NULL DEFAULT NU...原创 2018-03-20 13:38:02 · 210 阅读 · 0 评论 -
with as insert
with a as(select distinct pcode,matid,matgroup,matmemo from ps where matgroup like 'B01%' ), b as ( select distinct pcode,matid,matgroup,matmemo from ps where matgroup like 'H0%'), c as (selec...原创 2018-03-20 13:33:32 · 4355 阅读 · 0 评论 -
sql 时间操作
ELECT * FROM 表 WHERE CONVERT(Nvarchar, dateandtime, 111) = CONVERT(Nvarchar, GETDATE(), 111) ORDER BY dateandtime DESC本月记录SELECT * FROM 表 WHERE datediff(month,[dateadd],getdate())=0本周记录SELECT * FRO...转载 2018-02-22 14:31:46 · 427 阅读 · 0 评论 -
with as insert SQL
with a as ( select orderid,matid,matgroup from ps1 where matgroup like 'B01%' ), b as ( select orderid,matid,matgroup from ps1 where matgroup like 'H0%' ), c as ( select orderid,matid,mat...原创 2018-03-15 15:02:03 · 1370 阅读 · 0 评论 -
sqlserver 启动 端口
exec sys.sp_readerrorlog 0, 1, 'listening'原创 2017-12-27 13:55:03 · 410 阅读 · 0 评论