· 7 years ago · Nov 17, 2018, 06:38 AM
1-- Create a new database called 'EcologyDB'
2-- Connect to the 'master' database to run this snippet
3USE master
4GO
5-- Create the new database if it does not exist already
6IF NOT EXISTS (
7 SELECT name
8 FROM sys.databases
9 WHERE name = N'Rk2_var4_DB'
10)
11CREATE DATABASE Rk2_var4_DB
12GO
13
14USE Rk2_var4_DB
15GO
16
17-- Create a new table
18-- Drop the table if it already exists
19IF OBJECT_ID('link', 'U') IS NOT NULL
20DROP TABLE link
21GO
22-- Create the table in the specified schema
23CREATE TABLE link
24(
25 Id INT NOT NULL,
26 id_place INT NOT NULL,
27 id_man INT NOT NULL,
28);
29GO
30
31-- Create a new table
32-- Drop the table if it already exists
33IF OBJECT_ID('place', 'U') IS NOT NULL
34DROP TABLE place
35GO
36-- Create the table in the specified schema
37CREATE TABLE place
38(
39 Id INT NOT NULL,
40 Name NVARCHAR(85) NOT NULL,
41 Dist NVARCHAR(85) NOT NULL,
42 year DATE NOT NULL
43);
44GO
45
46-- Create a new table
47-- Drop the table if it already exists
48IF OBJECT_ID('man', 'U') IS NOT NULL
49DROP TABLE man
50GO
51-- Create the table in the specified schema
52CREATE TABLE man
53(
54 Id INT NOT NULL,
55 FullName NVARCHAR(85) NOT NULL,
56 Birthday Date NOT NULL,
57 Home NVARCHAR(85) NOT NULL,
58 Email NVARCHAR(85) NOT NULL
59);
60GO
61
62-- Create a new table
63-- Drop the table if it already exists
64IF OBJECT_ID('region', 'U') IS NOT NULL
65DROP TABLE region
66GO
67-- Create the table in the specified schema
68CREATE TABLE region
69(
70 Id INT NOT NULL,
71 Name NVARCHAR(85) NOT NULL,
72 Dist NVARCHAR(85) NOT NULL
73);
74GO