SqlServer 一些操作

时间:2023-12-25 17:02:19
//查询一个表中的某字段为条件修改另一个表的内容
update [VehicleInsuranceAgentConfiguration] set Keyword2=PC.ServerConfig from ProxyConfig PC,VehicleInsuranceAgentConfiguration VIAC
where VIAC.CompanyID=PC.CompanyID and VIAC.ProductCode=PC.ProductCode

  

//修改表中字段的类型 长度
Alter Table 表名 ALTER COLUMN 列名 类型(长度)
Alter Table [VehicleInsuranceAgentConfiguration] ALTER COLUMN Keyword2 nvarchar(max)

  

//修改表字段名
EXEC sp_rename '[ServiceConfig].[ServerName]', 'CompanyID', 'COLUMN'

  

 //添加一个字段
alter table [chexian].[dbo].[ServiceConfig] add CompanyID nvarchar(50)

  

//修改默认值
ALTER TABLE dbo.UPLOADED_FILES ADD DEFAULT(NEWID()) FOR FILE_ID