Bazy Danych (L) Part I


mysql -u root -p
create database test16;
use test16;
create table czlowiek (imie varchar(15), nazwisko varchar(20), pesel char(11));

Query OK, 0 rows affected (0.09 sec)

mysql> show tables;
+-------------------+
| Tables_in_test160 |
+-------------------+
| czlowiek |
+-------------------+
1 row in set (0.00 sec)

mysql> describe czlowiek;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| imie | varchar(15) | YES | | NULL | |
| nazwisko | varchar(20) | YES | | NULL | |
| pesel | char(11) | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

create table if not exists czlowiek (imie varchar(15), nazwisko varchar(20), pesel char(11));
create table if not exists student (imie varchar(15), nazwisko varchar(20), pesel char(11));


show tables
-> ;
+-------------------+
| Tables_in_test160 |
+-------------------+
| czlowiek |
| student |
+-------------------+
2 rows in set (0.00 sec)


create table samochod(id char(10), marka varchar(15),model varchar(15));
Query OK, 0 rows affected (0.11 sec)

create table samochod2(id INT AUTO_INCREMENT PRIMARY KEY, marka varchar(15),model varchar(15));

describe samochod2;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| marka | varchar(15) | YES | | NULL | |
| model | varchar(15) | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+


create table klienci(id INT AUTO_INCREMENT PRIMARY KEY, imie1 varchar(15), imie2 varchar(15) default 'brak');

create table pracownicy(id INT AUTO_INCREMENT PRIMARY KEY, imie varchar(20), nazwisko varchar(30)not null);

describe pracownicy
-> ;
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| imie | varchar(20) | YES | | NULL | |
| nazwisko | varchar(30) | NO | | NULL | |
+----------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)


create table uzytkownicy(id INT AUTO_INCREMENT PRIMARY KEY, haslo varchar(20), email varchar(30)unique);

describe uzytkownicy;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| haslo | varchar(20) | YES | | NULL | |
| email | varchar(30) | YES | UNI | NULL | |
+-------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)


alter table samochod add pojemnosc_silnika float;

describe samochod;
+-------------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+-------------+------+-----+---------+-------+
| id | char(10) | YES | | NULL | |
| marka | varchar(15) | YES | | NULL | |
| model | varchar(15) | YES | | NULL | |
| pojemnosc_silnika | float | YES | | NULL | |
+-------------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)


alter table czlowiek add ID INT AUTO_INCREMENT PRIMARY KEY FIRST;

describe czlowiek;
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| ID | int(11) | NO | PRI | NULL | auto_increment |
| imie | varchar(15) | YES | | NULL | |
| nazwisko | varchar(20) | YES | | NULL | |
| pesel | char(11) | YES | | NULL | |
+----------+-------------+------+-----+---------+----------------+


insert into samochod(pojemnosc_silnika)VALUES (0.1);

Wyszukiwarka

Podobne podstrony:
Bazy Danych (L) Part II
BAZY DANYCH Streszczenie z wykładów
Strona polecenia do bazy danych
2004 11 Porównanie serwerów relacyjnych baz danych Open Source [Bazy Danych]
MySQL Mechanizmy wewnętrzne bazy danych
Bazy danych w CAD
Postać normalna (bazy danych) – Wikipedia, wolna encyklopedia
bazy danych
01 Projektowanie relacyjnej bazy danych Czym jest relacyj
2004 05 Rozproszone fraktale [Bazy Danych]
bazy danych projekt infor w projekcie

więcej podobnych podstron