zoukankan      html  css  js  c++  java
  • sql server 常用脚本之table操作

    use Study
    go
     
    if exists (select * from sysobjects where name='Student')--判断是否存在此表
        drop table Student
    go
    create table Student
    (
        id int identity(1,1) primary key,--id自动编号,并设为主键
        [name] nvarchar(20) not null,
        sex char(2) not null,
        birthday datetime default GETDATE(),
    phone char(11) not null,
        remark
    text,
        tId
    int not null,
       age
    as datediff(yyyy,birthday,getdate())--计算列。 )
    go
     
    if exists (select * from sysobjects where name='Team')     drop table Team go create table Team (     id int identity(1,1) primary key,     tName varchar(20) not null,     captainId int ) go   alter table Student add     constraint CH_sex check(sex in ('','')),--检查约束,性别必须是男或女     constraint CH_birthday check(birthday between '1950-01-01' and '1988-12-31'),     constraint CH_phone check(len(phone)=11),     constraint FK_tId foreign key(tId) references Team(id),--外键约束,引用Team表的主键     constraint DF_remark default('请在这里填写备注') for remark--默认约束, go   alter table Team add     constraint UK_captainId unique(captainId)--唯一约束 go   insert into Team values('第一组',1) insert into Team values('第二组',2) insert into Team values('第三组',3) insert into Team values('第四组',4) insert into Team values('第五组',5)   insert into Student values('张三','','1982-6-9','23456789451','来自天津',1) insert into Student values('李四','','1987-6-9','78945678945','安徽',4) insert into Student values('王五','','1982-6-9','65987845651','大连',3) insert into Student values('赵六','','1981-6-9','25487965423','湖南',5) insert into Student(name,sex,birthday,phone,tId) values('江七','','1984-6-9','25487965423',5)   select * from Team select * from Student   if exists (select * from sysobjects where name='teacher')     drop table teacher go     create table teacher (     id int identity (1,1) primary key,     name varchar(20),     address varchar(20) )   go   insert into teacher values('zhang','hubei') insert into teacher values('wang','hubei') insert into teacher values('li','hubei') insert into teacher values('chen','hunan') insert into teacher values('zhao','hunan') insert into teacher values('tian','guangdong') insert into teacher values('ma','guangdong') insert into teacher values('chang','tianjin') insert into teacher values('liang','beijing')
  • 相关阅读:
    Pro ASP.NET MVC 3 Framework 译文(一)
    Pro ASP.NET MVC 3 Framework译文(二)第二章:准备工作
    新写的JS无限树状列表
    Windows phone中如何使用丰富的弹出框提示
    Windows phone中用RichTextBox实现文字、图片混合排版
    Windows phone中如何添加页面跳转动画
    java虚拟机JVM内存不够,OutOfMemorry Error
    Oracle常用的导入导出命令
    Oracle经常断开连接
    安装oracle后,很卡
  • 原文地址:https://www.cnblogs.com/yuchsheng/p/13200947.html
Copyright © 2011-2022 走看看