-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDb.txt
190 lines (162 loc) · 5.79 KB
/
Db.txt
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
USE SMS_SIS;
GO
-- Create the Users table
CREATE TABLE Users (
UserID INT IDENTITY(1,1) PRIMARY KEY,
Username NVARCHAR(50) NOT NULL,
Password NVARCHAR(50) NOT NULL,
UserType NVARCHAR(20) NOT NULL,
FullName NVARCHAR(100) NOT NULL,
Email NVARCHAR(100),
ContactNumber NVARCHAR(20)
);
GO
-- Create the Students table
CREATE TABLE Students (
StudentID INT IDENTITY(1,1) PRIMARY KEY,
RegNo NVARCHAR(20),
FullName NVARCHAR(100) NOT NULL,
Gender NVARCHAR(10),
DOB DATE,
Address NVARCHAR(255),
Contact NVARCHAR(20),
Email NVARCHAR(100),
GuardianName NVARCHAR(100),
GuardianContactNumber NVARCHAR(20),
Class NVARCHAR(50),
FOREIGN KEY (StudentID) REFERENCES Users(UserID)
);
GO
-- Create the Teachers table
CREATE TABLE Teachers (
TeacherID INT IDENTITY(1,1) PRIMARY KEY,
FullName NVARCHAR(100) NOT NULL,
DOB DATE,
ContactNumber NVARCHAR(20),
Address NVARCHAR(255),
Gender NVARCHAR(10),
Email NVARCHAR(100),
Subjects NVARCHAR(255),
OwnedClass NVARCHAR(50),
FOREIGN KEY (TeacherID) REFERENCES Users(UserID)
);
GO
-- Create the Classes table
CREATE TABLE Classes (
ClassID INT IDENTITY(1,1) PRIMARY KEY,
ClassName NVARCHAR(50),
ClassTeacherID INT,
FOREIGN KEY (ClassTeacherID) REFERENCES Teachers(TeacherID)
);
GO
-- Create the Noticeboard table
CREATE TABLE Noticeboard (
NoticeID INT IDENTITY(1,1) PRIMARY KEY,
Title NVARCHAR(100),
Description NVARCHAR(MAX),
PostedBy INT,
PostedDate DATETIME,
ExpiredDate DATETIME,
FOREIGN KEY (PostedBy) REFERENCES Users(UserID)
);
GO
-- Create the Attendance table
CREATE TABLE Attendance (
AttendanceID INT IDENTITY(1,1) PRIMARY KEY,
ClassID INT,
Date DATE,
StudentID INT,
Status NVARCHAR(20),
FOREIGN KEY (ClassID) REFERENCES Classes(ClassID),
FOREIGN KEY (StudentID) REFERENCES Students(StudentID)
);
GO
SCRIPT DATABASE YourDatabaseName TO 'C:\Path\To\Script.sql';
BACKUP DATABASE YourDatabaseName TO DISK = 'C:\Path\To\YourDatabaseBackup.bak' WITH INIT;
-- Insert sample data for Teachers table
INSERT INTO Teachers (FullName, DOB, ContactNumber, Address, Gender, Email, Subjects, OwnedClass)
VALUES ('John Doe', '1990-01-15', '123456789', '123 Main St', 'Male', '[email protected]', 'Math, Physics', 'Class A');
INSERT INTO Teachers (FullName, DOB, ContactNumber, Address, Gender, Email, Subjects, OwnedClass)
VALUES ('Jane Smith', '1985-08-20', '987654321', '456 Oak St', 'Female', '[email protected]', 'Chemistry, Biology', 'Class B');
-- Insert sample data for Classes table
INSERT INTO Classes (ClassName, ClassTeacherID)
VALUES ('Class A', 1); -- Assuming Teacher with ID 1 is the teacher for Class A
INSERT INTO Classes (ClassName, ClassTeacherID)
VALUES ('Class B', 2); -- Assuming Teacher with ID 2 is the teacher for Class B
-- Insert sample data for Users table
INSERT INTO Users (Username, Password, UserType, FullName, Email, ContactNumber)
VALUES ('admin', 'admin123', 'Admin', 'Admin User', '[email protected]', '123456789');
INSERT INTO Users (Username, Password, UserType, FullName, Email, ContactNumber)
VALUES ('student1', 'student123', 'Student', 'Student One', '[email protected]', '987654321');
INSERT INTO Users (Username, Password, UserType, FullName, Email, ContactNumber)
VALUES ('teacher1', 'teacher123', 'Teacher', 'Teacher One', '[email protected]', '555555555');
USE YourDatabaseName; -- Replace with your actual database name
-- Define the backup file path
DECLARE @BackupPath NVARCHAR(255);
SET @BackupPath = 'C:\YourBackupDirectory\YourDatabaseName_FullBackup.bak'; -- Replace with your desired backup path and file name
-- Create a full database backup
BACKUP DATABASE YourDatabaseName -- Replace with your actual database name
TO DISK = @BackupPath
WITH FORMAT, -- Use the WITH FORMAT option to overwrite existing backup files
MEDIANAME = 'YourMediaName', -- Replace with a media name for the backup set
NAME = 'YourBackupSetName'; -- Replace with a name for the backup set
-- Display a success message
PRINT 'Full backup created successfully.';
=====================
USE YourDatabaseName; -- Replace with your actual database name
-- Get table names and columns
SELECT
t.TABLE_NAME,
c.COLUMN_NAME,
c.DATA_TYPE,
c.CHARACTER_MAXIMUM_LENGTH,
c.IS_NULLABLE
FROM
INFORMATION_SCHEMA.TABLES t
JOIN
INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME
WHERE
t.TABLE_TYPE = 'BASE TABLE';
-- Get primary key constraints
SELECT
kcu.TABLE_NAME,
kcu.COLUMN_NAME
FROM
INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
JOIN
INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu ON tc.CONSTRAINT_NAME = kcu.CONSTRAINT_NAME
WHERE
tc.CONSTRAINT_TYPE = 'PRIMARY KEY';
-- Get foreign key constraints
SELECT
fk.name AS FK_Name,
tp.name AS ParentTable,
ref.name AS ReferencedTable,
cp.name AS ParentColumn,
cref.name AS ReferencedColumn
FROM
sys.foreign_keys AS fk
INNER JOIN
sys.tables AS tp ON fk.parent_object_id = tp.object_id
INNER JOIN
sys.tables AS ref ON fk.referenced_object_id = ref.object_id
INNER JOIN
sys.foreign_key_columns AS fkc ON fk.object_id = fkc.constraint_object_id
INNER JOIN
sys.columns AS cp ON fkc.parent_column_id = cp.column_id AND fkc.parent_object_id = cp.object_id
INNER JOIN
sys.columns AS cref ON fkc.referenced_column_id = cref.column_id AND fkc.referenced_object_id = cref.object_id;
-- Get index information
SELECT
t.name AS TableName,
ind.name AS IndexName,
col.name AS ColumnName,
ind.type_desc AS IndexType
FROM
sys.indexes ind
INNER JOIN
sys.tables t ON ind.object_id = t.object_id
INNER JOIN
sys.index_columns ic ON ind.object_id = ic.object_id AND ind.index_id = ic.index_id
INNER JOIN
sys.columns col ON ic.object_id = col.object_id AND ic.column_id = col.column_id;