SQL创建数据库、建表、填入内容
--创建数据库
create database Information go --使用数据库
use Information go --创建表
create table Student
(
Sno nvarchar(50) primary key not null,
Sname nvarchar(50) not null,
Ssex bit not null,
Sbirthday datetime,
Class nvarchar(50),
) create table Course
(
Cno nvarchar(50) primary key not null,
Cname nvarchar(50) not null,
Tno nvarchar(50) not null,
) create table Score
(
Sno nvarchar(50) not null,
Cno nvarchar(50) not null,
Degree decimal(4,1),
) create table Teacher
(
Tno nvarchar(50) primary key not null,
Tname nvarchar(50) not null,
Tsex bit not null,
Tbirthday datetime,
Prof nvarchar(50),
Depart nvarchar(50) not null,
) --填入数据 Student
insert into Student values('','曾华','','1977-09-01','')
insert into Student values('','匡明','','1975-10-02','')
insert into Student values('','王丽','','1976-01-23','')
insert into Student values('','李军','','1976-02-20','')
insert into Student values('','王芳','','1975-02-10','')
insert into Student values('','陆君','','1974-06-03','') --填入数据 Course
insert into Course values('3-105','计算机导论','')
insert into Course values('3-245','操作系统','')
insert into Course values('6-166','数字电路','')
insert into Course values('9-888','高等数学','') --填入数据 Score
insert into Score values('','3-245','')
insert into Score values('','3-245','')
insert into Score values('','3-245','')
insert into Score values('','3-105','')
insert into Score values('','3-105','')
insert into Score values('','3-105','')
insert into Score values('','3-105','')
insert into Score values('','3-105','')
insert into Score values('','3-105','')
insert into Score values('','6-166','')
insert into Score values('','6-166','')
insert into Score values('','6-166','') --填入数据 Teacher
insert into Teacher values('','李诚','','1958-12-02','副教授','计算机系')
insert into Teacher values('','张旭','','1969-03-12','讲师','电子工程系')
insert into Teacher values('','王萍','','1972-05-05','助教','计算机系')
insert into Teacher values('','刘冰','','1977-08-14','助教','电子工程系') --主外键关系
--如表A中的Ids是主键,要约束表B中的Aid列,那么语句应该是:
--alter table B add constraint A_B_Ids foreign key(Aid) references A(Ids) --Student 中的Sno 约束 Score 中的 Sno
alter table Score add constraint Student_Score_Sno foreign key(Sno) references Student(Sno) --Course 中的 Cno 约束 Score 中的 Cno
alter table Score add constraint Course_Score_Cno foreign key(Cno) references Course(Cno) --Teacher 中的 Tno 约束 Course 中的 Tno
alter table Course add constraint Teacher_Course_Tno foreign key(Tno) references Teacher(Tno)
创建好数据库,建表,填入内容后准备开始练习
SQL创建数据库、建表、填入内容的更多相关文章
- 第16课-数据库开发及ado.net-数据库SQl,创建数据库和表,增删改语句,约束,top和Distinct,聚合函数介绍
第16课-数据库开发及ado.net 数据库SQl,创建数据库和表,增删改语句,约束,top和Distinct,聚合函数介绍 SQL语句入门(脚本.命令) SQL全名是结构化查询语言(Structur ...
- 2016年11月14日--SQL创建数据库、表-查、插、删、改
--创建数据库(create database 数据库名)create database hq20161114go --使用选择数据库(use 数据库名)use hq20161114go --创建学生 ...
- SQL创建数据库、表、存储过程及调用
--如果存在数据库PRogrammerPay 就删除 if exists (select * from sysdatabases where name='programmerPay') drop d ...
- 创建数据库和表的SQL语句【转】
创建数据库和表的SQL语句 转至http://www.cnblogs.com/philanthr/archive/2011/08/09/2132398.html 创建数据库的SQL语句: 1 crea ...
- 字段自动递增的数据库建表的SQL写法
数据库建表的SQL写法如下: 数据库建表的SQL写法如下: create table dataC( a int identity(1,2) primary key, b varchar(20)) ...
- SQL Server数据库、表、数据类型基本概念
一.SQL Server的数据存储结构 SQL Server是一个数据库管理系统,需要以有效方式存储高容量数据.要更好地理解SQL Server处理数据的方式,就需要了解数据的存储结构. 1.文件类型 ...
- 【Java框架型项目从入门到装逼】第九节 - 数据库建表和CRUD操作
1.新建学生表 这节课我们来把和数据库以及jdbc相关的内容完成,首先,进行数据库建表.数据库呢,我们采用MySQL数据库,我们可以通过navcat之类的管理工具来轻松建表. 首先,我们得建一个数据库 ...
- ylb:创建数据库、表,对表的增查改删语句
ylbtech-SQL Server:SQL Server-创建数据库.表,对表的增查改删语句 SQL Server 创建数据库.表,对表的增查改删语句. 1,ylb:创建数据库.表,对表的增查改删语 ...
- PowerDesigner连接Oracle数据库建表序列号实现自动增长
原文:PowerDesigner连接Oracle数据库建表序列号实现自动增长 创建表就不说了.下面开始介绍设置自动增长列. 1 在表视图的列上创建.双击表视图,打开table properties — ...
随机推荐
- Hadoop学习之路(二十六)MapReduce的API使用(三)
影评案例 数据及需求 数据格式 movies.dat 3884条数据 1::Toy Story (1995)::Animation|Children's|Comedy 2::Jumanji (1995 ...
- 业务id转密文短链的一种实现思路
业务场景: 买家通过电商app下单后,会受到一条短信,短信内容中包括改订单详情页面的h5地址连接,因为是出现在短信中,所以对连接有要求: 1.尽量短:2.安全性考虑,订单在数据库中对应的自增主键id不 ...
- 1、RabbitMQ入门
RabbitMQ 可以参考官网进行学习! 开发语言:Erlang – 面向并发的编程语言. AMQP:是消息队列的一个协议. mysql 是 java 写的吗?不是 那么 java 能不能访问?可以, ...
- .net中使用mysql回滚和sqlserver回滚的区别
关于sqlserver事务和mysql事务 首先这是一种方法 public static int GetExecteQuery() { SqlConnection ...
- URL列表
MySql函数大全:http://www.cnblogs.com/xuyulin/p/5468102.html
- Linux-- su和sudo 切换用户
su 切换用户 用法:su [选项] [-] [用户 [参数]... ] - :以 login-shell 方式进行登录 不加 - :以 no-login-shell 方式进行登录 -c:只进行一次在 ...
- DBA手记(学习)-library cache pin
select sid,event,p1raw from v$session_wait where event like 'library cache pin%'; select sql_text fr ...
- C++ primer第三章作业
3.1节 练习3.1: 使用恰当的using声明重做1.4.1节(第11页)和2.6.2节(第67页)的练习 #ifdef 1 #include <iostream> using std: ...
- Ubuntu如何挂载U盘
1. 以root用户登陆 2. 查看当前挂载 fdisk -l 一般情况未挂载的硬盘都在最后,这里是/dev/sdb1 3.新建一个目录来挂载硬盘 挂载到MNT/usb root@h-Default- ...
- putty登录出现access denied的解决办法
[转]https://www.aliyun.com/jiaocheng/152659.html 在/etc/ssh/sshd_config 中有个 PermitRootLogin, 改成“Permit ...