基础3sql server数据库5 Sql语句简单理解就是用于操作的_第1页
基础3sql server数据库5 Sql语句简单理解就是用于操作的_第2页
基础3sql server数据库5 Sql语句简单理解就是用于操作的_第3页
基础3sql server数据库5 Sql语句简单理解就是用于操作的_第4页
基础3sql server数据库5 Sql语句简单理解就是用于操作的_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Dns解析系Ip地址\MysqlSqlSQLSql o’’World!’ 数据库对象(表名,库中名,列名可以用[]括起来,1)防止和关键字2)对象名之间有空DroptableDropdatabase要删除的数据库名修改表语法:altertable表名……修改表结构时,一定要注意会不会原来表中的数据有--altertable表名dropcolumn要删除的列名;altertabletblStudentdropcolumntSCla --altertable表名addaltertabletblStudentadd --altertable表名altercolumnaltertabletblStudentaltercolumn intnot--altertable表名addconstraint主键约束名primarykey(主键列)altertableTblStudentaddconstraintPK_TblStudent_tSIdPrimaryaltertabletblStudentdropconstraint对数据库,最常用的就是增 删 改 查查:语法 Select*from表 显示表中的所有数useselect*fromStudent--select后的*,SELECTstuId,stuAddress,'我也不知道asnewColfromselectstuName,stuAddress,stuName+stuAddressas'+地址'fromselecttestId+stuIdfromSELECTstuIdas学号],stuName,stuAddressfromSELECTstuIdas[学号],stuName,stuAddressfromSELECTstuIdas[学号],stuName,'地址'=stuAddressfrom--要求:两个结果集的列数必须相同2两个结果集对应列的数据类型相同select*fromScoreselectstuId,testBasetestName,testDatefromscorewherestuId=1union--合并结果集selectstuId,testBase,testName,testDatefromscorewhereselectcol1from selectCol2as'aaa'fromtblTest2--语法:insertinto表名(列名,列名 insertintoTblClass(tClassName,tClassDesc)insertintoTblClass(tClassName) select*from--insertintoTblClass(tClassDescvalues('这里是描述insertintoTblClassvalues('未命名班','还没想好班名--SETIDENTITY_INSERT表名setidentity_inserttblclassinsertintoTblClass(tCla setidentity_inserttblclassOff不允许手动设置自动增涨列了insertintoTblClass(tClassName,tClassDesc)select*fromTblClass--语法:insertinto表名[(列名,列 insertintoTblClass(tClassName,tClassDesc)select'','我喜欢的地方'unionselect'班','明天开unionselect'','都是'unionselect'杨','班'insertintoselecttSAddress,tSPhonefromTblStudentselect*fromTblClassinsertintoselecttSGender,tSAddress,tSPhone,tSAge,tSBirthday,tSCardId,tSCla fromTblStudentselect*fromTblStudent--select*from表名在列名后加上into新表名注意:新表必须不存在select*intonewClassAfromTblClassselecttClassName,tClassDescintonewClassColsfromTblClassselect*fromnewClasscolsselect*fromselecttClassName,tClassDescintonewClassWherefromTblClasswheretCla select*fromupdate表名set要更新的列名=新值[,要更新的列名=新值[where表达式]useTestDataBaseselect*intonewStudentfromStudentselect*fromnewStudentupdatenewStudentset updatenewStudentsetstuIsDel=1,cla select*fromnewStudentupdaTEnewStudentset select*fromupdateScoresettestBase=testBase-1select*fromscoreselect*fromScorewhereupdateScoresettestBase=testBase+5wherestuId=1select*fromScorewherestuId=1delete--删除的语法deletefrom表名select*fromnewStudentdeletefromnewStudentselect*fromselect*fromnewStudentwherecla =1andstu deletefromnewStudentwherecla =1andstu --语法truncatetableselect*fromnewStudenttruncatetable约束是保证数据库完数据为完整性说白了就是保证数据库中的比如:,只有男和女 唯一约束:select*frominsertintoTblClassvalues('期','12-28')deletefromTblClasswheretCla --语法altertable表名addconstraint约束名约束的关键字(列名)...altertabletblclassaddconstraintUQ_tblClass_tClassDescUnique(tClassDesc)select*fromTblClassinsertintoTblClass(tClassDesc)values('ttt12-28altertabletblClassaddconstraintDF_TblClass_tClassDescDefault(N'')fortClassDescinsertintoTblClass(tClassName)values('测试就业班')updateTblClasssettclassmaxstudent=50select*fromTblClassinsertintoTblClassvalues('11',' selectLEN(tclassName),tclassNamefromTblClassaltertabletblClassaddconstraintCK_

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论