SQL
Posted Rexcnblog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL相关的知识,希望对你有一定的参考价值。
alter table LianTong_ContractApproveHistoryModels add CreateUserName nvarchar(max) NULL; EXEC sys.sp_addextendedproperty @name=N‘MS_Description‘, @value=N‘创建人名称‘ , @level0type=N‘SCHEMA‘,@level0name=N‘dbo‘, @level1type=N‘TABLE‘,@level1name=N‘LianTong_ContractApproveHistoryModels‘, @level2type=N‘COLUMN‘,@level2name=N‘CreateUserName‘ --修改字段 ALTER TABLE CisEmployee ALTER COLUMN EmployeeDescription nvarchar(max) NULL; sp_rename ‘KYX_Employee.PK_KYX_Department_DepartmentName‘,‘PK_KYX_Department_DepartmentName1‘,‘column‘ /*ALTER TABLE 删除字段 */ ALTER TABLE TABLE_USER DROP COLUMN TEMP_COL; --按照字符串长度获取数据 SELECT [CompanyName] ,LEN(CompanyName) as lengths FROM [dbo].[OOF_Company] where LEN(CompanyName) <= 4 --按照字符串长度更新数据 update [dbo].[OOF_Company] set EnumCompanyStatus = ‘0‘ where LEN(CompanyName) <= 4 --查询当天数据 SELECT * FROM 表 WHERE datediff(day,列名,getdate())=0 --获取关联表的数据更新 UPDATE QST_OrderDetail SET ActualPrice = (SELECT CurrentPrice FROM QST_Product WHERE ID = QST_OrderDetail.PK_QST_Product_ProductName) --修改自增的初始值 DBCC CHECKIDENT (‘TXCC_Assit‘, RESEED, 100000) --Valuess((N.w*‘,) SELECT [Id] ,[Operator] ,[Message] ,[Result] ,[Type] ,[Module] ,[CreateTime] FROM [dbo].[SysLog] WHERE CreateTime >= Convert(datetime,‘2018-05-02 17:20:00‘, 101) and CreateTime <= Convert(datetime,‘2018-05-02 17:30:00‘, 101) update [GMGood] set [uploaddate] = REPLACE(SUBSTRING([uploaddate],6, 10),‘.‘,‘-‘) where a=a --字符串值的长度 datalength(uploaddate) = 20 --字符串位置 Select CharIndex(‘a‘, ‘1235ab‘) --5 SELECT * FROM (select row_number()over(order by uploaddate desc)rownumber,* from GMGood) GMGood1 WHERE statusupload = ‘1‘ and rownumber between 31 and 60 SQL Server 字段设置默认值 1. 如果表字段已经建好 ALTER TABLE 表名 ADD CONSTRAINT DF_TABLEName_FieldName DEFAULT 1 FOR 字段名 2. 如果表字段没有建 alter table 表名 add 字段名 int default(1)
以上是关于SQL的主要内容,如果未能解决你的问题,请参考以下文章
sql 日期转换代码片段 - Dato,120,konvertere