server2003安装sqlserver以及基本操作

本文介绍了如何在Server 2003上安装SQL Server,包括新建数据库、创建学生表和课程表,以及数据处理的各种操作,如增删改查、聚合函数和时间函数等。还涉及到存储过程的使用和一些系统存储过程的展示。
摘要由CSDN通过智能技术生成

新建数据库

create database stu on
(name='s2',
filename='C:\temp\stu.mdf',
size=3MB,
filegrowth=5%
)
log on(
name='s2_log',
filename='C:\temp\stu.ldf',
size=3MB,
filegrowth=5%
)

 删除数据库

创建学生表

create table stu_info(
    sid int primary key not null identity(1,1),
    name nvarchar(10) not null,
    sex char(2) check(sex in('男','女')) not null,
    age as datediff(year,birth,getdate()),
    birth date not null,
    addr nvarchar(50) default ('北京'),
    email nvarchar(50) check(email like '%@%'),
    tel nvarchar(30),
)

 

删除学生表 

 创建课程表和成绩表

create table course(
    cid int primary key not null identity(1,1),
    cname nvarchar(20) not null, 
)
-- 创建成绩表
create table score(
    sid int foreign key(sid) references stu_info(sid),
    cid int foreign key(cid) references course(cid),
    cj int not null check(cj between 0 and 100),
    primary key(sid,cid),    
)

处理数据

-- 修改表结构
-- 增加字段
alter table stu_info add mr bit
select * from stu_info
alter table stu_info add beizhu nvarchar(200);

-- 删除字段
alter table stu_info drop column beizhu;

-- 修改字段
alter table stu_info alter column beizhu nvarchar(50);

-- 增加数据
-- 全部字段插入
insert into stu_info values('w1','男','1988-8-8','上海','w1@onetest.com','13825689516',0);

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值