sql server2008中怎样用sql语句创建数据库和数据表
這是簡單用代碼實現創建數據庫和數據表的sql語句,如下:
--調用系統數據庫--
use?master
go
/***防止你要創建的數據庫同名,先把它刪除掉****/
if Exists(select * from dbo.sysdatabases where name='TestDB')
begin
drop database TestDB
end
go
--創建數據庫TestDB----
create?databasse TestDB
on(
--數據庫的名稱--
name='testdb_mdf';
--設置數據庫存放的路徑--
filename='D:\SQL\DB\testdb_mdf.mdf';
)
log on(
name='testdb_ldf';
filename='D:\SQL\DB\testdb_ldf.ldf';
)
go
/***創建數據庫表*****/
---使用新創建的數據庫--
use?TestDB
go
--創建Student表--
create table Student(
--identity(1,1)自增,primary key是主鍵--
stuId int identity(1,1) primary key,??
stuName varchar(20) not null,
stuAge int not null,
stuSex varchar(2) not null,
Address varchar(50) not null
)
go
/***數據表的添加,查詢。修改、刪除的操作***/
--添加操作--
insert?into Student? values('張三',23,'男',‘廣州’);
insert?into Student(stuName,stuAge,stuSex,Address) values('李四',21,'女',‘海南’);
--查詢操作--
select * from Student;
select * from Student where stuId='2';
--修改操作--
update Student set stuAge=27 where stuId='1';
--刪除操作--
delete from Student where stuId='2'
總結
以上是生活随笔為你收集整理的sql server2008中怎样用sql语句创建数据库和数据表的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一个C实现的线程池(产品暂未运用)
- 下一篇: DexClassLoader的使用