DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
SITE SEARCH SQLUSA.com HEADLINES NEWS
SQL E/BOOKS  SQL 2012 PROGRAMMING  DOWNLOADS
SCRIPTS SQL 2005 SQL 2008 ARTICLES
SQL JOBS TWITTER FORMAT VIDEOS
How to create a database?

Execute the following Microsft SQL Server T-SQL example scripts in SSMS Query Editor to demonstrate how to create and test a new database.

USE master;

--SQL create database

CREATE DATABASE [dbFINANCE] ON  PRIMARY

( NAME = N'dbFINANCE_Data',

FILENAME = N'F:\DB\DATA\dbFINANCE.mdf' , SIZE = 217152KB ,

MAXSIZE = UNLIMITED, FILEGROWTH = 16384KB )

LOG ON

( NAME = N'dbFINANCE_Log',

FILENAME = N'F:\DB\DATA\dbFINANCE_1.ldf' ,

SIZE = 67584KB , MAXSIZE = 2048GB , FILEGROWTH = 16384KB )

GO

-- SQL compatibility level 100 is SQL Server 2008

ALTER DATABASE [dbFINANCE] SET COMPATIBILITY_LEVEL = 100

GO

 

USE dbFINANCE;

 

-- SQL select into table create

SELECT * INTO POH

FROM AdventureWorks2008.Purchasing.PurchaseOrderHeader

GO

 

-- SQL select query for 3 random records

SELECT TOP (3) * FROM POH ORDER BY NEWID()

GO

 

/* Results

PurchaseOrderID   RevisionNumber    Status      EmployeeID  VendorID

1803              0                 4           258         1664

1944              0                 4           254         1608

1179              0                 4           255         1690

*/

 

-- Cleanup

-- Drop table

DROP TABLE POH

GO

-- Drop database - delete database

USE master;

GO

DROP DATABASE dbFINANCE

GO

----------

USE master;

GO

--SQL create database with FILESTREAM

CREATE DATABASE [dbACCOUNTING] ON  PRIMARY

( NAME = N'dbACCOUNTING_Data',

FILENAME = N'F:\DB\DATA\dbACCOUNTING.mdf' , SIZE = 217152KB ,

MAXSIZE = UNLIMITED, FILEGROWTH = 16384KB ),

 FILEGROUP [DocumentFileStreamGroup] CONTAINS FILESTREAM  DEFAULT

( NAME = N'FileStreamDocuments',

FILENAME = N'F:\DB\DATA\dbACCOUNTING_2.Documents' )

 LOG ON

( NAME = N'dbACCOUNTING_Log',

FILENAME = N'F:\DB\DATA\dbACCOUNTING_1.ldf' ,

SIZE = 67584KB , MAXSIZE = 2048GB , FILEGROWTH = 16384KB )

GO

-- SQL compatibility level 100 is SQL Server 2008

ALTER DATABASE [dbACCOUNTING] SET COMPATIBILITY_LEVEL = 100

GO

 

USE dbACCOUNTING;

 

-- SQL select into create table

SELECT * INTO SOH

FROM AdventureWorks2008.Sales.SalesOrderHeader

GO

 

-- SQL select query for random selection of 3 records

SELECT TOP (3) * FROM SOH ORDER BY NEWID()

GO

 

/* Results

 

SalesOrderID      RevisionNumber    OrderDate   DueDate

51829             1                 2003-08-01 2003-08-13

59350             1                 2003-12-05 2003-12-17

44454             1                 2001-10-27 2001-11-08

*/

 

-- Cleanup

-- Drop table

DROP TABLE SOH

GO

-- Drop database - delete database

USE master;

GO

DROP DATABASE dbACCOUNTING

GO

 

 

 

Exam Prep 70-461
Exam 70-461
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE