-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdesign.html
165 lines (154 loc) · 5.3 KB
/
design.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rauf: AI and ML</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
#comment{
color: lightgreen;
}
body {
background-color: white;
color: black;
}
.main-heading {
color: blue;
}
.navbar {
background-color: rgb(199, 193, 193);
}
.navbar-brand {
font-weight: bold;
color: blue;
}
.navbar-nav .nav-link {
color: blue;
}
.content img {
max-width: 100%;
height: auto;
display: block;
margin: 20px auto;
}
footer {
background-color: white;
color: black;
padding: 15px 0;
}
pre {
background-color: white;
color: blue;
padding: 15px;
border-radius: 5px;
overflow-x: auto;
}
</style>
</head>
<body>
<!-- navbar -->
<nav class="navbar navbar-expand-lg">
<div class="container">
<a class="navbar-brand" href="https://rauf-psi.vercel.app/">Rauf</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="tutorialDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Notes
</a>
<ul class="dropdown-menu dropdown-menu-dark" aria-labelledby="tutorialDropdown">
<li><a class="dropdown-item" href="index.html">Quering</a></li>
<li><a class="dropdown-item" href="relating.html">Relating</a></li>
<li><a class="dropdown-item" href="#">Designing</a></li>
<li><a class="dropdown-item" href="writing.html">Writing</a></li>
<li><a class="dropdown-item" href="viewing.html">Viewing</a></li>
<li><a class="dropdown-item" href="optimizing.html">Optimizing</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<!-- header -->
<header class="container text-center my-4">
<h1 class="main-heading">Rauf</h1>
<h5>AI and ML</h5>
<h2 class="main-heading">Designing a Database</h2>
</header>
<!-- content -->
<div class="container content">
<section id="schemas" class="mb-5">
<h2 class="main-heading">Schemas</h2>
<p>A schema is the structure of a database, defining tables, columns, relationships, and other elements. It organizes data logically.</p>
<pre><code>CREATE SCHEMA Company;
CREATE TABLE Company.Employees (
EmployeeID INT PRIMARY KEY,
Name VARCHAR(100) NOT NULL,
DepartmentID INT,
FOREIGN KEY (DepartmentID) REFERENCES Company.Departments(DepartmentID)
);
</code></pre>
</section>
<section id="normalization" class="mb-5">
<h2 class="main-heading">Normalization</h2>
<p>Normalization is the process of organizing data to reduce redundancy and improve integrity. It involves splitting data into related tables.</p>
<pre><code> <p id="comment"> -- Example of splitting data into two tables for normalization </p>
CREATE TABLE Customers (
CustomerID INT PRIMARY KEY,
Name VARCHAR(100),
Email VARCHAR(100)
);
CREATE TABLE Orders (
OrderID INT PRIMARY KEY,
CustomerID INT,
OrderDate DATE,
FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)
);
</code></pre>
</section>
<section id="datatypes" class="mb-5">
<h2 class="main-heading">Data Types</h2>
<p>Data types define the kind of data that can be stored in a column. Common types include INT, VARCHAR, DATE, and BOOLEAN.</p>
<pre><code>CREATE TABLE Products (
ProductID INT PRIMARY KEY,
Name VARCHAR(255) NOT NULL,
Price DECIMAL(10, 2),
Available BOOLEAN DEFAULT TRUE
);
</code></pre>
</section>
<section id="constraints" class="mb-5">
<h2 class="main-heading">Table Constraints</h2>
<p>Constraints ensure data integrity. Examples include PRIMARY KEY, FOREIGN KEY, CHECK, DEFAULT, NOT NULL, and UNIQUE.</p>
<pre><code>CREATE TABLE Students (
StudentID INT PRIMARY KEY,
Name VARCHAR(100) NOT NULL,
Age INT CHECK (Age >= 18),
Email VARCHAR(100) UNIQUE
);
</code></pre>
</section>
<section id="altering" class="mb-5">
<h2 class="main-heading">Altering Tables</h2>
<p>Use SQL commands to modify the structure of an existing table, such as adding, renaming, or removing columns.</p>
<pre><code><p id="comment"> -- Add a new column </p>
ALTER TABLE Employees ADD COLUMN PhoneNumber VARCHAR(15);
<p id="comment"> -- Rename a column </p>
ALTER TABLE Employees RENAME COLUMN PhoneNumber TO ContactNumber;
<p id="comment"> -- Drop a column </p>
ALTER TABLE Employees DROP COLUMN ContactNumber;
</code></pre>
</section>
</div>
<!-- Footer -->
<footer class="text-center">
<p>23 Dec 2024 Rauf AI and ML</p>
</footer>
<!-- Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>