1、创建表语句
#创建表
if exists(select * from sysobjects where name='表名')
begin
select '该表已经存在'
drop table 表名 --删除表endelsebegin
create table 表名(
--设置为主键和自增长列,起始值为1,每次自增1
ID int not null identity(1,1) primary key comment'id',
serID nvarchar(20) not null comment '备注'
)end
2、创建视图语句
#创建视图
if exists(select * from sys.views where name=视图名称)
drop view 视图名称;
go
CREATE view 视图名称
as
select Name,Age,ClassID from students;
go
3、输出及输入存储过程的创建及调用
#创建存储过程
--创建名为 GetStuCou_Out 的有输入参数和输出参数的存储过程
create procedure GetStuCou_Out
@StuNo nvarchar(64),
@Height nvarchar(32) output
as
begin
if(@StuNo is not null and @StuNo <> '')
begin
select @Height=S_Height
from Student
where S_StuNo=@StuNo
end
else
begin
set @Height='185'
end
end
--执行名为 GetStuCou_Out 的有输入参数和输出参数的存储过程
execute GetStuCou_Out '005',null