--第一章上机 --创建BBS数据库 create database 库名 on primary//建数据库文件 ( name库名_mdf, filename='路径', size=初始大小, maxsize=unlimited-表示无限制增长, filegrowth=15%-按百分比来比较 ) log on建事务日志文件 ( name=BBS_ldf, filename='d:\
--第一章上机
--创建BBS数据库
create database 库名
on primary//建数据库文件
(
name库名_mdf,
filename='路径',
size=初始大小,
maxsize=unlimited-表示无限制增长,
filegrowth=15%-按百分比来比较
)
log on建事务日志文件
(
name=BBS_ldf,
filename='d:\BBSdatabase\BBS.ldf',
size=3mb,
maxsize=30mb,
filegrowth=5%
)
--删除数据库
drop database 库名
--第二章上机
--创建表的结构
use 库名
create table 新建表名
(
列名 int identity(1,1) not null primary key, --标识列、自动增长
列名 varchar (16) not null default('888888'), --不为空、默认值
列名 datetime, --日期用datetime表示
列名 varchar(13) not null unique check (len(列名)=15 or len(列名)=18),
列名 varchar(50) not null check(列名 Like '表达式' or len(列名)=11)
列名 varchar(20) not null foreign key references 引用主键表(对应的列名)
)
--创建已有的表的约束
Alter table 存在的表名
Add constraint 约束名称 check(len(UPassword)>=6),
constraint CK_id check(UEmail like '%@%')
--建立已有表之间的主外键关系
Alter table 表名
add constraint 约束名称 foreign key (子表列名) references 主表名称(对应的主表列名),
constraint FK_TUID foreign key (TUID) references BBSUsers(UID)
……
--创建数据库关系图
--点击数据关系图,右键创建新的关系图,按CTRL选择全部的表即可
--向表中插入数据方法一用insert向表中插入
insert into 表名(列名1,列名2,列名3,……)
values('对应列名1的值','对应列名2的值','对应列名3的值',……)
--向表中插入数据方法二用select来插入
insert into 表名(列名 1,列名2,列名3,……)
select '对应列名1的值','对应列名2的值','对应列名3的值',…… union //插入的第一行数据
select '对应列名2的值','对应列名2的值','对应列名3的值',…… union //插入的最后一行数据
…… union
select '对应列名N的值','对应列名N的值','对应列名N的值',…… 切记住最后一行没有union
--执行更新
update set [where ] //可以紧随多个数据列的更新值
--delete删除数据
delete from [where ]
--Truncae Table 删除数据 用来删除所有表中的所有行
Truncate table 表名

mySqlStringTypesimpactStorageAndPerformanCeaseAsfollows:1)长度,始终使用theSamestoragespace,whatcanbefasterbutlessspace-felfficity.2)varCharisvariable varcharisvariable length,morespace-morespace-morespace-effficitybuteftife buteftife butfority butfority textifforlyslower.3)

mySqlStringTypesIncludeVarChar,文本,char,enum和set.1)varCharisVersAtileForvariable-lengthStringStringSuptOptoPeptoPepecifientlimit.2)textisidealforlargetStortStorStoverStorextorewiteWithoutAdefinedLengthl.3)charlisfixed-Length

MySQLoffersvariousstringdatatypes:1)CHARforfixed-lengthstrings,2)VARCHARforvariable-lengthtext,3)BINARYandVARBINARYforbinarydata,4)BLOBandTEXTforlargedata,and5)ENUMandSETforcontrolledinput.Eachtypehasspecificusesandperformancecharacteristics,sochoose

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

toadduserInmysqleffectection andsecrely,theTheSepsps:1)USEtheCreateuserStattoDaneWuser,指定thehostandastrongpassword.2)GrantNectalRevileSaryPrivilegesSustate,usiveleanttatement,AdheringTotheTeprinciplelastPrevilegege.3)

toaddanewuserwithcomplexpermissionsinmysql,loldtheSesteps:1)创建eTheEserWithCreateuser'newuser'newuser'@''localhost'Indedify'pa ssword';。2)GrantreadAccesstoalltablesin'mydatabase'withGrantSelectOnMyDatabase.to'newuser'@'localhost';。3)GrantWriteAccessto'

MySQL中的字符串数据类型包括CHAR、VARCHAR、BINARY、VARBINARY、BLOB、TEXT,排序规则(Collations)决定了字符串的比较和排序方式。1.CHAR适合固定长度字符串,VARCHAR适合可变长度字符串。2.BINARY和VARBINARY用于二进制数据,BLOB和TEXT用于大对象数据。3.排序规则如utf8mb4_unicode_ci忽略大小写,适合用户名;utf8mb4_bin区分大小写,适合需要精确比较的字段。

最佳的MySQLVARCHAR列长度选择应基于数据分析、考虑未来增长、评估性能影响及字符集需求。1)分析数据以确定典型长度;2)预留未来扩展空间;3)注意大长度对性能的影响;4)考虑字符集对存储的影响。通过这些步骤,可以优化数据库的效率和扩展性。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

SublimeText3汉化版
中文版,非常好用