- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
sqlserver2008数据库操作代码
1 新建数据库 create database hhc;2 新建数据库里的一张表use hhc;create table hy(name varchar(10),age varchar(10));3 查看数据库表结构,不需要制定数据库 sp_help hy4 修改表的数据类型use hhc;alter table lxalter column name varchar(40);5 更改表中的字段的数目向表中添加字段use hhc;alter table hyadd score varchar(20);删除表中的字段use hhc;alter table hydrop column score;6 给表中的字段改名sp_rename hy.name,username;7 给数据表改名sp_rename hy,hanyan;8 删除数据表use hhc;drop table hanyan;9 查看数据库表的信息select * from lx10 向表中插入数据默认给所有的列添加数据use hhc;insert into lxvalues(还魂草,18);给特定的列添加数据use hhc;insert into lx(name)values(huanhuncao);一次添加多条数据use hhc;insert into lx(name,age)values(lx,21),(李行,22);11 复制一个表的数据到另外一个表use hhc;insert into hy(name1,age1)select name,agefrom lx;12 修改表中的数据,把年龄为21的这一行的姓名改了,不加条件就是这一列的所有数据全部修改use hhc;update lxset name=lixingwhere age=21;修改前n条数据use hhc;update top(2) hyset name1=修改的13 从表中删除数据,不加条件就是全部删除use hhc;delete from lxwhere age=21删除前n条数据use hhc;delete top(2) hy14 右键数据库新建表,在新建表里定义表的数据类型和类型名,定义完了后,点击菜单栏下的保存按钮,保存,输入表名。右键新建的表,编辑前200行,即可向表里插入数据15 查询表中的所有列use hhc;select * from test查询表中的指定列use hhc;select id,name from test;查询表中的指定列的指定行use hhc;select id,name from testwhere id=2;给查询的列换个别名use hhc;select id as 卡号,name as 姓名 from testwhere id=2;查询表中的前n条数据use hhc;select top(2) id as 卡号,name as 姓名 from test16 对某列按照降序desc 升序asc排列use hhc;select id as 卡号,name as 姓名 from testorder by id desc;use hhc;select id as 卡号,name as 姓名 from testorder by id asc;17 对于某列为空的,查询条件不是列名=‘’,而是列名is ‘’use hhc;select id,name from testwhere age is null;18 模糊查询use hhc;select * from testwhere id like %10%查询id中含有10的,%表示0到多个字符,%10%表示10的前面有0或者以上的字符,后面也有use hhc;select * from testwhere id like _10%_表示一个字符use hhc;select * from testwhere id like [123]条件里的字符如果没用%和_就表示字符写的第一个就是表里的第一个,【123】表示id列的第一个字母可以是123中的任何一个不包含用not likeuse hhc;select * from testwhere id not like [123]19 查询某一范围用in,只是表示id里1或者3的,不是1到3use hhc;select * from testwhere id in (1,3)20 多个条件用anduse hhc;select * from testwhere id in (1,3) and age=2121 MAX,MIN,AVG,SUM,最大,最小,平均,和use hhc;select MAX(id) from test;22 求某个条件的行数use hhc;select C
文档评论(0)