SQL数据库

来源:互联网 发布:赛迦奥特曼大电影知版 编辑:程序博客网 时间:2024/04/28 22:28

一.创建数据库的SQL语句

1 create database stuDB 

2 on  primary  -- 默认就属于primary文件组,可省略

3 (

 4 /*--数据文件的具体描述--*/

5     name='stuDB_data'-- 主数据文件的逻辑名称

6     filename='D:\stuDB_data.mdf',-- 主数据文件的物理名称

7     size=5mb,--主数据文件的初始大小

 8     maxsize=100mb,-- 主数据文件增长的最大值

 9     filegrowth=15%--主数据文件的增长率

10 )

11 log on

12 (

13 /*--日志文件的具体描述,各参数含义同上--*/

14     name='stuDB_log',

15     filename='D:\stuDB_log.ldf',1

6     size=2mb,

17     filegrowth=1mb18)

二.删除这个数据库

use master -- 设置当前数据库为master,以便访问sysdatabases表
go
if exists(select* from sysdatabaseswhere name='stuDB')
drop database stuDB
go

三.创建表和删除表的SQL语句

use StuDB
go
if exists(select* from sysobjectswhere name='stuMarks')
drop table stuMarks
create table stuMarks
(
    ExamNo     
int     identity(1,1) primary key,
    stuNo      
char(6) notnull,
    writtenExam
int     notnull,
    LabExam    
int     notnull
)
go

alter table 表名add constraint 约束名 约束类型 具体的约束说明alter table 表名drop constraint 约束名
alter table stuMarksadd constraint UQ_stuNo Unique(stuNo)
alter table stuMarksdrop constraint UQ_stuNo

 

0 0
原创粉丝点击