Home > Database > Mysql Tutorial > body text

SQL语句添加约束

WBOY
Release: 2016-06-07 17:44:13
Original
1785 people have browsed it

-----检查数据库是否存在------- use master go if exists(select*from sysdatabases where) drop database studentdb ------建数据库-------- create database studentdb on primary( name='student', filename='d:\data\student.mdf', size=15, maxsize=25

-----检查数据库是否存在-------

use master

go

if exists(select*from sysdatabases where)

drop database studentdb

------建数据库--------

create database studentdb

on primary(

name='student',

filename='d:\data\student.mdf',

size=15,

maxsize=25,

filegrowth=10%

)

log on (

name='student_log',

filename='d:\data\student_log.ldf',

size=20,

filegrowth=1

)

------修改数据库--------

alter database studentdb

modify file(

name='student_log',

maxsize=500

)

alter database studentdb

modify file(

name='student',

filegrowth=3

)

------创建表---------

use studentdb

go

if exists(select * from sysobjects where)

drop table t_class

create table t_class(

C_Id char(6) primary key not null,

C_Number varchar(30) unique not null,

C_Depart varchar(30) null

)

use studentdb

go

if exists(select * from sysobjects where)

drop table t_student

create table t_student(

S_Id char(6) primary key not null,

C_Id char(6) not null,

S_Name varchar(30) null,

S_Gender char(2) check(S_Gender in('男','女')) null,

S_Birthday datetime not null,

S_Nation char(10) null,

s_idcard varchar(18) check(len(s_idcard) in(15,18)) not null,

s_email varchar(50) check(s_email like '%@%') not null

)

-------向表中添加信息---------

insert into t_class values('01','软件技术班','计算机技术系')

insert into t_class values('02','网络技术班','计算机技术系')

insert into t_class values('03','会计班','经贸系')

insert into t_student (S_Id,C_Id,S_Name,S_Gender,S_Birthday,S_Nation) values ('001','01','李林','男','1998-8-9','汉')

insert into t_student (S_Id,C_Id,S_Name,S_Gender,S_Birthday,S_Nation) values ('002','01','黄莺','女','1980-11-2','满')

insert into t_student (S_Id,C_Id,S_Name,S_Gender,S_Birthday,S_Nation) values ('003','03','张华','男','1991-3-19','汉')

------修改信息---------

update t_student set S_Name='李大林' where S_Id=001

--------显示男同学的信息------

select * from t_student where S_Gender='男'

---------显示特定信息-----

select * from t_student where year(S_Birthday)=1998

--------删除特定信息-------

delete from t_student where C_Id='01'

select * from t_student

,香港虚拟主机,香港空间,香港虚拟主机
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template