sql语句复习

--创建一张表
create table MyTestTable
(
   --默认值写法 default('12123') default(getdate()) id
int primary key identity(1,1),--primary key意思是:主键的意思 --identity(1, 1)意思是:自增,初始值1,每次自增+1 name varchar(55) not null unique,--unique的意思是:让字段不重复 pwd varchar(55) not null ) --删除一张表 drop table MyTestTable --插入 insert into MyTestTable(name, pwd) values ('sss', '1233') update MyTestTable set name = '小红', pwd = '123' where id = 3 delete from MyTestTable where id = 2 select * from MyTestTable


--排序 sql语句xxxxxx order by 字段名 desc降序 (asc升序)
--新增字段    alter table 表名 add 字段名 类型 (默认字段的时候注意时:not null default 数值)
--删除字段    alter table 表名 drop column 字段名
--修改字段类型  alter table 表名 alter column 字段名 类型
--修改字段名称  exec sp_rename '表名.原字段名' , '新字段名'
--if not exists(select * from sys.columns where name='字段名' and [object_id]=object_id(N'表名')) --判断表是否存在某字段
--if not exists(select 1 from sysobjects where id = object_id('表名') and type = 'U')--判断是否存在表
--if not exists(select 1 from sysobjects where id = object_id('函数名') and type in ('IF', 'FN', 'TF')) --是否存在某方法
--if not exists(select 1 from sysobjects where id = object_id('存储过程名') and type in ('P','PC'))--是否存在某存储过程

 

posted on 2020-08-19 13:41  炼金师  阅读(86)  评论(0)    收藏  举报

导航