sql server2008中怎样用sql语句创建数据库和数据表
這是簡(jiǎn)單用代碼實(shí)現(xiàn)創(chuàng)建數(shù)據(jù)庫和數(shù)據(jù)表的sql語句,如下:
--調(diào)用系統(tǒng)數(shù)據(jù)庫--
use?master
go
/***防止你要?jiǎng)?chuàng)建的數(shù)據(jù)庫同名,先把它刪除掉****/
if Exists(select * from dbo.sysdatabases where name='TestDB')
begin
drop database TestDB
end
go
--創(chuàng)建數(shù)據(jù)庫TestDB----
create?databasse TestDB
on(
--數(shù)據(jù)庫的名稱--
name='testdb_mdf';
--設(shè)置數(shù)據(jù)庫存放的路徑--
filename='D:\SQL\DB\testdb_mdf.mdf';
)
log on(
name='testdb_ldf';
filename='D:\SQL\DB\testdb_ldf.ldf';
)
go
/***創(chuàng)建數(shù)據(jù)庫表*****/
---使用新創(chuàng)建的數(shù)據(jù)庫--
use?TestDB
go
--創(chuàng)建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
/***數(shù)據(jù)表的添加,查詢。修改、刪除的操作***/
--添加操作--
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'
總結(jié)
以上是生活随笔為你收集整理的sql server2008中怎样用sql语句创建数据库和数据表的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一个C实现的线程池(产品暂未运用)
- 下一篇: [转]经典SQL语句大全