加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

SQL Server 数据库基础编程

发布时间:2020-12-12 09:03:31 所属栏目:MsSql教程 来源:网络整理
导读:? Go批处理语句 ???? 用于同时执行多个语句 ? ? 使用、切换数据库 master ? ? 创建、删除数据库 方法1、 ( ( * sys.databases name = )) testHome testHome ( , ( ,monospace; direction: ltr; border-top-style: none; color: black; font-size: 10pt; bord

? Go批处理语句

???? 用于同时执行多个语句

?

? 使用、切换数据库

master





?

? 创建、删除数据库

方法1、

 ( ( *  sys.databases  name = ))
  testHome

  testHome
(
,
    
(
,monospace; direction: ltr; border-top-style: none; color: black; font-size: 10pt; border-left-style: none; overflow: visible; padding-top: 0px">    filename = 





?

方法2(设置文件大小)、

( ( * sys.databases name = ))
  testHome

  (    
,--主数据文件的逻辑名
,--主数据文件的物理名
 = 3MB,--主数据文件的初始大小
 (
,
 = 1MB,monospace; direction: ltr; border-top-style: none; color: black; font-size: 10pt; border-left-style: none; overflow: visible; padding-top: 0px">    fileGrowth = 1MB





?

方法3(设置次数据文件)、

,--主数据文件的逻辑名
,--主数据文件的物理名
 = 2MB,--主数据文件的初始大小
 (
,monospace; direction: ltr; border-top-style: none; color: black; font-size: 10pt; border-left-style: none; overflow: visible; padding-top: 0px">    fileName = ,monospace; direction: ltr; border-top-style: none; color: black; font-size: 10pt; border-left-style: none; overflow: visible; padding-top: 0px">

?

? 基本数据类型

精确数字类型

类型

?

近似数字类型

类型

?

日期时间类型

类型

?

字符串类型

类型

?

Unicode字符串类型

类型

?

二进制字符串类型

类型

?

? 判断表或其他对象及列是否存在

 ( ( *  sys.objects  name = ))
 ;
 ( ( *  sys.objects  object_id = object_id()))
 ;
 (object_id(,)   )
 ( ( *  sys.columns  object_id = object_id()  name = ))
  student   idCard
 ( ( *  information_schema.columns  table_name =   column_name = ))
  student   tel




?

? 创建、删除表

  classes
  classes(
   (1,2),monospace; direction: ltr; border-top-style: none; color: black; font-size: 10pt; border-left-style: none; overflow: visible; padding-top: 0px">    name (22)  ,monospace; direction: ltr; border-top-style: none; color: black; font-size: 10pt; border-left-style: none; overflow: visible; padding-top: 0px">    createDate datetime  getDate()
  student
  student(
 (1,1)  ,monospace; direction: ltr; border-top-style: none; color: black; font-size: 10pt; border-left-style: none; overflow: visible; padding-top: 0px">    name (20),monospace; direction: ltr; border-top-style: none; color: black; font-size: 10pt; border-left-style: none; overflow: visible; padding-top: 0px">    age ,monospace; direction: ltr; border-top-style: none; color: black; font-size: 10pt; border-left-style: none; overflow: visible; padding-top: 0px">    sex ,monospace; direction: ltr; border-top-style: none; color: black; font-size: 10pt; border-left-style: none; overflow: visible; padding-top: 0px">    cid 




? 给表添加字段、修改字段、删除字段

  student  address (50)  ;
  student   address (20);
  student   number;
  student 
 address (22),monospace; direction: ltr; border-top-style: none; color: black; font-size: 10pt; border-left-style: none; overflow: visible; padding-top: 0px">    tel (11),monospace; direction: ltr; border-top-style: none; color: black; font-size: 10pt; border-left-style: none; overflow: visible; padding-top: 0px">    idCard (3);




? 添加、删除约束

  student 
 number (20)   no_uk ;  
  student  
  pk_id  (id);  
  student
  fk_cid   (cid)  classes(id)
  name_uk (name);
  student     
  check_age  (age > 1);
  student
  ck_age  (age >= 15  age <= 50)
  sex_def  1  sex;
 createDate smalldatetime 
 createDate_def  getDate()  ;

  student    

   id  ,monospace; direction: ltr; border-top-style: none; color: black; font-size: 10pt; border-left-style: none; overflow: visible; padding-top: 0px">    
     
 uNumber  classes(number),monospace; direction: ltr; border-top-style: none; color: black; font-size: 10pt; border-left-style: none; overflow: visible; padding-top: 0px">    
(3,3)  
 createDate  2010-6-1  
 
  student    no_uk;

?

? 插入数据

classes(name) ();
 classes (,);
 classes(name) ();
 classes (,);
 student (,22,1,1);
 student (,25,1);
 student (,24,3);
 student (,23,3);
 student (,21,5);
 student (,28,5);
 student (,,monospace; direction: ltr; border-top-style: none; color: black; font-size: 10pt; border-left-style: none; overflow: visible; padding-top: 0px">insert  student (,monospace; direction: ltr; border-top-style: none; color: black; font-size: 10pt; border-left-style: none; overflow: visible; padding-top: 0px">insert  student 
  name,age,sex,cid 
 student 
 name = ;
 student
 ,5 
 ,3 
 ,3 
 ,26,5;

?

? 查询、修改、删除数据

 *  classes;
 *  student;
 id, name,cid  student 
 name = ;
 *,( (age)  student)  student 
 student  name = ,sex = 1  id = 1;
  student  id = 1;

?

? 备份数据、表

 *  stu  student;
 *  stu1  ( *  stu) t;
 *  stu;
 *  stu1;

?

? 利用存储过程查询表信息

 sp_help student;
 sp_help classes;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读