Home Database Mysql Tutorial Mysql数据库,表,字符集,主外键等创建的sql模板_MySQL

Mysql数据库,表,字符集,主外键等创建的sql模板_MySQL

Jun 01, 2016 pm 01:02 PM
character set database template

##如果存在同名的数据库,删除此同名的数据库。

DROP DATABASE IF EXISTS cfms;

##如果不存在字符集为utf8的cfms这个数据库,那么就创建

CREATE DATABASE IF NOT EXISTS cfms CHARACTER SET utf8;

##第一次时表示使用此数据库

USE cfms;

##如果存在users这个表了,就删除重新创建

DROP TABLE IF EXISTS cfms.users; ##如果存在要创建的数据库就删除

##如果不存在这个表了,就重新创建。

CREATE TABLE IF NOT EXISTS cfms.users(

id VARCHAR(36) NOT NULL, ##使用UUID,它是36位的

username VARCHAR(10) NOT NULL, ##用户名

password VARCHAR(32) NOT NULL, ##这里使用的是32位的MD5加密

sex VARCHAR(4) DEFAULT NULL, ##你的性别

userage VARCHAR(3) DEFAULT NULL , ##你的年龄

birthday VARCHAR(10) DEFAULT NULL, ##出生日期

email VARCHAR(100) NOT NULL, ##电子邮件

edubackground CHAR(1) DEFAULT NULL, ##你的学历

mobile VARCHAR(11) DEFAULT NULL, ##手机号码

tel VARCHAR(15) DEFAULT NULL, ##联系电话

regtime BIGINT(13) DEFAULT NULL, ##注册时间存的是时间戳,Java的时间戳为13为所以用BIGINT,用FLOAT和DOUBLE都太大

regip VARCHAR(15) DEFAULT NULL, ##注册的ip地址,为十五位的

logtimes INT(10) DEFAULT 0, ##登录次数

CONSTRAINT PRIMARY KEY(id) ##这个表中id作为主键CONSTRAINT-UNIQUE-KEY(password)##为密码添加唯一性约束

) ENGINE=INNODB DEFAULT CHARSET=utf8;

##文件分类对应的按名称分类的表

DROP TABLE IF EXISTS cfms.namecategory;

CREATE TABLE IF NOT EXISTS cfms.namecategory(

id VARCHAR(36) NOT NULL, ##使用UUID,它是36位的

namecategory VARCHAR(100), ##文件的类型名称

description text, ##文件描述

user_id VARCHAR(36) NOT NULL, ##文件分类者

CONSTRAINT PRIMARY KEY(id),

CONSTRAINT namecategory_user_id_FK FOREIGN KEY(user_id) REFERENCES cfms.users(id) ON DELETE CASCADE ON UPDATE CASCADE

) ENGINE=INNODB DEFAULT CHARSET=utf8;

##文件分类对应的按文件类型分类的表

DROP TABLE IF EXISTS cfms.typecategory;

CREATE TABLE IF NOT EXISTS cfms.typecategory(

id VARCHAR(36) NOT NULL, ##使用UUID,它是36位的

typecategory VARCHAR(100), ##文件的类型名称

description text, ##文件描述

user_id VARCHAR(36) NOT NULL, ##文件分类者

CONSTRAINT PRIMARY KEY(id),

CONSTRAINT typecategory_user_id_FK FOREIGN KEY(user_id) REFERENCES cfms.users(id) ON DELETE CASCADE ON UPDATE CASCADE

) ENGINE=INNODB DEFAULT CHARSET=utf8;

##文件分类对应的按文件时间分类的表

DROP TABLE IF EXISTS cfms.timecategory;

CREATE TABLE IF NOT EXISTS cfms.timecategory(

id VARCHAR(36) NOT NULL, ##使用UUID,它是36位的

timecategory VARCHAR(100) NOT NULL, ##文件的类型名称

description text, ##文件描述

user_id VARCHAR(36) NOT NULL, ##文件分类者

CONSTRAINT PRIMARY KEY(id),

CONSTRAINT timecategory_user_id_FK FOREIGN KEY(user_id) REFERENCES cfms.users(id) ON DELETE CASCADE ON UPDATE CASCADE

) ENGINE=INNODB DEFAULT CHARSET=utf8;

##文件分类对应的按文件大小分类的表

DROP TABLE IF EXISTS cfms.sizecategroy;

CREATE TABLE IF NOT EXISTS cfms.sizecategroy(

id VARCHAR(36) NOT NULL, ##使用UUID,它是36位的

sizecategroy VARCHAR(100) NOT NULL, ##文件的类型名称

size_min VARCHAR(20) DEFAULT NULL, ##文件最小值

size_max VARCHAR(20) DEFAULT NULL, ##文件最大值

user_id VARCHAR(36) NOT NULL, ##文件分类者

CONSTRAINT PRIMARY KEY(id),

CONSTRAINT sizecategroy_user_id_FK FOREIGN KEY(user_id) REFERENCES cfms.users(id) ON DELETE CASCADE ON UPDATE CASCADE

) ENGINE=INNODB DEFAULT CHARSET=utf8;

##如果存在文件信息表,那么就删除,如果不存在就创建

DROP TABLE IF EXISTS cfms.files;

##如果不存在这个表,就重新创建

CREATE TABLE IF NOT EXISTS cfms.files(

id VARCHAR(36) NOT NULL, ##文件的主键值

name VARCHAR(250) NOT NULL, ##上传文件的名称,文件的uuid名

realname VARCHAR(250) NOT NULL, ##上传文件的真是名称

path VARCHAR(250) NOT NULL, ##文件的位置

uptime BIGINT(13), ##文件的上传时间

description text, ##文件的描述

size BIGINT(13) DEFAULT NULL, ##文件大小

keyword VARCHAR(100) DEFAULT NULL, ##文件关键字

user_id VARCHAR(36) NOT NULL, ##上传人

namecategory_id VARCHAR(36) NOT NULL,

typecategory_id VARCHAR(36) NOT NULL,

timecategory_id VARCHAR(36) NOT NULL,

CONSTRAINT PRIMARY KEY(id),

CONSTRAINT files_user_id_FK FOREIGN KEY(user_id) REFERENCES cfms.users(id) ON DELETE CASCADE ON UPDATE CASCADE,

CONSTRAINT files_namecategory_id_FK FOREIGN KEY(user_id) REFERENCES cfms.users(id) ON DELETE CASCADE ON UPDATE CASCADE,

CONSTRAINT files_typecategory_id_FK FOREIGN KEY(user_id) REFERENCES cfms.users(id) ON DELETE CASCADE ON UPDATE CASCADE,

CONSTRAINT files_timecategory_id_FK FOREIGN KEY(user_id) REFERENCES cfms.users(id) ON DELETE CASCADE ON UPDATE CASCADE

)ENGINE=INNODB DEFAULT CHARSET=utf8;

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

How to connect to remote database using Golang? How to connect to remote database using Golang? Jun 01, 2024 pm 08:31 PM

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.

How to use database callback functions in Golang? How to use database callback functions in Golang? Jun 03, 2024 pm 02:20 PM

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

What are the common applications of C++ templates in actual development? What are the common applications of C++ templates in actual development? Jun 05, 2024 pm 05:09 PM

C++ templates are widely used in actual development, including container class templates, algorithm templates, generic function templates and metaprogramming templates. For example, a generic sorting algorithm can sort arrays of different types of data.

How to save JSON data to database in Golang? How to save JSON data to database in Golang? Jun 06, 2024 am 11:24 AM

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

Comparison of C++ templates and generics? Comparison of C++ templates and generics? Jun 04, 2024 pm 04:24 PM

The difference between templates and generics in C++: Templates: defined at compile time, clearly typed, high efficiency, and small code size. Generics: runtime typing, abstract interface, provides flexibility, low efficiency.

See all articles