生科院

SQL Server简单语句/待整理

数据库对象:表Table,视图View,存储过程Stored Procedure,触发器Trigger

关系:1关系=1二维表,1关系有1关系名。1关系=1表对象

属性/字段: 二维表中垂直方向的列 元组/记录:二维表中水平方向的行

码/关键字:二维表中某个属性(侯选码)  ,  值唯一标识1元祖  该属性为侯选码。若1关系有多侯选码,则选其一为主码/主属性

关系模式:描述关系的,它包括关系名、组成该关系的属性名和属性到域的映像。=关系名(属性名1,属性名2,…,属性名n)

select name , sex , Entrancescore from student where Entrancescore between 500 and 600

【从表中取出仅这三列 分500-600间】

 

create database databse_name  

drop database databse_name

alter table tabname add               col1 int   加int型col1列

alter table tabname add  primary key (col1)      加主键

alter  table tb_text add primary key(列1)  加列1为主键(前提notnull)

create table  tabname(col1 int  not null primary key) 主键col表tabname

select * into  tbnew from tboldname    旧表建新表(主键要设)

select * into tbnew  from tboldname where 1=2  建和旧表类型一样的

alter table table1 alter column col varchar 改字段col 类型

alter table table1 drop column col 删字段

alter table table1 add         col char(200)  加字段

select top 10 * from  M2box_Structure1  前10条

select top 10 * from  table1 order by newid() 随机取10条

select count(*)as 学生总数 from student 【统计学生总数,并以"学生总数"字段名命名】

select avg(Entrancescore)   as 平均成绩 from student

select max(Entrancescore) as 入学最好成绩 from student 

DELETE FROM M2box_Structure1  删除所有的行

select * into table2 from table1 where 1=2  只复制表结构不复制数据;where 1= 1所有的都符合,where 1=2表示都不符合。

 

posted on 2015-06-12 12:50  生科院  阅读(188)  评论(0)    收藏  举报