MSSQL 数据库表字段增/删/改/查的操作
发布时间:2020-12-12 12:39:07 所属栏目:MsSql教程 来源:网络整理
导读:添加 1、向Loginfo中添加新列newcomlum1 ,int型,ALTER TABLE Loginfo ADD newcomlum1 int NULL 2、表:LogInfo 代码--判断要添加列的表中是否有主键 if exists(select 1 from sysobjects where parent_obj=object_id('LogInfo') and xtype='PK') begin prin
添加 1、向Loginfo中添加新列“newcomlum1” ,int型,ALTER TABLE Loginfo ADD newcomlum1 int NULL 2、表:LogInfo 代码--判断要添加列的表中是否有主键 if exists(select 1 from sysobjects where parent_obj=object_id('LogInfo') and xtype='PK') begin print '表中已经有主键,列只能做为普通列添加' --添加int类型的列,默认值为0 alter table LogInfo add 列名 int default 0 end else begin print '表中无主键,添加主键列' --添加int类型的列,默认值为0 alter table LogInfo add 列名 int primary key default 0 end 删ALTER TABLE LogInfo DROP COLUMN 列名修改 1、修改 类型 修改字段类型为intALTER TABLE LogInfo ALTER COLUMN 列名 int 2、修改字段名LogInfo(表).LogInfocomlum1(字段名)--改为---〉LogInfocomlum2 EXEC sp_rename 'LogInfo.LogInfocomlum1','LogInfocomlum2' 查(数据库中所有的表、用户表名) select name from sysobjectsselect name from sysobjects where xtype='u' --下面LogInfo,用户自己建的表 select c.* from syscolumns c,sysobjects o where c.id = o.id and o.type = 'U' and o.name = 'LogInfo' (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读