Create DATABASE HappyRelaxDB on( NAME='HappyRelaxDB',FILENAME='D:\Sunny_Project\HappyRelaxPro\HappyRelaxDB.mdf') LOG ON(NAME='HappyRelaxDB_log',FILENAME='D:\Sunny_Project\HappyRelaxPro\HappyRelaxDB_log.ldf') GO
以上黃色標記的為需要更改的內容
假設創建數據庫abc,並創建一個用戶表:
IF NOT EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'abc')
BEGIN
CREATE DATABASE [abc] ON (NAME = N'abc_Data', FILENAME = N'D:\abc_Data.MDF' , SIZE = 12, FILEGROWTH = 10%) LOG ON (NAME = N'abc_Log', FILENAME = N'D:\abc_Log.LDF' , SIZE = 10, FILEGROWTH = 10%)
COLLATE Chinese_PRC_CI_AS
END
GO
CREATE TABLE [abc].[user] (
[UserID] [GUID] NOT NULL ,
[UserName] [varchar] (255) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[Password] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
在你的SQLSERVER中,點擊左上角的新建查詢,然後新建查詢上邊還有一個下拉列表,可以選擇當前數據庫,你想在哪個數據庫中建表,就選擇哪個表。
建立數據庫可以使用SQL SERVER設計器,當然也可以利用SQL語句
use master --設置當前數據庫為master,以便方便訪問表sysdatabases
if exists(select * from sysdatabases where name = 'stuDB') --查詢是否存在stuDB數據庫
Drop database stuDB --如果存在,則刪除數據庫
go
create database stuDB
on primary
(
name = 'stuDB'
,finename = 'D:\stuDB.mdf'
,size = 3mb
,filegrowth = 10%
,maxsize = unlimited
)
log on
(
name = 'stuDB_log'
,filename = 'D:\stuDB_log.ldf'
,size = 3mb
,filegrowth = 10%
,maxsize = unlimited
)
建表
if exists(select * from sysobjects where name = 'stuInfo')
drop table stuInfo
go
create table stuInfo
(
stuName varchar(50) not null
, stuAge int not null
)