⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 my.txt

📁 to study the example of creation of tables, formative DB, and filling with their information. Using
💻 TXT
📖 第 1 页 / 共 2 页
字号:
if NOT exists(select TABLE_NAME from INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Countries')
BEGIN
create table Countries (id_country int identity  PRIMARY KEY, 
						country_name varchar(50))
insert into Countries 
select 'Ukraine'
union select 'Russia'
union select 'Belorussia'
union select 'Kazahstan'
union select 'Turkey'

END
--ELSE
--DROP TABLE Countries


if NOT exists(select TABLE_NAME from INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Cities')
BEGIN
create table Cities (id_city int identity PRIMARY KEY,
					 city_name varchar(50))
insert into Cities 
select 'Dnipropetrovsk'
union select 'Kharkiv'
union select 'Moscow'
union select 'Kiev'
union select 'Minsk'

END
--ELSE
--DROP TABLE Cities


if NOT exists(select TABLE_NAME from INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Streets')
BEGIN
create table Streets (id_street int identity PRIMARY KEY, 
					  street_name varchar(50))
insert into Streets 
select 'Kazakova'
union select 'Gagarina'
union select 'Lenina'
union select 'Gorkogo'
union select 'Shevchenko'

END
--ELSE
--DROP TABLE Streets


if NOT exists(select TABLE_NAME from INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Person')
BEGIN
create table Person (id_person int identity PRIMARY KEY ,
					 st_surname varchar(50),
					 st_name varchar(50),
					 st_pname varchar(50), 
					 st_sex bit,
					 st_birthday datetime, 
					 st_phone varchar(15),
					 st_military bit,
					 id_country int REFERENCES Countries, 
				     id_city int REFERENCES Cities, 
					 id_street int REFERENCES Streets, 
					 house varchar(10),
					 flat int,
					 check(datediff(d,st_birthday, getdate())>0)
					 )
insert into Person 
select 'Kyrgyzova','Khrystyna','Valentinovna','1','28 Aug 88','8-0562-38-17-26','0', 1, 1, 1, '34',5
union select 'Duma','Karina','Valentinovna','1','2 Aug 87','8-0562-38-17-26','0', 1, 1, 2, '75', 31
union select 'Kulichenko','Petr','Afanasjevich','0','25 Aug 89','8-0592-35-18-46','1',  1, 1, 3, '20b', 2
union select 'Ivanenko','Oleg','Georgievich','0','23 Jul 88','8-0532-36-55-26','1',1, 2, 1, '2a', 16
union select 'Zubr','Pavel','Petrovich','0','2 Feb 89','8-056-774-17-26','1', 1, 1, 4, '21', 8
union select 'Ivanov','Ivan','Ivanovich','0','23 Sep 88','8-0532-36-57-86','1', 2, 2, 2, '43', 8
union select 'Kulibaba','Irina','Valentinovna','1','2 Aug 88','8-0562-38-17-26','0', 1, 2, 1, '4', 8
union select 'Petrov','Petr','Petrovich','0','23 Sep 88','8-0532-36-57-86','1', 1, 1, 3, '21', 4
union select 'Lawina','Khrystyna','Valentinovna','1','28 Aug 88','8-0562-38-17-26','0', 1, 1, 5, '45', 2
union select 'Sergeev','Ivan','Ivanovich','0','23 Sep 88','8-0532-36-57-86','1', 4, 1, 3, '21', 8
union select 'Procenko','Khrystyna','Valentinovna','1','28 Aug 88','8-0562-38-17-26','0', 1, 1, 3, '4', 7
union select 'Kucjko','Ivan','Ivanovich','0','23 Sep 88','8-0532-36-57-86','1', 1, 1, 1, '21', 8
union select 'Zasteba','Khrystyna','Valentinovna','1','28 Aug 88','8-0562-38-17-26','0', 1, 1, 1, '2a', 2
union select 'Pavlov','Ivan','Ivanovich','0','23 Sep 88','8-0532-36-57-86','1', 5, 1, 5, '21', 8
union select 'Karacjuba','Khrystyna','Valentinovna','1','28 Aug 88','8-0562-38-17-26','0', 1, 1, 2, '3', 1
union select 'Wava','Ivan','Ivanovich','0','23 Sep 88','8-0532-36-57-86','1', 1, 1, 1, '21', 43
union select 'Kalinova','Khrystyna','Valentinovna','1','28 Aug 88','8-0562-38-17-26','0', 1, 1, 1, '30b', 45
union select 'Prosolov','Ivan','Ivanovich','0','23 Sep 88','8-0532-36-57-86','1', 1, 1, 1, '21', 2
union select 'Kazakova','Khrystyna','Valentinovna','1','28 Aug 88','8-0562-38-17-26','0', 1, 1, 1, '3', 56
union select 'Zaharov','Ivan','Ivanovich','0','23 Sep 88','8-0532-36-57-86','1', 1, 1, 3, '21', 1
union select 'Popova','Khrystyna','Valentinovna','1','28 Aug 88','8-0562-38-17-26','0', 3, 1, 2, '2', 4
union select 'Bokov','Ivan','Ivanovich','0','23 Sep 88','8-0532-36-57-86','1', 3, 2, 1, '21', 8
union select 'Jdanova','Khrystyna','Valentinovna','1','28 Aug 88','8-0562-38-17-26','0', 1, 1, 1, '8', 3
union select 'Kotov','Ivan','Ivanovich','0','23 Sep 88','8-0532-36-57-86','1', 1, 1, 1, '21', 8
union select 'Kapusta','Khrystyna','Valentinovna','1','28 Aug 88','8-0562-38-17-26','0', 1, 1, 2, '32', 10

END
--ELSE
--DROP TABLE Person


if NOT exists(select TABLE_NAME from INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Specialnosti')
BEGIN
create table Specialnosti (id_spec smallint identity PRIMARY KEY, 
							spec_name varchar(50))
insert into Specialnosti 
select 'KS'
union select 'KI'
union select 'KM'
union select 'KP'
union select 'KT'
END
--ELSE
--DROP TABLE Specialnosti



if NOT exists(select TABLE_NAME from INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Grouppa')
BEGIN
create table Grouppa (id_group int identity PRIMARY KEY,
					  group_name varchar(9),
					  id_spec int REFERENCES Specialnosti,
					  kurs tinyint default 1)
insert into Grouppa
select 'KS-05', 1, 4
union select 'KI-05', 'KI', 2, 4
union select 'KM-08', 'KM', 3, 1
union select 'KP-06','KP', 4, 2
union select 'KT-04','KT',5, 3


END
--ELSE
--DROP TABLE Grouppa


if NOT exists(select TABLE_NAME from INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Form_edu')
BEGIN
create table Form_edu (id_form smallint PRIMARY KEY,
					   form_name varchar(10))
insert into Form_edu 
select '1','Dnevnoe'
union select '2','Vechernee'
union select'3','Zaochne'
union select'4','Extern'

END
--ELSE
--DROP TABLE Form_edu



if NOT exists(select TABLE_NAME from INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Student')
BEGIN
create table Student (id_stud int identity PRIMARY KEY , 
					  id_person int NOT NULL REFERENCES Person,
					  id_group smallint NOT NULL REFERENCES Grouppa,
					  id_form smallint NOT NULL REFERENCES Form_edu,
					  finance bit)
insert into Student 
select 1,1,1,0
union select 2,1,1,1
union select 3,1,1,0
union select 4,1,4,1
union select 5,2,2,0
union select 6,2,2,1
union select 7,2,2,0
union select 8,3,3,1
union select 9,3,3,0
union select 10,3,3,1
union select 11,3,3,0
union select 12,3,3,1
union select 13,3,3,0
union select 14,3,3,1
union select 15,4,1,0
union select 16,4,1,1
union select 17,4,1,0
union select 18,5,4,1
union select 19,5,1,0
union select 20,5,1,1
union select 21,5,4,0
union select 22,5,1,1
union select 23,5,1,0
union select 24,5,4,1
union select 25,5,1,0

END
--ELSE
--DROP TABLE Student

if NOT exists(select TABLE_NAME from INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Subject_names')
BEGIN
create table Subject_names (id_subject int identity PRIMARY KEY,
							subject_name varchar(30))
insert into Subject_names
select 'fizika'
union select 'algebra'
union select 'geometrija'
union select 'OPAM'
union select 'SQL'
union select 'IKG'
union select 'C++'
union select 'English'
union select 'Ukr.mova'
union select 'UML'
union select 'CASE-tech'
union select 'Elektrotech'
union select 'Schemotech'
union select 'Assembler'
union select 'Teor.ver'
union select 'Networks'
union select 'Algorithms'
union select 'Image Processing'
union select 'Signal Processing'
union select 'TAU'
END
--ELSE
--DROP TABLE Subject_names


if NOT exists(select TABLE_NAME from INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Mark_names')
BEGIN
create table Mark_names (id_mark tinyint identity PRIMARY KEY, 
						 ball_name tinyint, 
						 bolon_mark_name varchar(10),
						 zach_nezach bit)
insert into Mark_names 
      select 1,'E',0--1
union select 2,'D',0--2
union select 3,'C',1--3
union select 4,'B',1--4
union select 5,'A',1--5
END
--ELSE
--DROP TABLE Mark_names


if NOT exists(select TABLE_NAME from INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Mark')
BEGIN
create table Mark (id_stud int REFERENCES Student , 
					id_subject int REFERENCES Subject_names ,
					id_mark tinyint REFERENCES Mark_names)

insert into Mark 
select 1, 1, 4
union select  1 , 2 , 5  
union select  1 , 3 , 6  
union select  1 , 4 , 7  
union select  1 , 5 , 4  
union select  1 , 6 , 5  
union select  1 , 7 , 6  
union select  1 , 8 , 7  
union select  1 , 9 , 5  
union select  1 , 10 , 5  

union select  2 , 11 , 4  
union select  2 , 12 , 5  
union select  2 , 13 , 6  
union select  2 , 14 , 7  
union select  2 , 15 , 4  
union select  2 , 16 , 5  
union select  2 , 17 , 6  
union select  2 , 18 , 7  
union select  2 , 19 , 5  
union select  2 , 20 , 5  

union select  3 , 1 , 4  
union select  3 , 2 , 5  
union select  3 , 3 , 6  
union select  3 , 4 , 7  
union select  3 , 5 , 4  
union select  3 , 6 , 5  
union select  3 , 7 , 6  
union select  3 , 8 , 7  
union select  3 , 9 , 5  
union select  3 , 10 , 5  

union select  4 , 11 , 4  
union select  4 , 12 , 5  
union select  4 , 13 , 6  
union select  4 , 14 , 7  
union select  4 , 15 , 4  
union select  4 , 16 , 5  
union select  4 , 17 , 6  
union select  4 , 18 , 7  
union select  4 , 19 , 5  
union select  4 , 20 , 5  

union select  5 , 1 , 4  
union select  5 , 2 , 5  
union select  5 , 3 , 6  
union select  5 , 4 , 7  
union select  5 , 5 , 4  
union select  5 , 6 , 5  
union select  5 , 7 , 6  
union select  5 , 8 , 7  
union select  5 , 9 , 5  
union select  5 , 10 , 5  

union select  6 , 11 , 4  
union select  6 , 12 , 5  
union select  6 , 13 , 6  
union select  6 , 14 , 7  
union select  6 , 15 , 4  
union select  6 , 16 , 5  
union select  6 , 17 , 6  
union select  6 , 18 , 7  
union select  6 , 19 , 5  
union select  6 , 20 , 5  

union select  7 , 1 , 4  
union select  7 , 2 , 5  
union select  7 , 3 , 6  
union select  7 , 4 , 7  
union select  7 , 5 , 4  
union select  7 , 6 , 5  
union select  7 , 7 , 6  
union select  7 , 8 , 7  
union select  7 , 9 , 5  
union select  7 , 10 , 5  

union select  8 , 11 , 4  
union select  8 , 12 , 5  
union select  8 , 13 , 6  
union select  8 , 14 , 7  
union select  8 , 15 , 4  
union select  8 , 16 , 5  
union select  8 , 17 , 6  
union select  8 , 18 , 7  
union select  8 , 19 , 5  
union select  8 , 20 , 5  

union select  9 , 1 , 4  
union select  9 , 2 , 5  
union select  9 , 3 , 6  
union select  9 , 4 , 7  
union select  9 , 5 , 4  
union select  9 , 6 , 5  
union select  9 , 7 , 6  
union select  9 , 8 , 7  
union select  9 , 9 , 5  
union select  9 , 10 , 5  

union select  10 , 11 , 4  
union select  10 , 12 , 5  
union select  10 , 13 , 6  
union select  10 , 14 , 7  
union select  10 , 15 , 4  
union select  10 , 16 , 5  
union select  10 , 17 , 6  
union select  10 , 18 , 7  
union select  10 , 19 , 5  
union select  10 , 20 , 5  

union select  11 , 11 , 4  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -