sql server建库建表,增删改查,创建视图事务存储过程

最简单的建库建表语句。

/创建数据库/

use master
create database HD_LMS
on(
name='HD_LMS',
filename='HD_LMS.mdf'
)
log on(
name='HD_LMS_log',
filename='HD_LMS_log.ldf'
)

/创建表/

use [HD_LMS]
create table T_girlFrend(
F_ID int identity(1,1) primary key not null,
F_Name nvarchar(100) not null,
F_Age int 
)

–查询

select * from T_girlFrend 

–模糊查询

select * from T_girlFrend where F_name like '%靓妹%'

–批量添加

insert into T_girlFrend (F_Name,F_Age) values
('s',21),
('y',23),
('阁',23)

–修改

update T_girlFrend set  F_Name='王某' where F_ID=1;

–删除

delete from T_girlFrend where f_id=3;

–创建视图

create view T_GIRL as select * from T_girlFrend

使用视图

select * from T_GIRL

–修改视图

alert view T_GIRL as ....

–删除试图

DROP VIEW T_GIRL ;

–事务

begin try
begin tran--设置回滚点
delete from t_User where F_CODE >2
delete from t_girlfrend where F_Age>18
commit tran--提交
end try
begin catch
rollback tran--回滚
end catch

–存储过程
–创建

create proc GrilF
@n1 int
as
begin
select * from T_girlFrend where F_Age >@n1
end

–使用

exec GrilF 3

你可能感兴趣的:(sql,server,sql,数据库)