数据库的实现
来源:互联网 发布:licecap for mac 编辑:程序博客网 时间:2024/06/16 18:31
一.创建数据库:
1.语法: create database 表名
on (
<数据文件参数>[,·······] [<文件组参数>]
)
log on
(
<日志文件参数>[,········]
)
例子:
create database stuDB on primary -- 默认就属于primary文件组,可省略 ( /*--数据文件的具体描述--*/ name='stuDB_data', -- 主数据文件的逻辑名称 filename='D:\stuDB_data.mdf', -- 主数据文件的物理名称 size=5mb, --主数据文件的初始大小 maxsize=100mb, -- 主数据文件增长的最大值 filegrowth=15%--主数据文件的增长率 ) log on ( /*--日志文件的具体描述,各参数含义同上--*/ name='stuDB_log', filename='D:\stuDB_log.ldf', size=2mb, filegrowth=1mb )
2.删除数据库:
语法:
drop database 数据库名
例子:
drop database bankDB
二.创建表:
1.语法:
create table 表名
(
列1 数据类型 列的特征,
列2 数据类型 列的特征,
.......
)
例子:
create table student
(
studentno int not null,
name nvarchar(20) not null,
age int not null
)
2.删除表:
语法:
drop table 表名
例子:
drop table student
三.添加约束:
1. 常用的五大约束的语法示例
1.—-添加主键约束(将stuNo作为主键)
alter table stuInfo
add constraint PK_stuNo primary key (stuNo)
2.—-添加唯一约束(身份证号唯一,因为每个人的都不一样)
alter table stuInfo
add constraint UQ_stuID unique(stuID)
3.—-添加默认约束(如果地址不填 默认为“地址不详”)
alter table stuInfo
add constraint DF_stuAddress default (‘地址不详’) for stuAddress
4.—-添加检查约束 (对年龄加以限定 15-40岁之间)
alter table stuInfo
add constraint CK_stuAge check (stuAge between 15 and 40)
alter table stuInfo
add constraint CK_stuSex check (stuSex=’男’ or stuSex=’女′)
5.—-添加外键约束 (主表stuInfo和从表stuMarks建立关系,关联字段stuNo)
alter table stuInfo
add constraint FK_stuNo foreign key(stuNo)references stuinfo(stuNo)
2.删除约束:
alter table 表名 drop constraint 约束名
例子: alter table student drop constraint FK_stuNo
- 数据库的实现
- 数据库的分页实现
- java数据库的实现
- 实现数据库的操作
- 数据库实现的留言板
- 数据库的实现
- 关系数据库的实现
- 数据库的分页实现
- 数据库的简单实现
- 数据库索引的实现
- 数据库的实现【笔记】
- 数据库的实现
- 数据库的实现
- 数据库设计、数据库的实现、SQL编程
- J2EE -- 数据库事务处理的实现
- 实现两个数据库的同步***
- derby数据库分页的实现
- 如何实现数据库的优化
- beautiful soul 解析html
- 使用PL/SQL备份和恢复Oracle
- weex 调试
- iOS开发中遇到过的坑
- 优化MySchool 第六章 上机
- 数据库的实现
- java中equals()方法与hashCode()方法的隐式调用时的约定详解
- Java中的原子操作类
- java基础学习集合之list 九-2
- 行为类模式(读书笔记)
- WSClient客户端调用---codehaus.xfire
- C语言中全局变量、局部变量、静态全局变量、静态局部变量的区别
- ORCLE 知识总结
- LeetCode-35. Search Insert Position