-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.sql
45 lines (37 loc) · 1.34 KB
/
db.sql
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
drop database java4
create database java4
use java4
CREATE TABLE users (
userid INT IDENTITY(1,1) NOT NULL,
username VARCHAR(50) NOT NULL,
email VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
isActive BIT DEFAULT 1,
PRIMARY KEY (userid),
CONSTRAINT uq_email UNIQUE (email)
);
CREATE TABLE user_logs (
log_id INT IDENTITY(1,1) NOT NULL,
userid INT NOT NULL,
login_time DATETIME NOT NULL CONSTRAINT DF_user_logs_login_time DEFAULT GETDATE(),
logout_time DATETIME,
PRIMARY KEY (log_id),
FOREIGN KEY (userid) REFERENCES users(userid)
);
INSERT INTO user_logs (userid)
SELECT TOP 10 userid FROM users;
INSERT INTO users (username, email, password)
VALUES
('john_doe', '[email protected]', 'password1'),
('jane_doe', '[email protected]', 'password2'),
('bob_smith', '[email protected]', 'password3'),
('sara_jones', '[email protected]', 'password4'),
('mike_taylor', '[email protected]', 'password5'),
('kim_nguyen', '[email protected]', 'password6'),
('dan_brown', '[email protected]', 'password7'),
('tina_foster', '[email protected]', 'password8'),
('matt_jackson', '[email protected]', 'password9'),
('amy_lee', '[email protected]', 'password10');
select * from users
select * from user_logs
delete from user_logs