資料庫操縱語言筆記

2021-10-09 19:28:53 字數 3211 閱讀 9520

剛在資料庫課上學了資料庫操作語言,對於英語不好的我來說又要記不少單詞,趁著這次作業,把剛學的一些語法記一下

注:1.文中路徑和檔名請自行替換

2.報錯大多是因為一些細微之差,比如冒號引號的缺失,請多多注意

create

database test1 #新建資料的名字為test1

on #以下是指定資料庫檔案和檔案組屬性

primary #主檔案組檔案屬性

(name

='test1_dat1'

, #檔名

filename

='e:\sql lianxi\test1.mdf'

, #檔案路徑,最後檔案格式為.mdf

size

=20mb, #檔案初始大小

maxsize

=60mb, #檔案最大大小,不限制則填unlimited

filegrowth

=5mb #檔案的增長增量),

filegroup test1_group1 #其他檔案組名

(name

='test1_dat2'

, #檔名

filename

='e:\sql lianxi\test1.ndf'

, #檔案路徑,最後檔案格式為.ndf

size

=10mb,

maxsize

=unlimited

,filegrowth=10

%)logon #日誌檔案

(name

='test1_log'

,filename

='e:\sql lianxi\test1_log.ldf'

,size

=50mb,

maxsize

=100mb,

filegrowth

=10mb

)

// 

alter

database test1 #需要更改的資料庫名字test1

addfilegroup test1_group2 #指定要增加的資料檔案

goalter

database test1

addfile #增加檔案

(name

='test1_dat3'

, #檔名

filename

='d:\data\store3add.ndf'

, #檔案路徑

size

=2mb, #檔案初始大小

maxsize

=10mb, #檔案最大大小

filegrowth

=1mb #檔案增量大小)to

filegroup test1_group2 #指定該檔案是屬於哪個檔案組的

alter

database test1

modify

file #指定要更改的檔案屬性

(name

= test1_dat3,

maxsize

=100mb #將test_dat3檔案的最大大小改為100m

)alter

database test1

remove

file test1_dat3 #刪除檔案test1_dat3

alter

database test1

remove

filegroup test1_group2 #刪除檔案組test1_group2

alter

database test1

modify

name

= test2 #重新命名資料庫test1名字為test2

drop

database test1 #刪除資料庫test1

create table employee   #建立employee表

( emplid char(4) not null primary key, #列名,資料型別,是否為空,主鍵

emplname char(8) not null,

*** char(2) not null,

birthday date not null,

address char(20) null,

wages money not null,

deptid char(4) not null

)go

alter table goods2 add remarks char(10)     #增加列remarks,資料型別為char(10)

alter table goods2 alter column remarks char(12) #修改remarks列的資料型別為char(12)

alter table goods2 drop column remarks #刪除remarks列

drop table table_name

insert into consumer values 

(1,'劉宇豪','男','仁厚街21號')

由於插入的資料報含各列的值並按表中各列的順序列出這些值,所以省略列名表(colume_list)。

insert into consumer

(consumerid, name, ***, address) values (1,'劉宇豪','男','仁厚街21號')

本例與上例功能完全相同,但本例顯式列出列名表(colume_list),顯示列表可用於插入值少於列的個數或插入與列的順序不同的資料。

【例】 在consumer表中將consumerid為1的客戶的address修改為』沙灣路35號』。

update consumer   #指定修改的表

set address ='沙灣路35號' #先寫修改內容

where consumerid=1 #再指定是修改哪個

【例】刪除consumer表中客戶號為1的記錄。

delete consumer  #刪除consumer表中的內容

where consumerid=1

#若沒有指定修改內容,則刪除所有行

資料庫操縱語言DML

資料庫操縱語言dml dml 有三條語句 insert update delete.一 insert 插入資料 1 插入一條資料 insert into 表名 列名 values 值列表 insert into stuinfo stuname,stuno,stu stuage,stuaddress ...

DML 資料庫操縱語言

增 插入 1,張三,18 注意 字串和日期時間 必須加上 插入完整記錄 insert into student values 1,張三 18 插入部分記錄 insert into student name,age values 張三 18 插入多條完整記錄 insert into student v...

mysql資料庫操縱語言

dml語言增刪改查 插入insert into 表名 列名 values 值列表 例項 insert into students sname,saddress,sgrade,semail,s values 張青裁 上海松江 6,zqc sohu.com 0 注意事項1 每次插入一行資料,不能只插入半...