W3schools - SQL_DDL
이 페이지는 다음에 대한 공부 기록입니다
Lecture에서 배웠던 내용을 복습하며 작성했습니다
찾으시는 정보가 있으시다면
주제별reference를 이용하시거나
우측 상단에 있는 검색기능을 이용해주세요
CREATE DATABASE
Is used to create a new SQL database
CREATE DATABASE databasename;
-- Make sure you have admin privilege before creating any database.
DROP DATABASE
Is used to drop an existing SQL database
DROP DATABASE databasename;
BACKUP DATABASE
Is used in SQL Server to create a full back up of an existing SQL database
Always back up the database to a different drive than the actual database
- Then, if you get a disk crash, you will not lose your backup file along with the database
BACKUP DATABASE databasename
TO DISK = ‘filepath’;
-- A differential back up only backs up the parts of the database that have changed since the last full database backup
BACKUP DATABASE databasename
TO DISK = ‘filepath’
WITH DIFFERENTIAL;
CREATE TABLE
Is used to create a new table in a database
CREATE TABLE table_name(
column1 datatype,
column2 datatype,
….
);
-- Using another table
CREATE TABLE new_table_name AS
SELECT column(s)
FROM existing_table_name
WHERE condition;
-- The column parameters specify the names of the column of the table
-- The datatype parameter specifies the type of data the column can hold
DROP TABLE
Is used to drop an existing table in a database
DROP TABLE table_name;
TRUNCATE TABLE
Is used to delete the data inside a table, but not the table itself
TRUNCATE TABLE table_name;
ALTER TABLE
Is used to add, delete, or modify columns in a existing table
Is also used to add and drop various constraints on an existing table
-- ADD
ALTER TABLE table_name
ADD column_name datatype;
-- DROP
ALTER TABLE table_name
DROP COLUMN column_name;
-- MODIFY
ALTER TABLE table_name
MODIFY column_name datatype;