Team Ai
Apppublic

Quan1811/docstring-api

sourceHugging Facemitupdated 5mo agoView on Hugging Face
0likes
docstring_db.sql70 linesDownload Raw Back to data
1-- RESET (tránh lỗi khi chạy lại)
2DROP DATABASE IF EXISTS docstring_db;
3
4-- 1.Tạo database
5CREATE DATABASE IF NOT EXISTS docstring_db;
6USE docstring_db;
7
8-- 2. Tạo bảng
9CREATE TABLE users (
10    id INT PRIMARY KEY AUTO_INCREMENT,
11    username VARCHAR(100) NOT NULL,
12    email VARCHAR(100) UNIQUE,
13    password VARCHAR(255) NOT NULL
14);
15
16CREATE TABLE codes (
17    id INT PRIMARY KEY AUTO_INCREMENT,
18    title VARCHAR(255),
19    content TEXT,
20    created_at DATETIME DEFAULT CURRENT_TIMESTAMP
21);
22
23CREATE TABLE docstrings (
24    id INT PRIMARY KEY AUTO_INCREMENT,
25    content TEXT,
26    created_at DATETIME DEFAULT CURRENT_TIMESTAMP
27);
28
29CREATE TABLE history (
30    id INT PRIMARY KEY AUTO_INCREMENT,
31    user_id INT NOT NULL,
32    code_id INT NOT NULL,
33    docstring_id INT NOT NULL,
34    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
35
36    FOREIGN KEY (user_id) REFERENCES users(id),
37    FOREIGN KEY (code_id) REFERENCES codes(id),
38    FOREIGN KEY (docstring_id) REFERENCES docstrings(id)
39);
40
41-- 3. Thêm dữ liệu fake
42INSERT INTO users (username, email, password)
43VALUES 
44('dung123', 'dung@gmail.com', '123456'),
45('anhcoder', 'anh@gmail.com', '123456'),
46('testuser1', 'test1@gmail.com', 'abc123'),
47('testuser2', 'test2@gmail.com', 'abc123');
48
49INSERT INTO codes (content)
50VALUES 
51('print("Hello World")'),
52('def add(a, b): return a + b');
53
54INSERT INTO docstrings (content)
55VALUES 
56('In ra Hello World'),
57('Hàm cộng 2 số');
58
59INSERT INTO history (user_id, code_id, docstring_id)
60VALUES 
61(1, 1, 1),
62(2, 2, 2);
63
64
65SHOW TABLES;
66
67SELECT * FROM users;
68SELECT * FROM codes;
69SELECT * FROM docstrings;
70SELECT * FROM history;