sql语句实现数据库的创建和增删改查

创建数据库:

create database student1
on primary
(
name=‘student_data’,
filename=‘C:\project\student_data1.mdf’, //这里的文件存放路径必须是事先创建好的
size=5MB,
maxsize=100MB,
filegrowth=1%
),
filegroup fg
(
name=‘FG_student_data’,
filename=‘C:\project\FG_student_data1.ndf’,
size=3MB,
maxsize=100MB,
filegrowth=1%
)
log on
(
name=‘student_log’,
filename=‘C:\project\student_log1.ldf’,
size=3MB,
maxsize=100MB,
filegrowth=10%
)

创建表格:
use student
go
create table stu
(
id integer identity primary key ,
name varchar(8) not null,
sex varchar(2)
)

删除表格:
use student
go
drop table stu

为表格添加属性:
use student
go
alter table stu
add adr char(10)

删除表格中的属性:
use student
go
alter table stu
drop column sex

增:
use student
go
insert stu(sid,sname,sex) values(‘121212’,‘小明’,‘男’)

删:
use student
go
delete stu where sex=‘男’

改:
use student
go
update stu set sex=‘女’ where sex=‘男’

查:
use student
go
select * from stu

创建视图:
use student
go
create view view_1
as
select * from student where id=1
go
查看视图
select *from view_1
这些都是作者自己一个字一个字码的,希望对你有所帮助,如果觉得对你有帮助,请给作者点个赞

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