数据库(实验2 数据库表)

创建数据库


//创建数据库数据文件
create database testbase2
on
(name=testbase2_data,
 filename='D:\张小山数据库\lianxi2\testbase2_data.mdf',
 size=5mb,
 maxsize=50mb,
 filegrowth=20%)
 //创建数据库的日志文件
 log on 
 (name=testbase2_log,
  filename='D:\张小山数据库\lianxi2\testbase2_log.ldf',
  size=20mb,
  maxsize=500mb,
  filegrowth=10mb)

/1建教师表/

  create table Teacher
  (TNO char(2) not null,
   TN char(8) not null,
   SEX char(2),
   AGE tinyint,
   PROF char(10),
   SAL smallint,
   COMM smallint,
   DEPT char(10))

/2建学生表/

  create table Student
  (SNO char(2) not null,
   SN char(8) not null,
   SEX char(2),
   AGE tinyint,
   DEPT char(10))

/3建课程表/

  create table Course
  (CNO char(2) not null,
   CN char(10) not null,
   CT tinyint)

/4建选课表/

create table SC
  (SNO char(2) not null,
   CNO char(2) not null,
   CT tinyint)

/5建授课表/

  create table TC
  (TNO char(2) not null,
   CNO char(2) not null,
   Evalution char(20))

数据库表的删除


  /*删除Teacher表*/
  drop table Teacher
  /*删除Student表*/
  drop table Student
  /*删除Course表*/
  drop table Course
  /*删除SC表*/
  drop table SC
  /*删除TC表*/
  drop table TC

数据库表的增加、修改

  /*增加Student的NATIVE列*/
  ALTER table Student
   ADD NATIVE char(40) null
   
  /*修改数据库表Student中的列NATIVE*/
  alter table Student
	alter column NATIVE char(16) null

你可能感兴趣的:(Sql,Server)