반응형

SQL의 종류 DDL, DML, DCL 이란?


 

 

 

SQL(Structured Query Language) - 구조적 질의 언어 이란? 해당 질의 언어를 통해 데이터베이스를 제어하고 관리할 수 있습니다

 

 

   DDL(Data Definition Language)  - 데이터 정의어

 

 

DDL(Data Definition Language)  - 데이터 정의어 란? 데이터베이스를 정의하는 언어이며, 데이터리를 생성, 수정, 삭제하는 등의 데이터의 전체의 골격을 결정하는 역할을 하는 언어 입니다.

 

 

종류 역할
 CREATE  데이터베이스, 테이블등을 생성하는 역할을 합니다.
 ALTER  테이블을 수정하는 역할을 합니다.
 DROP  데이터베이스, 테이블을 삭제하는 역할을 합니다.
 TRUNCATE  테이블을 초기화 시키는 역할을 합니다.

 

 

* SCHEMA, DOMAIN, TABLE, VIEW, INDEX를 정의하거나 변경 또는 삭제할 때 사용하는 언어입니다.

 

* 데이터 베이스 관리자나 데이터베이스 설계자가 사용 합니다.

 

 

 

 

 

   DML(Data Manipulation Language) - 데이터 조작어

 

 

DML(Data Manipulation Language) - 데이터 조작어란? 정의된 데이터베이스에 입력된 레코드를 조회하거나 수정하거나 삭제하는 등의 역할을 하는 언어를 말합니다.

 

 

 

종류 역할
 SELECT  데이터를 조회하는 역할을 합니다.
 INSERT  데이터를 삽입하는 역할을 합니다.
 UPDATE  데이터를 수정하는 역할을 합니다.
 DELETE  데이터를 삭제하는 역할을 합니다.

 

 

 

* 데이터베이스 사용자가 응용 프로그램이나 질의어를 통하여 저장된 데이터를 실질적으로 처리하는데 사용하는 언어 입니다.

 

* 데이터베이스 사용자와 데이터베이스 관리 시스템 간의 인터페이스를 제공합니다.

 

 

 

 

 

   DCL(Data Control Language) - 데이터 제어어

 

 

DCL(Data Control Language) - 데이터베이스에 접근하거나 객체에 권한을 주는등의 역할을 하는 언어를 입니다.

 

 

 

종류 역할
 GRANT  특정 데이터베이스 사용자에게 특정 작업에 대한 수행권한 부여 합니다.
 REVOKE  특정 데이터베이스 사용자에게 특정 작업에 대한 수행 권한을 박탈, 회수 합니다.
 COMMIT
 트랜잭션의 작업을 취소 및 원래래 복구하는 역할을 합니다.
 ROLLBACK
 트랜잭션의 작업을 취소 및 원래대로 복구하는 역할을 합니다.

 

 

 

종류 역할
 GRANT  특정 데이터베이스 사용자에게 특정 작업에 대한 수행권한 부여 합니다.
 REVOKE  특정 데이터베이스 사용자에게 특정 작업에 대한 수행 권한을 박탈, 회수 합니다.

 

 

 

* 데이터를 제어하는 언어 입니다.

 

* 데이터의 보안, 무결성, 회복, 병행 수행제어 등을 정의하는데 사용합니다.

 

 

출처: https://server-talk.tistory.com/159

반응형

'DB > SQL' 카테고리의 다른 글

sql Join & Where개요  (0) 2020.05.06
Foreign Key 제약 설정 Delete Rule  (0) 2020.04.21
WHERE 절의 조합(AND / OR / NOT / IN)  (0) 2020.04.21
[SQL] join의 on절과 where절 차이  (0) 2020.04.10
반응형

ome tips for using full-text search in SQL Server 2016


Use a full-text query instead of the LIKE Transact-SQL predicate if you need to
query 
formatted binary data or query a large amount of unstructured text data.

A full-text query against millions of rows of text data can take only seconds; whereas

a LIKE query against the same data can take minutes to return.

Reduce the full-text unique key size.

To create a full-text index, the table to be indexed must have a unique index. Try to

select a numeric column as the full-text unique key to increase the speed of full-text

population. If the table to be indexed does not have numeric unique index, consider

creating numeric unique index.

Set the virtual memory size to at least 3 times the physical memory installed in

the computer, and set the SQL Server ‘max server memory’ server configuration

option to half the virtual memory size setting (1.5 times the physical memory).

Because working with full-text search is very resource expensive, you should have

enough physical and virtual memory.

Update the statistics on the clustered index or the full-text key for a full population.

Using so, you can help a multi-range population to generate good partitions on the table.

Set the ‘max full-text crawl range’ option to the number of CPUs on the server box.

Setting this option to the number of CPUs on the server box allows optimize CPU

utilization, which improves crawl performance during a full-text index crawl.

Because the ‘max full-text crawl range’ configuration option is an advanced option, you

should set the ‘show advanced option’ option to 1 to make the ‘max full-text crawl

range’ available.

Note. Setting the ‘max full-text crawl range’ option takes effect immediately without

a server restart.

Consider using the full-text property searching.

SQL Server 2016 supports property searching. Now, you can configure a full-text

index to support property-scoped searching on properties, which are emitted by IFilters.

Use an integer data type for the first column of the clustered index of the base table.

Using an integer data type for the first column of the clustered index of the base table

produces the highest full-text index population speed.

Build a secondary index on a timestamp column.

By using so, you can improve the performance of incremental population.

If you have several physical disks, place the database files separately from the

full-text catalog files.

In this case, you can improve the speed of full-text queries, because multiple disks

can process input/output requests concurrently.

Consider using search across multiple columns.

In SQL Server 2016, you can specify an arbitrary number of columns in a full-text

predicate via a column list.

If you have several physical disks, create several Pagefile.sys files, so that each

Pagefile.sys file will be placed on its own physical disk.

Spreading paging files across multiple disk drives and controllers improves

performance on most disk systems because multiple disks can process input/output

requests concurrently.

Use the top_n_by_rank parameter with CONTAINSTABLE or FREETEXTTABLE.

It can be used to restrict the number of rows returned. The top_n_by_rank parameter

specifies that only the n-highest ranked matches, in descending order, will be returned.

Try to use the CONTAINS or FREETEXT predicates instead of the CONTAINSTABLE

or FREETEXTTABLE functions to simplify the query’s text.

Because qualifying rows returned by the CONTAINSTABLE or FREETEXTTABLE

rowset functions must be explicitly joined with the rows in the original SQL Server table,

the queries that use the CONTAINSTABLE and FREETEXTTABLE functions are more

complex than those that use the CONTAINS and FREETEXT predicates.

Consider limit the size of the buffer pool before you perform a full population.

If the sqlservr.exe process tries to grab all available memory for the buffer pool,

out-of-memory conditions and failure to allocate shared memory can occur for the

fdhost.exe process. You can limit the size of the buffer pool by setting the

‘max server memory’ server option to leave enough memory for the fdhost.exe

process and operating system use.

Use full-text data definition language (DDL) statements to create, modify, and
drop 
full-text catalogs and indexes.

You can use CREATE FULLTEXT CATALOG, ALTER FULLTEXT CATALOG,

DROP FULLTEXT CATALOG, CREATE FULLTEXT INDEX, ALTER FULLTEXT

INDEX and DROP FULLTEXT INDEX statements to create, modify, and drop

full-text catalogs and indexes. Because using the full-text data definition language
(DDL) statements is more efficient than using the stored procedures and the stored
procedures, which used to work with full-text catalogs and indexes, will be removed
in a future version of SQL Server, you should use full-text data definition language
(DDL) statements to create, modify, and drop full-text catalogs and indexes.

Consider using the NEAR option of the CONTAINS predicate or CONTAINSTABLE

function.

SQL Server 2016 supports the NEAR option of the CONTAINS predicate or

CONTAINSTABLE function. By using the custom NEAR option you can do the following:

– specify the maximum number of non-search terms that separate the first and last
search terms in a match

– specify that words and phrases are matched only if they occur in the order in which

you specify them.


Set the ‘awe enabled’ server configuration option to 1 if you have more than

4 gigabytes (GB) of physical memory.

Beginning in SQL Server 2008, the full-text engine can use AWE memory because

the full-text engine is part of the sqlservr.exe. Because the ‘awe enabled’ configuration

option is an advanced option, you should set the ‘show advanced option’ option to 1

to make the ‘awe enabled’ available.

Note. You must restart the SQL Server 2016 to apply changes to the ‘awe enabled’ option.


Make full-text index population during periods of low database access.

Because full-text index population takes some time, these updates should be
scheduled during CPU idle time and slow production periods.

Assign a very large table (a table that has millions of rows) to its own full-text catalog.

This can improve performance, and can be used to simplify administering and monitoring.

 

출처: https://www.sswug.org/alexanderchigrik/sql-server/some-tips-for-using-full-text-search-in-sql-server-2016/

반응형
반응형

1) Drop the existing clustered index first (IX_TableX_FieldB):

DROP INDEX TableX.IX_TableX_FieldB

2) Create a (temporary) UNIQUE constraint on the unique fields referenced in the primary key

ALTER TABLE TableX
ADD CONSTRAINT UQ_TableX UNIQUE(FieldA)

3) Drop the PRIMARY KEY

ALTER TABLE TableX
DROP CONSTRAINT PK_TableX

4) Recreate the PRIMARY KEY as CLUSTERED

ALTER TABLE TableX
ADD CONSTRAINT PK_TableX PRIMARY KEY CLUSTERED(FieldA)

5) Drop the temporary UNIQUE constraint

ALTER TABLE TableX
DROP CONSTRAINT UQ_TableX

6) Add the IX_TableX_FieldB back on as NONCLUSTERED

CREATE NONCLUSTERED INDEX IX_TableX_FieldB ON TableX(FieldB)

출처 : https://stackoverflow.com/questions/2297355/change-a-primary-key-from-nonclustered-to-clustered

반응형
반응형

WHERE 절에서 CASE WHEN을 사용해보자

 

 

예제1. 과목이 Math일 경우에만 점수가 100점 그 외의 경우에는 0점인 ROW 조회

 

SELECT *
FROM TBL_TEST
WHERE Score = (CASE WHEN @in_Subject = 'Math' THEN 100 ELSE 0 END)

 

위의 쿼리는 아래와 같이 AND OR 조건으로 바꿔 사용할 수도 있다.

SELECT *
FROM TBL_TEST
WHERE (@in_Subject = 'Math' AND Score = 100)
	OR (@in_Subject <> 'Math' AND Score = 0)

 

 

 

예제2. 과목이 Math일 경우에만 점수가 100점 그 외의 경우에는 전체 ROW 조회

SELECT * 
FROM TBL_TEST 
WHERE (CASE WHEN @in_Subject = 'Math' THEN Score ELSE '' END) 
		= (CASE WHEN @in_Subject = 'Math' THEN 100 ELSE '' END)

 

 

 

예제3. 과목이 Math일 경우 점수가 100점 English일 경우에 점수가 50점인 ROW 조회

SELECT * 
FROM TBL_TEST 
WHERE (CASE WHEN @in_Subject IN ('Math','English') THEN Score ELSE '' END)
		= (CASE WHEN @in_Subject = 'Math' THEN 100 WHEN @in_Subject = 'English' THEN 50 ELSE '' END)
반응형

+ Recent posts