摘要: View Code --建库createdatabase Studentonprimary( name='Student_db',--逻辑名 filename='D:\Student_db.mdf',--物理文件名 size=5mb,--初始化大小 maxsize=100,--最大值 filegrowth=15%--自动增长率)logon( name='Student_log', filename='D:\Student_log.ldf', size=2mb, filegrowth=1mb)--建库(带次要的数据库文件和多个日志文 阅读全文
posted @ 2012-06-24 10:42 ComBat 阅读(138) 评论(0) 推荐(0) 编辑
摘要: View Code --内联接:Whereselect s.SName as姓名,m.Score 成绩fromStudents s,StuMark mwhere s.ID=m.StuID--三表联接查询select s.SName 姓名,m.Score 成绩,c.CourseName 课程fromStudents s innerjoin stuMark mon s.ID=m.StuID innerjoin Courses con c.ID=m.CourseID--左外联接(如果左表存在的数据在右表中不存在以空的方式显示)select s.SName,m.Score fromStudents s 阅读全文
posted @ 2012-06-24 10:40 ComBat 阅读(109) 评论(0) 推荐(0) 编辑
摘要: View Code --求学生信息表:平均年龄、男生总数、最大,最小年龄、学生人数selectavg(Age)平均年龄,sum(convert(int,Sex))男生人数,max(age)最大年龄,min(age)最小年龄,count(*)学生人数from Students--分组统计每种课程的平均分--通常集合函数配合分组来统计数据的--在使用聚合函数时,所指定的列必须是聚合函数列、或--分组所指定的列select CourseID 课程编号,avg(Score)平均分,Sum(Score)总分,max(Score)最高分,min(Score)最低分,count(*)总人数from StuM 阅读全文
posted @ 2012-06-24 10:23 ComBat 阅读(132) 评论(0) 推荐(0) 编辑
摘要: View Code --系统函数--数据类型转换selectconvert(varchar(5),12345)selectconvert(int,'12345')--当前数据库用户selectcurrent_user--返回字符的字节数selectdatalength('中华人民共和国')--返回当前OS的计算机名selectHost_Name()--当前SQLSever的登录名selectsystem_user--根据指定数值获取当前数据的用户名selectuser_name(1)selectuser_name(2)selectuser_name(3)sele 阅读全文
posted @ 2012-06-24 10:21 ComBat 阅读(146) 评论(0) 推荐(0) 编辑
摘要: View Code --字符串函数:--返回指定字符串的索引,索引从开始,返回一个索引(int类型)selectcharindex('niit','Welcome to niit')selectcharindex('niit','Welcome to niit',8) --返回字符串的长度(返回字符个数非字节个数)selectlen('SQLServer2005编程') --将大写字符串转换为小写selectlower('SQLSERVER') --清除字符左边空格selectltrim(' 阅读全文
posted @ 2012-06-24 10:14 ComBat 阅读(102) 评论(0) 推荐(0) 编辑
摘要: View Code --向子表中插入外键列数据时,在主表中必须存在--否则将违反外键约束--如果在子表中存在关联主表中的数据,那么删除主表--会违反外键约束,无法删除,如果一定要删除主表中的--数据,应先将子表中的数据删除后再删除主表中的数据--delete语句删除表标识列不会重新编号deletefrom StuBak--truncate语句删除表会重新编号标识列--注:不能用于有外键约束的表truncatetable StuBak--指定列名查询表的信息select SName,Age,Address from Students--取别名查询表的信息select SName as姓名,Age 阅读全文
posted @ 2012-06-24 10:11 ComBat 阅读(169) 评论(0) 推荐(0) 编辑
摘要: View Code 可靠+准确=数据完整性实体完整性(主键):确保表中的数据是唯一的.域完整性(检查约束):确保表中的列值是一个有效的数据范围引用完整性(外键):保证关联表中不会出现无效的数据自定义完整性:我们可以通过用户自定义:规则、存储过程、触发器来保证数据的完整性--使用指定的数据库use Students--查询语句select:查询,*:所有列,from:从哪个表select*from Students--插入语句insertinto Students (SName,Age,Sex,SEmail,IdentityCard,Address)values('张三',20, 阅读全文
posted @ 2012-06-24 10:08 ComBat 阅读(126) 评论(0) 推荐(0) 编辑
摘要: View Code 查询:select *From 表名where 条件 select ...,...from 表名1,表名2where 插入:INSERT INTO 表名(学号,姓名,性别...................)Values (常量1,..............,常量n)INSERT INTO 表名select 列名1...............列名nfrom 表名1where条件 修改:UPDATE 表SET 列名1=表达式1; 列名2=表达式2;weher 条件 删除:DELETEfrom 表where 条件 阅读全文
posted @ 2012-06-21 16:24 ComBat 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 静态:select * from uselist(表) where 姓名=" 李四" ;动态:select * from uselist(表)where 姓名="+xm+"技巧:先写个原句列子aa,再把aa删除,加双引号,空格,然后"+xm+" 阅读全文
posted @ 2012-06-21 16:23 ComBat 阅读(147) 评论(0) 推荐(0) 编辑
摘要: View Code 数据库连接 八步SQL: using System.Date.SqlClient;ACCESS: using System.Date.OLeDb;======================== 1.创建连接对象SqlConnection 连接对象名称=new SqlConnection();OleDbConnection 连接对象名称=new OledbConnection();2.设置连接字符串连接对象名称.ConnectionString="...连接字符串..."; 字符串:Access:provider=microsoft.Jet... 阅读全文
posted @ 2012-06-21 16:22 ComBat 阅读(115) 评论(0) 推荐(0) 编辑