SQL Server DATABASE creation script Create DATABASE, createdatabase

Source: Internet
Author: User

SQL Server DATABASE creation script Create DATABASE, createdatabase

Create DATABASE HappyRelaxDBon( NAME='HappyRelaxDB',FILENAME='D:\Sunny_Project\HappyRelaxPro\HappyRelaxDB.mdf')LOG ON(NAME='HappyRelaxDB_log',FILENAME='D:\Sunny_Project\HappyRelaxPro\HappyRelaxDB_log.ldf')GO

The above marked yellow is the content to be changed


SQL Server 2008 how to create a database using SQL scripts

Suppose you create a database abc and a user table:
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,
[User name] [varchar] (255) COLLATE Chinese_PRC_CI_AS not null,
[Password] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO

For the sql-server2005, how to write the program to achieve table creation, create database book write with create, but where to write the create statement

In your SQLSERVER, click Create query in the upper left corner, and a drop-down list is displayed on the top of the new query. You can select the database where you want to create a table and select the table.
You can use the SQL server designer to create a database, or use SQL statements.
Use master -- set the current database as the master to facilitate access to the table sysdatabases
If exists (select * from sysdatabases where name = 'database') -- query whether stuDB database exists
Drop database stuDB -- delete the database if it exists
Go
Create database stuDB
On primary
(
Name = 'database'
, Finename = 'd: \ stuDB. mdf'
, Size = 3 mb
Filegrowth = 10%
, Maxsize = unlimited
)
Log on
(
Name = 'db _ Log'
, Filename = 'd: \ stuDB_log.ldf'
, Size = 3 mb
Filegrowth = 10%
, Maxsize = unlimited
)

Create a table

If exists (select * from sysobjects where name = 'stuinfo ')
Drop table stuInfo
Go
Create table stuInfo
(
StuName varchar (50) not null
, StuAge int not null
)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.