SlideShare une entreprise Scribd logo
1  sur  3
Télécharger pour lire hors ligne
Home Contents




Creating, altering and dropping tables

In this part of the SQLite tutorial, we will cover the data definition language (DDL) of the SQLite

database. The DDL consists of SQL statements that define the database schema. The schema is the

database structure defined in a formal language. In relational databases, the schema defines the

tables, views, indexes, relationships or triggers.


The SQLite supports the following three DDL statements:


    •   CREATE

    •   ALTER TABLE

    •   DROP


In SQLite, the CREATE statement is used to create tables, indexes, views and triggers. The ALTER

TABLE statement changes the structure of the table. The DROP statement removes tables, indexes,

views and triggers.




CREATE and DROP statements

The CREATE statement is used to create tables. It is also used to create indexes, views and triggers.


To create a table, we give a name to a table and to its columns. Each column can have one of these

data types:


    •   NULL - The value is a NULL value

    •   INTEGER a signed integer

    •   REAL - a floating point value

    •   TEXT - a text string

    •   BLOB - a blob of data




  sqlite> CREATE TABLE Testing(id integer);




  sqlite> .schema Testing
CREATE TABLE Testing(id integer);


We create a simple Testing table with the CREATE TABLE statement. The .schema command shows

the formal definition of the table.




  sqlite> .table




  Names       Testing    cars




  sqlite> DROP TABLE Testing;




  sqlite> .table




  Names    cars


We verify the existence of the table with the .table command. Next the DROP TABLE statement

removes the table Testing from the database.




ALTER TABLE

SQLite supports a limited subset of ALTER TABLE. The ALTER TABLE command in SQLite allows the

user to rename a table or to add a new column to an existing table. It is not possible to rename a

column, remove a column, or add or remove constraints from a table.




  sqlite> .schema Names




  CREATE TABLE Names(Id integer, Name text);




We have a table called Names, which we want to rename.




  sqlite> ALTER TABLE Names RENAME TO NamesOfFriends;
We rename the table to NamesOfFriends.




  sqlite> .schema NamesOfFriends




  CREATE TABLE "NamesOfFriends"(Id integer, Name text);


We verify the schema of the renamed table.


Say we wanted to add a new column to the table.




  sqlite> ALTER TABLE NamesOfFriends ADD COLUMN Email text;


The SQL statement adds a new column named Email to the table.




  sqlite> .schema NamesOfFriends




  CREATE TABLE "NamesOfFriends"(Id integer, Name text, Email text);


Here we see the new structure of the table.


In this part of the SQLite tutorial, we were creating, altering and dropping tables.

Contenu connexe

Tendances (19)

Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and Joins
 
8. sql
8. sql8. sql
8. sql
 
SQL-Alter Table, SELECT DISTINCT & WHERE
SQL-Alter Table, SELECT DISTINCT & WHERESQL-Alter Table, SELECT DISTINCT & WHERE
SQL-Alter Table, SELECT DISTINCT & WHERE
 
Sql basic things
Sql basic thingsSql basic things
Sql basic things
 
Oracle: DDL
Oracle: DDLOracle: DDL
Oracle: DDL
 
Database Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and deleteDatabase Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and delete
 
Oracle: DML
Oracle: DMLOracle: DML
Oracle: DML
 
SQL DDL
SQL DDLSQL DDL
SQL DDL
 
Les13
Les13Les13
Les13
 
View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Sql commands
Sql commandsSql commands
Sql commands
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 
Mysql cheatsheet
Mysql cheatsheetMysql cheatsheet
Mysql cheatsheet
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
 
SQL
SQLSQL
SQL
 
MySQL notes - Basic Commands and Definitions
MySQL notes - Basic Commands and DefinitionsMySQL notes - Basic Commands and Definitions
MySQL notes - Basic Commands and Definitions
 

En vedette

Java one 2010
Java one 2010Java one 2010
Java one 2010scdn
 
The sqlite3 commnad line tool
The sqlite3 commnad line toolThe sqlite3 commnad line tool
The sqlite3 commnad line toolpunu_82
 
Sq lite functions
Sq lite functionsSq lite functions
Sq lite functionspunu_82
 
第5回SCDN - Things that become possible with HTML5
第5回SCDN - Things that become possible with HTML5第5回SCDN - Things that become possible with HTML5
第5回SCDN - Things that become possible with HTML5scdn
 
SCDN 1
SCDN 1SCDN 1
SCDN 1scdn
 
Introduction to sq lite
Introduction to sq liteIntroduction to sq lite
Introduction to sq litepunu_82
 

En vedette (7)

Java one 2010
Java one 2010Java one 2010
Java one 2010
 
The sqlite3 commnad line tool
The sqlite3 commnad line toolThe sqlite3 commnad line tool
The sqlite3 commnad line tool
 
Sq lite functions
Sq lite functionsSq lite functions
Sq lite functions
 
第5回SCDN - Things that become possible with HTML5
第5回SCDN - Things that become possible with HTML5第5回SCDN - Things that become possible with HTML5
第5回SCDN - Things that become possible with HTML5
 
мясной дом Бородина.
мясной дом Бородина.мясной дом Бородина.
мясной дом Бородина.
 
SCDN 1
SCDN 1SCDN 1
SCDN 1
 
Introduction to sq lite
Introduction to sq liteIntroduction to sq lite
Introduction to sq lite
 

Similaire à Creating, altering and dropping tables

Similaire à Creating, altering and dropping tables (20)

MySQL Essential Training
MySQL Essential TrainingMySQL Essential Training
MySQL Essential Training
 
SQL Query
SQL QuerySQL Query
SQL Query
 
Sql commands
Sql commandsSql commands
Sql commands
 
Module 3
Module 3Module 3
Module 3
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
 
Les10
Les10Les10
Les10
 
Sql presentation 1 by chandan
Sql presentation 1 by chandanSql presentation 1 by chandan
Sql presentation 1 by chandan
 
Oracle sql material
Oracle sql materialOracle sql material
Oracle sql material
 
SQL Tutorial for BCA-2
SQL Tutorial for BCA-2SQL Tutorial for BCA-2
SQL Tutorial for BCA-2
 
Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptx
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
 
SQL.ppt
SQL.pptSQL.ppt
SQL.ppt
 
Les10 Creating And Managing Tables
Les10 Creating And Managing TablesLes10 Creating And Managing Tables
Les10 Creating And Managing Tables
 
Sql tables
Sql tablesSql tables
Sql tables
 
Introduction to Oracle Database.pptx
Introduction to Oracle Database.pptxIntroduction to Oracle Database.pptx
Introduction to Oracle Database.pptx
 
DBMS LAB M.docx
DBMS LAB M.docxDBMS LAB M.docx
DBMS LAB M.docx
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
 

Dernier

Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Dernier (20)

Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

Creating, altering and dropping tables

  • 1. Home Contents Creating, altering and dropping tables In this part of the SQLite tutorial, we will cover the data definition language (DDL) of the SQLite database. The DDL consists of SQL statements that define the database schema. The schema is the database structure defined in a formal language. In relational databases, the schema defines the tables, views, indexes, relationships or triggers. The SQLite supports the following three DDL statements: • CREATE • ALTER TABLE • DROP In SQLite, the CREATE statement is used to create tables, indexes, views and triggers. The ALTER TABLE statement changes the structure of the table. The DROP statement removes tables, indexes, views and triggers. CREATE and DROP statements The CREATE statement is used to create tables. It is also used to create indexes, views and triggers. To create a table, we give a name to a table and to its columns. Each column can have one of these data types: • NULL - The value is a NULL value • INTEGER a signed integer • REAL - a floating point value • TEXT - a text string • BLOB - a blob of data sqlite> CREATE TABLE Testing(id integer); sqlite> .schema Testing
  • 2. CREATE TABLE Testing(id integer); We create a simple Testing table with the CREATE TABLE statement. The .schema command shows the formal definition of the table. sqlite> .table Names Testing cars sqlite> DROP TABLE Testing; sqlite> .table Names cars We verify the existence of the table with the .table command. Next the DROP TABLE statement removes the table Testing from the database. ALTER TABLE SQLite supports a limited subset of ALTER TABLE. The ALTER TABLE command in SQLite allows the user to rename a table or to add a new column to an existing table. It is not possible to rename a column, remove a column, or add or remove constraints from a table. sqlite> .schema Names CREATE TABLE Names(Id integer, Name text); We have a table called Names, which we want to rename. sqlite> ALTER TABLE Names RENAME TO NamesOfFriends;
  • 3. We rename the table to NamesOfFriends. sqlite> .schema NamesOfFriends CREATE TABLE "NamesOfFriends"(Id integer, Name text); We verify the schema of the renamed table. Say we wanted to add a new column to the table. sqlite> ALTER TABLE NamesOfFriends ADD COLUMN Email text; The SQL statement adds a new column named Email to the table. sqlite> .schema NamesOfFriends CREATE TABLE "NamesOfFriends"(Id integer, Name text, Email text); Here we see the new structure of the table. In this part of the SQLite tutorial, we were creating, altering and dropping tables.