①資料庫的建立:
create
database
[student]
--資料庫名
containment = none
onprimary
( name = n'student'
,--主資料檔案的邏輯名稱
filename = n'c:\datalibrary\student.mdf'
,--主資料檔案的物理名稱
size =
5120kb ,
--主資料檔案的初始大小
maxsize = unlimited,
--主資料檔案增長的最大值
filegrowth =
1024kb –主資料檔案的增長率
) log on
--建立日誌檔案
( name = n'student_log'
,--日誌檔案的邏輯名稱
filename = n'c:\datalibrary\student_log.ldf'
,--日誌檔案的物理名稱
size =
1024kb ,
--日誌檔案的初始大小
maxsize =
2048gb ,
--日誌檔案的增長的最大值
filegrowth =10%
--日誌檔案的增長率)go
```sql
②表的建立:
create
table class --class表的建立
( c_name varchar(10
)not
null
, c_number char(8
)not
null
primary
key,
dep_number char(8
)not
null, )
create
table department --學院表的建立
( dep_number char(8
)not
null
primary
key,
dep_name nvarchar(10)
notnull )
create
table grade --成績表的建立
( g_number char(10
)not
null
, s_number char(10
)not
null
, math int
notnull
, english int
notnull
, c+
+int
notnull
,sql
intnot
null,)
create
table login --賬號表的建立
( s_number char(10
)not
null
, code varchar(12
)not
null
)create
table student --學生表的建立
( s_number char(10
)not
null
primary
key,
s_name nvarchar(8)
notnull
, *** bit
notnull
, birthday datetime
notnull
, native nchar(20
)not
null
, c_number char(8
)not
null
, dep_number char(8
)not
null
, tel char(11
)not
null
, address nvarchar(20)
null
, zipcode char(8
)null
, email varchar(20
)null
, note nvarchar(
100)
null
)③定義表之間的關係:
④增刪改查:
select
*from student
insert
into student(s_number, s_name, ***, birthday, native, dep_number, tel)
--增加資料
values
(『001』,』廖永強』,1,『1999-10
-25』,『湖南』,『001』,『18373727165』)
insert
into student(s_name)
values
(『劉榮燊』),(『王佳磊『),(』閆成偉『)
結果如圖:
update student set dep_number=』001』 --為所有行的指定列進行修改
update student set dep_number=』001』
where 表示式 --為指定行進行修改列
delete students where 表示式 --按要求刪除行
truncate
table grade --清空
select
*from student as stu --為表起別名
select s_name , s_number from stu --查詢指定列
select
top3
*from students
select
top10
percent
*from student --篩選前多少行
order
by s_number desc
/asc
--排序由大到小/由小到大
order
by s_number desc,dep_number asc
/*多套排序規則,先排前面的,前面相同在按後面規則排*/
select
distinct dep_number from student --消除重複行
select s_name from student
where s_number=
1--按規則查詢
select
*from student
where sid between
3and
8--連續區間查詢
where sid>
3and sid<
8select
*from student
where dep_number in(1
,3)--非連續查詢
where dep_number=
1or dep_number=
3select
*from student
where sid between
3and
8and cid=
1select
*from student
where s_name like 『張%
%』 --模糊查詢
select
*from student
where s_name like 『黃_』
select
*from studentinfo
where s_phone like 『1[^
579]
%』
編寫資料庫指令碼
發表日期 2000 年 1 月 10 日 我在 if it moves,script it 英文 這篇文章中曾談到,如何使用 windows script host wsh windows 指令碼主機 管理 windows 和 windows 中的應用程式。文中的大多數示例都是基於管理 window...
資料庫公升級指令碼
工作流資料庫指令碼公升級技術小結 1.修改字段長度或型別 只能加大,不能減小 修改型別時得注意資料的可轉化性 mysql alter table 表名 modify column 欄位名 字段型別定義 oracle,修改型別時所改字段的資料必須為空 alter table 表名 modify 欄位名...
資料庫初始指令碼
新建查詢,將下面的指令碼執行 create database gamedb gouse gamedb gocreate table users id varchar 12 name varchar 20 pwd varchar 15 note varchar 50 photo image const...