0% found this document useful (0 votes)
10 views

My SQL Commands

The document discusses SQL statements for creating, modifying, backing up and deleting databases and tables. It covers the CREATE, DROP, BACKUP, ALTER and TRUNCATE statements and provides syntax examples for each.

Uploaded by

vickroid007
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

My SQL Commands

The document discusses SQL statements for creating, modifying, backing up and deleting databases and tables. It covers the CREATE, DROP, BACKUP, ALTER and TRUNCATE statements and provides syntax examples for each.

Uploaded by

vickroid007
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1. The CREATE DATABASE statement is used to create a new SQL database.

Syntax CREATE DATABASE databasename;


Example The following SQL statement creates a database called "Ra_AcademyDB":
Syntax : CREATE DATABASE Ra_AcademyDB;
2. The DROP DATABASE statement is used to drop (Delete) an existing SQL database.
Syntax DROP DATABASE databasename;
Example The following SQL statement drops the existing database "Ra_AcademyDB":
Syntax : DROP DATABASE Ra_AcademyDB;
3. The BACKUP DATABASE statement is used in SQL Server to create a full back up of
an existing SQL database.
Syntax BACKUP DATABASE databasename
TO DISK = 'filepath';
Example The following SQL statement creates a full back up of the existing database
"Ra_AcademyDB" to the D disk:
Syntax : BACKUP DATABASE Ra_AcademyDB
TO DISK = 'D:\backups\ Ra_AcademyDB.bak';

The following SQL statement creates a differential back up of the database "
Ra_AcademyDB ":
Syntax : BACKUP DATABASE Ra_AcademyDB
TO DISK = 'D:\backups\ Ra_AcademyDB.bak'
WITH DIFFERENTIAL;
4. The CREATE TABLE statement is used to create a new table in a database.
Syntax CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
....
);

The column parameters specify the names of the columns of the table.
The datatype parameter specifies the type of data the column can hold (e.g.
varchar, integer, date, etc.).
Example The following example creates a table called "Students_details" that contains
six columns: StudentID, FirstName, LastName, Address, Gender and City:

Syntax : CREATE TABLE Students_details (


StudentID int,
FirstName varchar(30),
LasttName varchar(30),
Address varchar(255),
Gender varchar(10),
City varchar(20)
);

RAMAKRISHNA ACADEMY 7003793770 1


The following SQL creates a new table called "S_Tables" (which is a copy of the
"Students_details" table):

Syntax : CREATE TABLE S_Table AS


SELECT StudentID, FirstName, Address, City,
FROM Students_details;

5. The DROP TABLE statement is used to drop an existing table in a database.


Syntax DROP TABLE table_name;
Example The following SQL statement drops the existing table "Students_Details":
Syntax : DROP TABLE Students_Details;

6. The TRUNCATE TABLE statement is used to delete the data inside a table, but not
the table itself.
Syntax TRUNCATE TABLE table_name;
Example The following SQL statement deletes the existing data from table
"Students_Details":
Syntax : TRUNCATE TABLE Students_Details;
7. The ALTER TABLE statement is used to add, delete, or modify columns in an
existing table.

The ALTER TABLE statement is also used to add and drop various constraints on an
existing table.
Syntax ALTER TABLE - ADD Column Example
ALTER TABLE table_name ALTER TABLE Customers
ADD column_name datatype; ADD Email varchar(255);
Syntax ALTER TABLE - DROP COLUMN Example
ALTER TABLE table_name ALTER TABLE Customers
DROP COLUMN column_name; DROP COLUMN Email;
Syntax ALTER TABLE - RENAME COLUMN Example
ALTER TABLE table_name ALTER TABLE Customers
RENAME COLUMN old_name to RENAME COLUMN Email to PhNo;
new_name;
Syntax ALTER TABLE - ALTER/MODIFY Example
DATATYPE ALTER TABLE Customers
ALTER TABLE table_name MODIFY COLUMN column_name datatype;
MODIFY COLUMN column_name
datatype;

RAMAKRISHNA ACADEMY 7003793770 2

You might also like