ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

SQl Para Dummies


Enviado por   •  23 de Octubre de 2013  •  1.219 Palabras (5 Páginas)  •  354 Visitas

Página 1 de 5

Conectarse a mysql

CODE:

1.

mysql -h localhost -u root -p pruebas

albertjh@portatil:~$ mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 7

Server version: 5.0.51a-3ubuntu5 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

Crear una base de datos

SQL:

1.

CREATE DATABASE pruebas;

Usar una base de datos

PLAIN TEXT

SQL:

1.

USE pruebas;

mysql> use prueba;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Ver estructura de una tabla de datos

PLAIN TEXT

SQL:

1.

DESCRIBE Alumnos ;

mysql> describe alumnos;

+-----------+-------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+-----------+-------------+------+-----+---------+-------+

| Id | int(11) | YES | | 0 | |

| nombre | varchar(10) | YES | | NULL | |

| apellidos | varchar(30) | YES | | NULL | |

| tlfn | int(10) | YES | | NULL | |

+-----------+-------------+------+-----+---------+-------+

4 rows in set (0.00 sec)

mysql>

Ver tablas de datos

SQL:

1.

SHOW TABLES;

mysql> show tables;

+------------------+

| Tables_in_prueba |

+------------------+

| Notas |

| alumnos |

| mascotas |

+------------------+

3 rows in set (0.00 sec)

Borrar tabla de datos

PLAIN TEXT

SQL:

1.

DROP Notas;

Crear una tabla de datos

PLAIN TEXT

SQL:

1.

CREATE TABLE Alumnos(

2.

id INT NOT NULL,

3.

nombre VARCHAR (10) NOT NULL,

4.

apellido VARCHAR (10) NOT NULL,

5.

telefono LONG,

6.

CONSTRAINT alumnosPk1 PRIMARY KEY (id)

7.

);

8.

9.

CREATE TABLE Notas(

10.

id INT NOT NULL,

11.

modulo VARCHAR (10) NOT NULL,

12.

parcial INT NOT NULL,

13.

nota INT NOT NULL CHECK (VALUE BETWEEN 1 AND 10),

14.

CONSTRAINT notasPk1 PRIMARY KEY (id, modulo),

15.

CONSTRAINT notasfk1 FOREIGN KEY (id) REFERENCES Alumnos(id)

16.

);

Insertar datos en una tabla de datos

PLAIN TEXT

SQL:

1.

INSERT INTO Alumnos VALUES(’1′,‘juan’,‘garcia’,’949494949′);

2.

INSERT INTO Alumnos VALUES(’2′,‘maria’,‘alvarez’,”);

3.

INSERT INTO Alumnos VALUES(’3′,‘carlos’,‘perez’,’6458544′);

4.

INSERT INTO Alumnos VALUES(’4′,‘alberto’,‘jimenez’,”);

5.

INSERT INTO Alumnos VALUES(’5′,‘vanesa’,‘galera’,’912552522′);

6.

INSERT INTO Alumnos VALUES(’6′,‘sergio’,‘molina’,’5464465656′);

...

Descargar como (para miembros actualizados)  txt (8.7 Kb)  
Leer 4 páginas más »
Disponible sólo en Clubensayos.com