0% found this document useful (0 votes)
159 views4 pages

PRACTICAL NO-3 Study of DDL and DML Command. Create Table and Insert Sample

Uploaded by

barot kajal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
159 views4 pages

PRACTICAL NO-3 Study of DDL and DML Command. Create Table and Insert Sample

Uploaded by

barot kajal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Practical 3

Aim: Study of DDL and DML command. Create table and insert sample data in
tables.
SQL Important Commands
Here is the list of some important SQL Commands:

Commands Descriptions

SELECT Used to retrieve data from a database.

INSERT Adds new records or rows to a table.

UPDATE Modifies existing records in a table.

DELETE Removes records from a table.

CREATE TABLE Creates a new table in the database.

ALTER TABLE Modifies an existing table structure.

DROP TABLE Deletes a table from the database.

CREATE INDEX Creates an index on a table column to speed up data retrieval.

DROP INDEX Removes an index from a table.

CREATE VIEW Creates a virtual table based on the result of a SQL statement.

DROP VIEW Deletes a view from the database.

INSERT INTO SELECT Inserts data from one table into another based on a query.
Commands Descriptions

Removes all records from a table, but keeps the table structure
TRUNCATE TABLE
intact.

ALTER TABLE ADD


Adds a constraint to a table after it has been created.
CONSTRAINT

GRANT Gives specific privileges to database users.

REVOKE Removes specific privileges from database users.

COMMIT Saves all changes made since the last commit.

ROLLBACK Discards all changes made since the last commit.

BEGIN TRANSACTION Starts a new transaction.

SET TRANSACTION Sets characteristics for the transaction.

SQL CREATE TABLE


CREATE TABLE command creates a new table in the database in SQL. In this article, we will learn
about CREATE TABLE in SQL with examples and syntax.

SQL CREATE TABLE Statement

SQL CREATE TABLE Statement is used to create a new table in a database. Users can define the
table structure by specifying the column’s name and data type in the CREATE TABLE command.

This statement also allows to create table with constraints, that define the rules for the table. Users
can create tables in SQL and insert data at the time of table creation.

Syntax
To create a table in SQL, use this CREATE TABLE syntax:

CREATE table table_name


(
Column1 datatype (size),
column2 datatype (size),
.
.
columnN datatype(size)
);

Here table_name is name of the table, column is the name of column

SQL CREATE TABLE Example


Let’s look at some examples of CREATE TABLE command in SQL and see how to create table in SQL.

CREATE TABLE EMPLOYEE Example

In this example, we will create table in SQL with primary key, named “EMPLOYEE”.

CREATE TABLE Employee (


EmployeeID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Department VARCHAR(50),
Salary DECIMAL(10, 2)
);

CREATE TABLE in SQL and Insert Data


In this example, we will create a new table and insert data into it.

Let us create a table to store data of Customers, so the table name is Customer, Columns are
Name, Country, age, phone, and so on.

CREATE TABLE Customer(


CustomerID INT PRIMARY KEY,
CustomerName VARCHAR(50),
LastName VARCHAR(50),
Country VARCHAR(50),
Age INT CHECK (Age >= 0 AND Age <= 99),
Phone int(10)
);

Output:

To add data to the table, we use INSERT INTO command, the syntax is as shown below:

Syntax:

INSERT INTO table_name (column1, column2, …) VALUES (value1, value2, …);


Example Query

This query will add data in the table named Subject

INSERT INTO Customer (CustomerID, CustomerName, LastName, Country, Age, Phone)


VALUES (1, 'Shubham', 'Thakur', 'India','23','xxxxxxxxxx'),
(2, 'Aman ', 'Chopra', 'Australia','21','xxxxxxxxxx'),
(3, 'Naveen', 'Tulasi', 'Sri lanka','24','xxxxxxxxxx'),
(4, 'Aditya', 'Arpan', 'Austria','21','xxxxxxxxxx'),
(5, 'Nishant. Salchichas S.A.', 'Jain', 'Spain','22','xxxxxxxxxx');

Output:

You might also like