mysql增加約束sql語句 SQL語句新增約束

2021-10-17 18:32:36 字數 2674 閱讀 8181

-----檢查資料庫是否存在------- 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

goif 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

goif 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

goif 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,香港虛擬主機,香港空間,香港虛擬主機

mysql增加約束sql語句 sql語句新增約束

sql語句新增約束 主鍵約束 primary key constraint 要求主鍵列的資料唯一,並且不允許為空。唯一約束 unique constraint 要求該列唯一,允許為空,但只能出現乙個空值。檢查約束 check constraint 某列取值範圍限制 格式限制等,如有關年齡的約束。預設...

MySQL增加欄位SQL語句

使用alter table向mysql資料庫的表中新增字段,向buildbaseinfo中新增字段 alter table table name add column column name varchar 100 default null comment 新加字段 after old column...

增加約束的語句

增加約束的語句2008 07 17 16 34 新增主鍵約束 alter table 表名 add constraint 約束名 primary key 主鍵 新增唯一約束 alter table 表名 add constraint 約束名 unique 字段 新增預設約束 alter table ...