Mysql数据库,表,字符集,主外键等创建的sql模板_MySQL
##如果存在同名的数据库,删除此同名的数据库。 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; |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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

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())

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.

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.

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.

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.

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.

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.
