SQL Sever的基本语句

Posted on 2018-07-18 17:05  hanyu柚子露  阅读(100)  评论(0)    收藏  举报

create table students (id int not null primary key,names int not null,age int not null);
--新建一个表格students,其中id为int类型,非空,主键
--names为int类型,非空
--age为int类型,非空

alter table students add socre int;
--在表students中添加一个字段为socre,字段类型为int;

alter table students alter column names char (20);
--将names的字段类型改为char;

alter table students alter column names char(100);
--增长names的字段类型;

sp_help students;
--查询表结构

insert into students (id,names,age) values ('001','孙悟空','500');
insert into students (id,names,age) values ('002','唐玄奘','25');
insert into students (id,names,age) values ('003','猪无能','1000');
insert into students (id,names,age) values ('004','沙悟净','1500');
--在表中插入数据;

select * from students;
--查询表中数据;

insert into students (socre) values ('100') where id='001';
--将表中的score字段插入数据;

update students set socre = 100 where id=001;
update students set socre = 90 where id=002;
update students set socre = 80 where id=003;
update students set socre = 70 where id=004;
--将表中score字段的数据更新;

select * from students where id=1;
--查询表,查询出id为1的数据;

select * from students where id=1 and age=500 or id = 2 or age = 1000;
--查询表,查询出当表中id为1并且年龄为500,或者id为2或者年龄为1000的数据,此时应有三条数据被查询出来;

select * from students where names like '%悟%';
--模糊查询,查询出names中包含“悟”的数据。

博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3