SQL CREATE DATABASE - . . , , , . , , , .
, . , SQL. CREATE DATABASE Animals CREATE DATABASE Electrical. . , , - .
, Animals. , Animals, . , . Electrical , : , , .
DDL, DML, DCL
SQL - .
, . , , . :
: SELECT, INSERT, UPDATE, DELETE. , GRANT, REVOKE, DENY.
:
Create , . SQL - SQL CREATE DATABASE base_name.
Alter . , , , . DROP .
CREATE
CREATE - , . . :
:
CREATE TABLE table_name
table_name , . () .
CREATE TABLE table_name ( arg )
,
Planets , ID OpeningYear, . PlanetName - 10 . Radius SunSeason . HavingRings true false.
CREATE VIEW . , , . , . , .
SQL - CREATE DATABASE base_name.
CREATE DATABASE
SQL Server- CREATE DATABASE. . . SQL. POSTGRESQL CREATE DATABASE . :
CREATE DATABASE db_name. , , .
SQL CREATE DATABASE User Password. .
SQL CREATE DATABASE Character set utf8 .
Database_name
MS SQL CREATE DATABASE . . .
- A Z a z.
- , @, $, #.
- .
- .
SQL CREATE DATABASE t.
120 . , database_name. , 123 , 128 .
CONTAINMENT
SQL Server 2012. . :
, , . . SQL , . NONE. , .
CONTAINMENT = PARTIAL, .
ON COLLATE
On , . <filespec>.
PRIMARY <filespec> . , CREATE DATABASE.
LOG ON <filegroup> , <filegroup> .
COLLATE collation_name . , SQL Server. FOR ATTACH FOR ATTACH_REBUILD_LOG. .
WITH options:
- <filestream_options> , : OFF ( ), READ_ONLY ( ), FULL ( ). DIRECTORY_NAME = <directory_name>. , .
- DEFAULT_FULLTEXT_LANGUAGE , . , . . .
- DEFAULT_LANGUAGE . 0-32.
- TRANSFORM_NOISE_WORDS -, - , 0 . 0, - , 0 . 1, , .
- TWO_DIGIT_YEAR_CUTOFF 1753 9999. SQL 1950-2049, 30, 2030, 50 1950.
- DB_CHAINING , .
- TRUSTWORTHY . off, .
<filespec>
. Logical_file_name , . , .
FILENAME = { 'os_file_name' | 'filestream_path' }
filename . Size , maxsize - .
. SQL CREATE DATABASE:
SQL. mydb. USE mydb.
USE db1;
SELECT COUNT(*) FROM mytable;
USE db2;
SELECT COUNT(*) FROM mytable;
db1 , db2.
mytable PRIMARY KEY 20 name. , AS/SELECT/FROM.
CREATE TABLE new_table_name AS
SELECT column1, column2,...
FROM existing_table_name
WHERE ....;
, new_table_name, , SELECT. column1 column2. , .
FROM existing_table_name
, SHOW DATABASES.
, INSERT INTO, INTO . : LOW_PRIORITY, DELAYED, HIGH_PRIORITY IGNORE.
, VALUES, ( 1, Will ), ( 2, Marry ) ( 3, Dean ). VALUES VALUE. SET, , . col = expr.
SELECT . , id, name mytable, id 1. , UPDATE, name Willy.
, . , DROP DATABASE _. , .
Sales, saledat.mdf , PRIMARY. SIZE MAXSIZE MB KB, . SIZE - 10 MB, MAXSIZE - 15 MB.
, , . , :
, 200 .
, FILEGROUP group_name.
SalesGroup1, SalesGroup2. , 50 . Sales_log. - SPri1_dat SPri2_dat , 10 , 50 .
,
FileStreamDB. , FILESTREAM. .
USE master;
GO
-- Get the SQL Server data path.
DECLARE @data_path nvarchar(256);
SET @data_path = (SELECT SUBSTRING(physical_name, 1, CHARINDEX(N'master.mdf', LOWER(physical_name)) - 1)
FROM master.sys.master_files
WHERE database_id = 1 AND file_id = 1);
-- Execute the CREATE DATABASE statement.
EXECUTE ('CREATE DATABASE FileStreamDB
ON PRIMARY
(
NAME = FileStreamDB_data
,FILENAME = ''' + @data_path + 'FileStreamDB_data.mdf''
,SIZE = 10MB
,MAXSIZE = 50MB
,FILEGROWTH = 15%
),
FILEGROUP FileStreamPhotos CONTAINS FILESTREAM DEFAULT
(
NAME = FSPhotos
,FILENAME = ''C:\MyFSfolder\Photos''
-- SIZE and FILEGROWTH should not be specified here.
-- If they are specified an error will be raised.
, MAXSIZE = 5000 MB
),
(
NAME = FSPhotos2
, FILENAME = ''D:\MyFSfolder\Photos''
, MAXSIZE = 10000 MB
),
FILEGROUP FileStreamResumes CONTAINS FILESTREAM
(
NAME = FileStreamResumes
,FILENAME = ''C:\MyFSfolder\Resumes''
)
LOG ON
(
NAME = FileStream_log
,FILENAME = ''' + @data_path + 'FileStreamDB_log.ldf''
,SIZE = 5MB
,MAXSIZE = 25MB
,FILEGROWTH = 5MB
)'
);
GO
@data_path - , 256 .
SET @data_path = (SELECT SUBSTRING(physical_name, 1, CHARINDEX(N'master.mdf', LOWER(physical_name)) - 1)
SUBSTRING , . , - . CHARINDEX, . physical_name, master.mdf.
EXECUTE . FileStreamDB_data, FileStreamPhotos FileStreamResumes.
FileStreamPhotos FILESTREAM data: FSPhotos FSPhotos2. FileStreamResumes FILESTREAM FileStreamResumes. FileStream_log 25 .