GIÁO TRÌNH MÔN CƠ SƠ DỮ LIỆU - Pdf 12

Tao CSDL bằng lệnh Create database

create database SalesDb
on
(
name= Salesdb_dat,
filename='d:\\data\salesdat.mdf',
size = 10mb,
maxsize = 50mb,
filegrowth=5%
)
log on
(
name= salesDb_log,
filename='d:\\data\salesdat.log',
size=5mb,
maxsize=25mb,
filegrowth=10%
)
Go

Thay đổi CSDL bằng lệnh Alter

alter database SalesDb
modify file (name='salesdb_log', size=10mb)

alter database SalesDb
add file (name=salesdb_data2, filename= 'd:\\data\salesdat2.mdf', size=5mb, maxsize=10mb)

Xóa CSDL bằng lệnh Drop


hiredate datetime not null,
positionid tinyint not null
)

Thay đổi bảng dữ liệu bằng lệnh Alter

alter table employees
add address2 nvarchar(16) not null
go

use salesDb1
alter table employees
drop column address2

alter table employees alter column address2 nvarchar(60)

Xóa bảng dữ liệu bằng lệnh Drop

Drop table employees

Xóa tất cả dữ liệu trong bảng bằng lệnh Truncate (không bật bẫy lỗi)

Truncate table employees

Tạo bảng tạm thời cục bộ (sẽ xóa khi kết thúc phiên làm việc)

create table #tamcucbo
( id int primary key,
cola varchar(30) not null,
colb varchar(30) not null

ID INT identity,
firstname varchar(30) not null,
Lastname varchar(30) not null )

insert table1 (firstname, Lastname ) values ('minh','thu')

set identity_insert table1 on
insert table1 (ID, firstname, Lastname ) values (99, 'minh','thu') chỉ định giá trị

Tạo ràng Check

alter table table1
add constraint qua_chk check (firstname != 'nga')

alter table table1
add constraint quat_chk check (id != 10)
go
Tạo rule và bind

create rule activeda as
@date between '01/01/70' and getdate()
go
sp_bindrule activeda, 'employees.DOB'

execute sp_unbindrule 'employees.DOB'

use salesDb1
Create table table2
(
manv INT not null,


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status