欢迎访问 生活随笔!

凯发k8官方网

当前位置: 凯发k8官方网 > 运维知识 > 数据库 >内容正文

数据库

sql server 2005学习笔记 -凯发k8官方网

发布时间:2024/10/8 数据库 0 豆豆
凯发k8官方网 收集整理的这篇文章主要介绍了 sql server 2005学习笔记 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

1.消除重复的行

  select distinct 字段名 from 表名

2.数据插入

  insert [into] table_name [column_list] values (data_values)

3.数据删除

    a.   delete 表名 where search_condition (注:没有from)

    b.  truncate table table_name (删除表中所有行)

            truncate table  功能上与不带where的delete语句相同,二者均可删除全部行。

           二者的区别:

               1.truncate table 的速度快,且使用的系统和事务日志资源少。

               2.truncate table 删除表中的所有行,但表结构及列、约束、索引等保持不变

               3.truncate table 新行标识所用的计数值重围为该列的种子,而delete保留标识计数值

  c.drop table 删除表定义及其数据(即把整个表都删了)、

4.数据修改

     updata table_name set column [where condition]

5.使用函数

   insert orderform values (1,2,50,getdate(),1)   //getdate()函数:得到当前时间

6.使用公式

    在出现的位置上,可以使用公式对查询结果进行计算

     示例:select book.book_name,'总金额:',(book.price*orderform.book_numer) from orderform,book where orderform.book_id=book.book_id

 7.数据库的操作语句

      a.创建数据库:(ms-help://ms.sqlcc.v9/ms.sqlsvr.v9.zh-chs/tsqlref9/html/29ddac46-7a0f-4151-bd94-75c1908c89f8.htm )

          creater database database_name              

                       on-----指定数据文件

                       og on -----指定事务日志文件

     b.修改数据库

          alter database

     c.删除数据库

               drop database database_name     

     d.使用数据库

               use database database_name

     e.查看sql server 服务器上包含哪些数据库,可以使用sp_helpdb存储过程,使用方式为:exec sp_helpdb

 8.表的操作语句

      a.    create table table_name

     (

               column_name data_type [null | not null] [primary | unique]

                                        [foreign key [(column_name)]]

                                        references ref_table[(ref_column)]

           [column_name2 data_type......]

       ......

     )

--------------------------

     primary key 设置字段为主键

     unique 指定字段具有唯一性

 

     b. 与其他表建立关联

      示例:

       create table author(

          author_id int not null primary key,

          author_name char(8) not null,

          address char(50) null

)

       create table book(

          book_id int not null primary key,

          book_name char(8) not null,

          author_id int foreign key references authors(author_id)

      --              类型            关键字                        表名    引用的字段

)

      c.修改表       alter table table_name

         add [column_name data_type]

                [primary key | constrain]

                [foreign key (column_name)

         references ref_table_name (ref_column_name) ]

           drop [constraint] constraint_name | column column_name

-----------------------------------------------------------------------------

  注释:

          a.  add 增加字段

          b.  drop 删除限制或者字段 。constraint :表示删除限制,column 表示删除字段

     d.删除关联和表

       drop table table_name

 

 

 

 

 

 

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/291099657/archive/2009/03/26/1422746.html

总结

以上是凯发k8官方网为你收集整理的sql server 2005学习笔记的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得凯发k8官方网网站内容还不错,欢迎将凯发k8官方网推荐给好友。

网站地图