MONDE-HISTOIRE-CULTURE GÉNÉRALE
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.
MONDE-HISTOIRE-CULTURE GÉNÉRALE

Vues Du Monde : ce Forum MONDE-HISTOIRE-CULTURE GÉNÉRALE est lieu d'échange, d'apprentissage et d'ouverture sur le monde.IL EXISTE MILLE MANIÈRES DE MENTIR, MAIS UNE SEULE DE DIRE LA VÉRITÉ.
 
AccueilAccueil  PortailPortail  GalerieGalerie  RechercherRechercher  Dernières imagesDernières images  S'enregistrerS'enregistrer  Connexion  
Derniers sujets
Marque-page social
Marque-page social reddit      

Conservez et partagez l'adresse de MONDE-HISTOIRE-CULTURE GÉNÉRALE sur votre site de social bookmarking
QUOI DE NEUF SUR NOTRE PLANETE
LA FRANCE NON RECONNAISSANTE
Ephémerides
Le Deal du moment : -17%
SSD interne Crucial SSD P3 1To NVME à ...
Voir le deal
49.99 €

 

 SQL Basics :CREATE

Aller en bas 
AuteurMessage
mihou
Rang: Administrateur
mihou


Nombre de messages : 8092
Localisation : Washington D.C.
Date d'inscription : 28/05/2005

SQL Basics :CREATE Empty
03022006
MessageSQL Basics :CREATE

CREATE DATABASE database_name

CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
.......
)
examples:
CREATE TABLE Person
(
LastName varchar,
FirstName varchar,
Address varchar,
Age int
)



CREATE TABLE Person
(
LastName varchar(30),
FirstName varchar,
Address varchar,
Age int(3)
)


CREATE TABLE customer
(First_Name char(50),
Last_Name char(50),
Address char(50),
City char(50),
Country char(25),
Birth_Date date



CREATE TABLE clients(

Nom char(30) NOT NULL,

Prenom char(30) NOT NULL,

Age integer, check (age < 100),

Email char(50) NOT NULL, check (Email LIKE "%@%")



The syntax for creating a view is as follows:

CREATE VIEW "VIEW_NAME" AS "SQL Statement"

"SQL Statement" can be any of the SQL statements we have discussed in this tutorial.

Let's use a simple example to illustrate. Say we have the following table:

TABLE Customer
(First_Name char(50),
Last_Name char(50),
Address char(50),
City char(50),
Country char(25),
Birth_Date date)



and we want to create a view called V_Customer that contains only the First_Name, Last_Name, and Country columns from this table, we would type in,

CREATE VIEW V_Customer
AS SELECT First_Name, Last_Name, Country
FROM Customer

Now we have a view called V_Customer as below:

View V_Customer
(First_Name char(50),
Last_Name char(50),
Country char(25))


We can also use a view to apply joins to two tables. In this case, users only see one view rather than two tables when they need to combine the information from these two tables. Let's say we have the following two tables:
Table Store_Information
store_name Sales Date
Los Angeles $1500 Jan-05-1999
San Diego $250 Jan-07-1999
Los Angeles $300 Jan-08-1999
Boston $700 Jan-08-1999
Table Geography
region_name store_name
East Boston
East New York
West Los Angeles
West San Diego

and we want to build a view that has sales by region information. We would issue the following SQL statement:

CREATE VIEW V_REGION_SALES
AS SELECT A1.region_name REGION, SUM(A2.Sales) SALES
FROM Geography A1, Store_Information A2
WHERE A1.store_name = A2.store_name
GROUP BY A1.region_name

This gives us a view, V_REGION_SALES, that has been defined to store sales by region records. If we want to find out the content of this view, we type in,

SELECT * FROM V_REGION_SALES

Result:
REGION SALES
East $700
West $2050

Create Index

Indices are created in an existing table to locate rows more quickly and efficiently. It is possible to create an index on one or more columns of a table, and each index is given a name. The users cannot see the indexes, they are just used to speed up queries.
Note: Updating a table containing indexes takes more time than updating a table without, this is because the indexes also need an update. So, it is a good idea to create indexes only on columns that are often used for a search.

A Unique Index

Creates a unique index on a table. A unique index means that two rows cannot have the same index value.

CREATE UNIQUE INDEX index_name
ON table_name (column_name)

The "column_name" specifies the column you want indexed.

A Simple Index

Creates a simple index on a table. When the UNIQUE keyword is omitted, duplicate values are allowed.

CREATE INDEX index_name
ON table_name (column_name)

The "column_name" specifies the column you want indexed.

Example

This example creates a simple index, named "PersonIndex", on the LastName field of the Person table:

CREATE INDEX PersonIndex
ON Person (LastName)

If you want to index the values in a column in descending order, you can add the reserved word DESC after the column name:

CREATE INDEX PersonIndex
ON Person (LastName DESC)

If you want to index more than one column you can list the column names within the parentheses, separated by commas:

CREATE INDEX PersonIndex
ON Person (LastName, FirstName)
Revenir en haut Aller en bas
https://vuesdumonde.forumactif.com/
Partager cet article sur : reddit

SQL Basics :CREATE :: Commentaires

Aucun commentaire.
 

SQL Basics :CREATE

Revenir en haut 

Page 1 sur 1

 Sujets similaires

-
» SQL Basics :DELETE FROM
» SQL Basics :WHERE clause
» SQL Basics :LIKE Condition
» SQL Basics :introduction
» SQL Basics :TRIGGERS

Permission de ce forum:Vous ne pouvez pas répondre aux sujets dans ce forum
MONDE-HISTOIRE-CULTURE GÉNÉRALE :: SCIENCES :: INFORMATIQUE-INTERNET/COMPUTER SCIENCES-
Sauter vers: