数据库语言

Create   database   second      --创建数据库second

Go                 

Create   table     second1        

(

Code  int ,

Name  varchar(20)   not null,--此时表示不能是   空!

Price   decimal(18,2) ,

)

Insert   into second1    values(1,’苹果’,3.3)

Insert   into second1    values(2,’西瓜’,7.3)

--上面操作创建了一个数据库second 并在里面建立了second1的表格。

Use  first  --这是指定数据库的操作。

Go

Select    *from  student    --查询语句,查询表格时在from前加*

Select   name,sxe  from  student  where code=2--表示查询code是2 的student表中的  name和sxe

Insert    into   student    values(2,’李四’,’1991-1-1’,’男’,178,,77)插入数据要按表格顺序。注意格式!

Insert    into   student (Code ,Name,sxe)  values(3,’网店’,’女’)

Update    student   set   Birthday=’1991-1-1’ where  code=2--修改表,code=2的学生的birthday 为1991-1-1。

Delete  from   student   where  code=2--删除code=2的一行

################################################################

Alter      table  xinxi   add  [int]  varchar(20)--  在xinxi 的表里添加int列,值类型是varchar(20).

后添加的列,不能设置   不为空,not null.

Alter table  xinxi drop  column  [int]   --删除[int]列

Sp_renamedb    xxx,fff       --为数据库改名!xxx改成fff

Select *from  xinxi  where  fenshu  between 80 and 100—选出分数80<=x<=100之间的信息

Update xinxi  set  nianling=26 where  fenshu between 80 and 100— 修改。把分数80~100之间的人,年龄改为26。

Select  distinct   name  from   xinxi –自动去除重复名字的信息!

select *from xinxi where name='李四' and nianling=26--这里and 表示并且!注意书写格式。

select *from xinxi where name='李四' or nianling=26 --这里or 表示或者!name为李四或者nianling是26的信息

select *from xinxi where name in ('李四','赵六')-- name中是李四赵六的信息

select *from xinxi where name not  in ('李四','赵六')-- name,不是李四和赵六的信息

select *from xinxi where name like '%四%'--name 中所有中间是‘四’的信息。%,通配符。表示模糊查询。

select *from xinxi where name like '李_'-- name中是李_的信息!_表示任意字符!

select *from xinxi where name like '_['李四','赵六']'-- 提取name中是李四和赵六的信息

select *from xinxi order   by nianling asc--(默认的,可以不写)从小到大排序!(升序)

select *from xinxi order   by nianling desc --从大到小排序!(降序)

select top 3 *from xinxi   order   by fenshu desc --从大到小排序!(降序),取前三名!

select top 1 *from xinxi where name='李四' order   by fenshu desc --从名字是李四的里面按分数排序,取出最高的!

原文地址:https://www.cnblogs.com/huaze/p/4063903.html