notiuni+de+baza

17

Upload: bogdan-tosa

Post on 01-Feb-2016

6 views

Category:

Documents


0 download

DESCRIPTION

Baze de date mysql intro

TRANSCRIPT

Page 1: Notiuni+de+baza

�����������������

��������������������� ���������

�� ���������� �

�����

�� ����������� �������������������

�������

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������� ����������������������������������������� ������!���������������������������������������������������������������������������"������������������������#$��������������������������������������������������������������������������������������������������������������������%�������������������������&����'(�����������������������������������������������������������������������������������������������������������������%���� �������������������#$������������������������������������������������������������������������������������������������������������������

���������������� �����������)���#$��������������������������������������������������������������������������������������� �������$��������������������������������������������������������������������������������������������������������������������������������������������������������� �������*������+�����,������������������������������������������������������������������������������������������������������������������������������������������ ���������������+�������,�������������������������������������������������������������������������������������������������������������������������������������"�������-������+��������,��������������������������������������������������������������������������������������������������������������������������������"���� ����������������.((���������������������������������������������������������������������������������������������������������������������������������%

���������������/�'(���������������������������������������������������������������������������������������������������������������������������%�������0�����������������������������������������������������������������������������������������������������������������������������������������������������%�������1�������&��������������������������������������������������������������������������������������������������������������������������������������������2

�����3�����������������/4��������������������������������������������������������������������������������������������������������������2�������������������������������������������������������������������������������������������������������������������������������������������������������������2�������(�������������������������������/4������������������������������������������������������������������������������������������������2�������3��������/4��������������������������������������������������������������������������������������������������������������������������5

���������������������������������������������������������������������������������������������������������������������������������������������5���������*������������������������������������������������������������������������������������������������������������������������������5���������6����������������������/4���������������������������������������������������������������������������������������������������������

���� ��3��������/4�������������)�������������������������������������������������������������������������������������������������������������� ���������)����'(��������������������������������������������������������������������������������������������������������������������������������������� ���������������������������������'(������������������������������������������������������������������������������������������� ����0�������������������������������)����������������������������������������������������������������������������������������

�� ��7������������������������&��'(��������������������������������������������������������������������������������������������������� �����������������������8���������������������������������������������������������������������������������������������������������������������� ������������������������'(������������������������������������������������������������������������������������������������������������������������ �� ������������������������9�����������������������������������������������������������������������������������������������������������������

�� ������*������������������������������������������������������������������������������������������������������������������������� �� �������������������� ��������������������!�����������������������������������������������������������������������������������"�� ��������������������������������������������������������������������������������������������������������������������������������������������"

��"��$�$(�:;-13�7��������������������������������������������������������������������������������������������������������������������������%

��������� ����������������������������������� ���������� ������������������������ ����������������� ������ ��������������������������������������������� �������������������������������� ��

Page 2: Notiuni+de+baza

���������������������

��������������������� ���������

�� ���������� �

������

���� ������������

�������������������������

:������������������������������������������������� �����������������)������������������������������������� ���������������������������������������<− �������������������������������− ���������������������� ���������������������������

�����������������������+ ���� ���������������9� �����)�����,��������������������������� ����������������������������� �������������������������������������������������������������������������������������������������������������

���� �����������������������������������

������������������������������������������������������� �����������9� ������ �����=����9���>����������������������������#��������&������������������������� ���������������������������������������������������������������������������������������������?�����������?���������������������� ��������������)���������������)��� ��9������������������������������������������������������� ����������������

������������������������9�����������������������������������������������������������9���������������������9������������������������������������������+�������������� ����������������9��������9��������������������,��1������������������������������������������������� ������������������������������������ ���������������������������������������������������������

�������������������������������������������

:���������������������������������������������������� ���������������������������������

#�)������������������� �������������� ���������������������������� ����������)��������������9� ������������������������������������������<− �������� ���) ���?�������������+���������������� �����8 ������,�����������������������������

�� ���������������������)��� ���������������9� ����������������������������������9������������������������ ��������������� ����������������������������������+��<� ��������@,

− ������������=��)�� ������������������������� ����������������������� ������������������������������������������)���������������+��<������� �������A�(,

− ��������������?�������������������������=�9�������� ��������������������������������������)��������������������������������������

− ������������������?�����������������������������������������������������������9��������� ���������������������������������������������������������������������� ��� ���������������� �����9���������������������������������� �������������������� �����+�������������������������������������������������������,

��������� ����������������������������������� ���������� ������������������������ ����������������� ������ ��������������������������������������������� �������������������������������� ��

Page 3: Notiuni+de+baza

���������������������

��������������������� ���������

�� ���������� �

������

��������������������������������������������������

:�������������9���������� ����� �������������9������������������������0���������������� ����������������� ������������������������������ ������ ������������������������������������� �B�������������������������� ������������������������������������.���� ������� �������������������������������� �����������������������������������;$#������������#$���+���� ���������������/���,�

.��#$���������������� ����������������������� �������������������������������������������<− ���������� �������������9����)��� ����������������������������������������− �� ��������� �����������������������������− ������������� �������������������������������������− �����������������������������������+��<�����������������9�������� ���������������������

��������8�����8������,− ������������������������������������������������� �������+���������� ��������9������9���������

��������������������������#$�������������������������������������������� �������������������������������������������� �B���)������������������������������,

��������������������������������������������������������

1������9����������������������<− � ������������������8�������8�������������������������������+��<��������������������������������

����������������������������������������������,− � ������������������8�������8�����������������������������+��<�����������������������������

��������������������B����������������)���������������� ��������������������������9������������B��� ��������,

-�������������������������9��=��������������C������������������������D9�������������������������������������������������������#$������������������������������������.�������������� ����������#$�����������������������������������������?���������������������������������9��������� ��������������������������?������������������?�������������������������9��������9��������

����!������������������������"#��

*������������9��������������9� ������������������������������������������������� ���������9���������������#$��E����������������9������������9���������������������������������������� �����������9������������ �����#$����� ������������������������9���������)������������������������9�������������������������������������������������������#$����������� ����������������� ������������� �����������������������������������������������������������E��������������9�������������9���������������������������������������������+��������������������������������������#$��,9����������������������������������� ��������������������������� ������������������� ����������������������������������

������������������������� ������������!��"����!"����#��������������

������������������������������������������������������������������������������������������������������

� ��������������������������������������������������������������������������������������������������

��������� ����������������������������������� ���������� ������������������������ ����������������� ������ ��������������������������������������������� �������������������������������� ��

Page 4: Notiuni+de+baza

���������������������

��������������������� ���������

�� ���������� �

������

1�����������������#$���� ���������������������������������� �����������������������9����������������������������������������"$�"����%������������

��������������������������� �����������������������������������������������������������������������

������������������������� ����������������������������������������������������������������������� �

������������������������������������������������������������� ����������������������������������������

���� ����

����������#$�������������������������� ��<− �������������������������+��<��������������������B��=����9�������������������������������������

����������� ����������������������������������������B��9���������������������������������������������������������B��,

− ����������� �������������������������)�������������+��<���������������9������ ������������������=���������������������������������������������� ������������������������������������ �������������������������9�������������,

������������������ ��������������������#$�����������������<− ��������������������������� �������*�08�09������������������������������#$���������������������

� ������������������������������������������������������9���������������������� �B���)����#$���&����������������������������9������������������������������������������������������������������������������������������

− ������������������������������� ����������������9��� ���������������������������������������������������������������������������������+��>�����(���8.��9�=����������/����������������F���B����,

����������#$������� <− ������������������������������������������������������������������������������������� ���������

���������?� ������������ ��9� ����������������� ���������������������������������������������'(������������

− ���������������� ������������������������������������������������������������#$���+��<����� ������������������������������������������������������������������������&���������E�� �����������������������������������)��������������,

����������������������������������������������������������������������������"!&�"��+4���/9�����������������������������������,�

����$��������������������������%����&'

.�������������� �������������������������� �������#$��������������������������� ����������������������������+��<�����������9������������������ ������,��������������������������������������������.������������������� �������������������#$�����������+������������������,������������B)����������

��������� ����������������������������������� ���������� ������������������������ ����������������� ������ ��������������������������������������������� �������������������������������� ��

Page 5: Notiuni+de+baza

���������������������

��������������������� ���������

�� ���������� �

������

������� ������9������������������������������������������������������������������������������9�����������������������

�����������9�#$������������������������������ �������� ������� ��9� ���������&���������������������������������������������� �������������������������(���&��� ���������������������������������������������'(�+�����������'���/�(�������,�

�'(������������&����������������������������� ��������� �����������������������������9����������������������������������������������������������7���� ���������������������������G%5�����$��� ���������������������)�������������������������� �����.������9����H2"9����������������������������1����+1�������������������������������,�����������������:�+�������������:���������� ����������������,9�������������������������������������'(9����������������� ����'(<�552��*������ ��������&����������#$��������������������������������� �����������&�����'(�

����$���������������������������"#��

0������������&������������������������� ����������#$��<− �"�����?����������:����������������E������������������������� ������ �B�������������������������

����− � '�?����������������������$�− ���"!�! ���(��?�������������� ��������������������������������− �!��&"��)��?�� �B����#$�������������)�����− �*�(��?�� �B����#$�������)�����

#�� ���������������������=����� �B���������������������&����'(9� �������������������������������������������������������������������������&���9������������������������������ ����������������������������������������������9��������������������������������������������������������� ����#$���

��� ��� ���������� ������ ������������ �����

�� ����#���������

:��������������������������������������������?���������������� �����������������)����������������������������������� �������������������������������� ����#$��� �����+� ��������������#$�����������,��;���������&�����'(9����������������������������������������������������� ����������������������

#��������� �������������C�����������������������������D9�� ���������������������������������9�����������)����������������������������:���������������������������������������������� ��������������#���������������� ������������������9�������������������������������������������������������������������������� ���� �������

�� � ��(����)������*

:������������)��������������������������+���������������������������������C������D,��������������������������������������������������9�������������������+�����������������,���������������������������

��������� ����������������������������������� ���������� ������������������������ ����������������� ������ ��������������������������������������������� �������������������������������� ��

Page 6: Notiuni+de+baza

���������������������

��������������������� ���������

�� ���������� �

������

��� ������������������������������������ �����������������������������������8���������� ���������� ������������������3����������������+����,�������������� ������������������������������������ ����������������������������������� ����

������������������������������������������������������������ ���

7������<����������������������������������������� ������������ �����0������ ������ ��������������������9������������������������������������9�������������������������������9�������?������������?�*���9�#�������1���*��������������������������9�����������������������������������9��������������������������E������������������ ����������������������������������������

��������������������������9������������������E�������������������9�������������������������3������������������������������������������������<�������������������������9� ������ �����������������������������������9����������������������������� ����������������������������������������������������+��<��������������������������������1�����������G��������������������G�������������������������9�������,�

��������������������� ��������� ����!�"� �������������������� �����������������������������������

��������������������������� ��������������������������������������������������������������������������������#��� �����$��#���� ������������� �����������������������������%�������������������������������

�����������������������������

�� �����������)������*

:����������������������������������������������������������������������������������������������������3�������������������������������������<− �������+�����,��������9� ��������������������������������� ������������������������������������������

�����������=������������− �������������������������*����������������+��������,������������ � ��������������������������������

������������������������− � �������������������������9���������� ��������������������������������������������������

���������

������������� ��������������������� ������������������������������� �����������#������ ���������������������������������������)��������������9����������������������������������������������� �������������

�� ����+������)�����������*

.���������������������������������������������������+����,9������������������������� ���������������0���������������� ������������������)������������ ������C��������D��������������������E����������������������� �������������������� ����������������9�������9�����������������

�����������������������9����������������������9��� ������������� ������)������������������������������������+��<������������������������� �����������������C���D,����������������������������������������������������������������<� ����������������������������������������������������������������������������������

��������� ����������������������������������� ���������� ������������������������ ����������������� ������ ��������������������������������������������� �������������������������������� ��

"

Page 7: Notiuni+de+baza

���������������������

��������������������� ���������

�� ���������� �

������

�� ������������������,''

����������������������������������������������������������������������������������������������������������������1������������������������������������������������������9��������������������������������������������������������������������0���������������������������������������������8�������9��������������������������.((��#����������������������9��.((���������� �������������������9����������������������������������������������+����������9��������������������,�

0�������������� �����.((���������������������� �������������9�������������������������������������������������������������������.((������������������������+���������� �������������������������������������������������,�

��������������

�������-���������������

�/�'(��������� �B��������)������������#$������������9����������������)����=�������������)��������������/�'(��������������������������/�'(�� ���������������������������0��������������������������������� �����������������������������9������������������=��������������������

0��=������/�'(�������������������������������� �B���<− ��"$�"����*�(���7������������������������������������9�����������=���)�>+��,������������9������

������������������������������� ���������������������������������������+������8�������8��� ����8�� ������������8����������������8���������,���������������������� �����������9� �����������������*�0�+����������� ��� �������������� �����5",9� ������������&�������������������������������������������������������������������������������������&�'���

− ���������*�(���#��������/�'(������������������������� �����������������9�����������)���������� ���������������������������#�����������������������������<− �������������������������������������������������������������������<

− �&�'�9����� ���������������������������������������������'(− �&�'�����9��������������������>����������������− �&�'������9��������������������)��� ������)���������������������������

− �������������������������������− �&�'������?���������������������������������������������/�'(

− �"!&"�+���������"���!�,��������������������������������� ���������������������������������9�������������� ���������������������������������.������������������������������������������������� �������� ��������������������������������

�/�'(�������������������F���B������(���8.�������������������������������������� ��������������������������������������������9������������������ ����������������������������������������������������#�������9��������������������������������������������������������������� ������������ ���������������������

��������������������������������(�&�'�)�%��������������������������������������������������������&�*+� �

�����������������������������������������������(����������&�*+)�����(�&�*+)�

��������� ����������������������������������� ���������� ������������������������ ����������������� ������ ��������������������������������������������� �������������������������������� ��

%

Page 8: Notiuni+de+baza

���������������������

��������������������� ���������

�� ���������� �

������

���� ��.��������%������

���� ��������������������������������� ������/�'(9������������������� ��������� �������������������������������������/�'(<− �*�(��(��"*� "!-��"�?����������� ����������������������������������������/�'(9���� �������

��������+������������������'(9�������������������������������)�)����9������������ ��������� �����������������������������9������ �������=���)��������������'(����,

− �*�(����+�����"��!"�?������������ ������������������������������/�'(���������� �����������������������������������������������������9�� ���������������>��)��������������������������������9�������������������������������������������������������

− �.��*��+���?���������B�����������������������������������/�'(��3������ ���������������������)������B������������ ����������������������������������

0�������������������������������������9������������ ����������������������������)���BBB��/4��������� ��������=�������/�'(�;.��*������������������������������������(���8.��9�������������F���B��������)����������������9��������������������9�������������B������������������������������060E�����������������������������������9�����������������������������������������������=��/1����������B����������9� ����������������������

�!"������������� �������#�

����������������������

.���������&�'��� ����������������������������������������������������'(����������������/�'(��0����������&�'�������� � �����������������<− +!��������"����$����������������������9���������������&�'��������������������������)�����������������

�������������������������������������������������������������������− +!�����!�,����"����$�+C����=�����D,��-���������������9��&�'�������������������������&���������)

��� ������������������������������������������������)�������������������������������������������������������������������������������������������'(9��������������������������������������� �������������������������������+��<�������������������������������������������������9������������������������������������������������������������������,

��������������������� �������������������������������������9���9��������������&�'����������������9������������������������� �����������������������������'(�����)��� ���

�������'��������������������������������#�

0��������&�'������������������������������������������� �������������������������+��������0��������������F���B9���������������������������������(���8.��,��(��������������������������������������������� ��������� ������������������ ���������������������������������������������������/�'(<− ������������������������������������+�����������������������9������������� �����9������8������8��>��)

�����������������������������,− ������������ ������������������������+����9�6*�(9�A�(,

��������� ����������������������������������� ���������� ������������������������ ����������������� ������ ��������������������������������������������� �������������������������������� ��

2

Page 9: Notiuni+de+baza

���������������������

��������������������� ���������

�� ���������� �

������

− �����������������������������������&�'����������������+� ����������������B�����)�����9�� ����������������������������������9����,

))=��)=

�������������������������������������������������������/�'(

))���)�

.������)��� ������������������� ���������������������������/�'(

))��B���I������)��������

0������ ������������������������������������/�'(

))��>��I����8�����8 �����>�� ��������������������������� ����������������������������������������� ���������������������� �����������������>���+(���8.��,9������������� ������������

))��������IJ*�0K�:�L7*K0�07K�7�:-MN ������������������������ ������+*�08�09���>������,

))� �)������)))��)�)����/

���������������������'(����������������������������������������� ���������+��������������������,�

7���������<������������������������ �����������������������������������������������������5559� ������������������������������<

user1@mycomputer:~$ mysql -h 1.2.3.4 -P 4000 -u user1 -p pass1

7���������<��������������9���� ��������� ���������������������������������9�����������������������������������������������������������<

user1@mycomputer:~$ mysql -h 1.2.3.4 -u user1 -pEnter password:

����������9������������������ ���������������������������������������������9�������������������������������� ����������������9����������������������������/4�� ����������������������9������������������������������������������������/�'(���������������������������� �������������)���������������������9� �����������

���������/4������������������������0������������������������������������ ���������������������������������������������������+������������=�����������,�

7������<����������������������������� �������������)�������������������9�������������������������������������<

user1@mycomputer:~$ mysql -u user2 -p pass2 studenti

��������� ����������������������������������� ���������� ������������������������ ����������������� ������ ��������������������������������������������� �������������������������������� ��

H

Page 10: Notiuni+de+baza

���������������������

��������������������� ���������

�� ���������� �

������

�������/���������0�1��������������������

�!!������$������ ��� ����

:���������������������������9��&�'��� �����������������������������������������������������������9��������������+������������ ���������������� ���������������������������������7�*7-,��3������������������������������=�����������������������������������������������������9��������������� ���E�+�������������,��0��� ���������������������������������<

user1@mycomputer:~$ mysqlWelcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 120Server version: 5.0.51a-24+lenny1-log (Debian)

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

mysql> show databases;+------------------------------+| Database |+------------------------------+| information_schema | | mysql | | test | +------------------------------+3 rows in set (0.00 sec)

mysql> select version(); select now();+-----------------------+| version() |+-----------------------+| 5.0.51a-24+lenny1-log | +-----------------------+1 row in set (0.00 sec)

+---------------------+| now() |+---------------------+| 2009-06-14 17:39:18 | +---------------------+1 row in set (0.00 sec)

�����������������������������������/4������������������������<− ����������'(9�����������������������������������������������������− ���������������������/4�9��������� �����������������������'(��.�����������������������������������9�

�����������������������+��<�� �����������������������������B�����)��9���������������)�������)��� ��,9��������C������D���������������������� ������������������+��<�� ����������������������������������,

�!!�%������ ��������������������

��������� ����������������������������������� ���������� ������������������������ ����������������� ������ ��������������������������������������������� �������������������������������� ��

�5

Page 11: Notiuni+de+baza

���������������������

��������������������� ���������

�� ���������� �

������

:���������������������� ���=��������� ����9�����������������������=�������<− ���E����O��+��=�������,9�����������������������������������������������������− ���O;�?�� �������������������������������� ��������������������������������������1�����������������

�������������������������������������������������������������������� ����������������������+�����C���D�������������������������,9�

− O��?��������������������������������������������������������������������/4�P

������������������������������������������+�����������������,<

mysql> select curdate(), curtime()\g+------------+-----------+| curdate() | curtime() |+------------+-----------+| 2009-06-14 | 17:46:40 | +------------+-----------+1 row in set (0.00 sec)

�������������������� ����� ������������������� �������������������O;<

mysql> select curdate(), curtime()\G

*************************** 1. row ***************************curdate(): 2009-06-14curtime(): 17:46:421 row in set (0.00 sec)

�������������������&�'���������� ��������*-()�9���������������������������/4��'�������,'�

�!!�&����������������������#�

7��������������������=������������������������������/4�<− =���������9������� ������������������)���������������������/4��+����������'(,�− =����������������������9������� ����� ������������������������'(������������������

6���)����������������������������+������,�=����������!�<

mysql> help

List of all MySQL commands:

Note that all text commands must be first on line and end with ';'? (\?) Synonym for `help'.clear (\c) Clear command.connect (\r) Reconnect to the server. Optional arguments are db and host.delimiter (\d) Set statement delimiter. NOTE: Takes the rest of the line as new delimiter.edit (\e) Edit command with $EDITOR.ego (\G) Send command to mysql server, display result vertically.exit (\q) Exit mysql. Same as quit.go (\g) Send command to mysql server.

��������� ����������������������������������� ���������� ������������������������ ����������������� ������ ��������������������������������������������� �������������������������������� ��

��

Page 12: Notiuni+de+baza

���������������������

��������������������� ���������

�� ���������� �

������

help (\h) Display this help.nopager (\n) Disable pager, print to stdout.notee (\t) Don't write into outfile.pager (\P) Set PAGER [to_pager]. Print the query results via PAGER.print (\p) Print current command.prompt (\R) Change your mysql prompt.quit (\q) Quit mysql.rehash (\#) Rebuild completion hash.source (\.) Execute an SQL script file. Takes a file name as an argument.status (\s) Get status information from the server.system (\!) Execute a system shell command.tee (\T) Set outfile [to_outfile]. Append everything into given outfile.use (\u) Use another database. Takes database name as argument.charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.warnings (\W) Show warnings after every statement.nowarning (\w) Don't show warnings after every statement.

For server side help, type 'help contents'

6���)���������������������������������������������9������������������������������������������������������������ �������&��������<

mysql> help contents;

You asked for help about help category: "Contents"For more information, type 'help <item>', where <item> is one of the followingcategories: Account Management Administration[...output omis...]

mysql> help Administration;

You asked for help about help category: "Administration"For more information, type 'help <item>', where <item> is one of the followingtopics:

DESCRIBE FLUSH QUERY CACHE HELP COMMAND HELP STATEMENT

���������)��������������������������������������������������������9�������� �������������������������������������&����������7����=�����=�������������������=���<

mysql> help help command;

Name: 'HELP COMMAND'Description:Syntax:

mysql> help search_string

��������� ����������������������������������� ���������� ������������������������ ����������������� ������ ��������������������������������������������� �������������������������������� ��

��

Page 13: Notiuni+de+baza

���������������������

��������������������� ���������

�� ���������� �

������

If you provide an argument to the help command, mysql uses it as a

search string to access server-side help from the contents of the MySQLReference Manual. The proper operation of this command requires that

[...output omis...]

�������/���������0�1��������������2���������

�!'������ ������

���������&�'������ ����������������)���������+C����=�����D,������������������� �����������������������'(��.���� ������ ��������������C����D����C����=� ��D��������������� ����������������������������������������+�����������������������������������������,������������������ ����������������������������������������������� ��9�������������������������������������������������������-��������������������� �� ������������

#����������������������9����������'(����������������������������)�������&��������������9�� ������� �����9� ��������������&��������������9�������������������������������������������9����������������������������������

���������*+��-������������������������������� �.����������������/������ ����������������

������0����������������������*+�������������������� ����������������������������������������

������������������������������-����������������1�2�������-������������������������������%�����������

��������������������������������������������������������������������������������*+���������������

�����������������*+��������������������-��������������������������������

�!'������ ����������� �������� ��� ������

����)���������'(�+����=�����������������������������,����� ���������������9����������� ������8���� ������������������������ ����������������������������������������� ����������)���������������������������������������=��� ����� ���������9� ������������������������������ ���9��� �������������+�������&�,���/�'(������������������������������������<• ������������������������������������������������1� �����������������������Q�������))��+�����

���)��������������������,������=������ �����������*�������������� ������������������������������� ����������������������������������������������������

• �����������������������������������������������������������������������������8R������=������R89������������������������������)��� ���������� ������*�������������� ���������������������������������������������������

• ������������������������������������1� �����������������������8RS������=������R8������������������������������������������������/�'(���������������9�������������������������������������� ����������������������������������������������������������������������������1����������������������������������������������������/�'(���������&�����'(������������������������ ������������������ ����������#$����������9����������������������������������������������������������9�����������C�����������D������� �����������������������������������/�'(����������������������

��������� ����������������������������������� ���������� ������������������������ ����������������� ������ ��������������������������������������������� �������������������������������� ��

��

Page 14: Notiuni+de+baza

���������������������

��������������������� ���������

�� ���������� �

������

���������������� ����9�������������������������������������������������������������������/�'(������������������=

7�������+����������������������,<

-- crearea bazei de date principaleCREATE SCHEMA academie; # baza de date cu clase si studenti/* creare tabele:− studenti− clase*/CREATE TABLE studenti /* conturile de utilizator sunt in alta tabela */ (Nume CHAR(50))# portiunea gri a instructiunii se executa numai daca ruleaza pe srv MySQL > 5.0.21SHOW /*!50021 FULL */ TABLES;

�!'�(������������������� ������������� ���� ��

7�������������������������������������'(�������������������������/4�<− �������������������������������������� ����������������:.-�7����������������������

�������������� �����������������������3����������������� �������������� ���������������<

mysql> SOURCE c:/sql/import.sql;[...output omis...]

− �������������������/4�������������)��������9��������������������������������������T��������� ���������������� �������������������������<

/* conectarea la serverul local folosind username si parola, setarea bazeide date test ca implicita si rularea scriptului import.sql */mysql -ustudent -p test < import.sql

�')����� ��������������*�+��

�������������������������������3�������

#������������������������������������&�����'(9���� �������������������������&���<• ����/������� �����!�����&��&�0�������������������������������������������������������������

+������8�������8�������������������������9�������8��� ��������������������� �������������������������,

• ����/���������������!�����&��&�0��-��������������������������������������������������+����������8���������8��� ����8������������ ������,

• ����/������!��"!�����&��&�0��7��� �������������������������������������������������������������+�� ��������������9��������������������������������������������������������8������8�������,�

#��� ��� ������������)���������������������������������� ���������������������������������������������������������9��������'(����������������������������������##(�����������������������������������������

��������� ����������������������������������� ���������� ������������������������ ����������������� ������ ��������������������������������������������� �������������������������������� ��

��

Page 15: Notiuni+de+baza

���������������������

��������������������� ���������

�� ���������� �

������

���� ����������������������&'

0������)������������9�����&����'(��� �����������������������1�������H2"��#������������������������������������������������������'(9� ������������������ ���������������&����+����=���<88���B>��������8B>8�'(Q��������������,��#�����������������9����������������#$����������������������������������������������������� ���������9��������������������C�������D���������&�������������#�����������������������������������������������������������?������������ ���������������������)��� ����������������������������������������������� ��������������� ��������&����������9��������7��������������������������&������������������ ���������� �������������������������9�������������� ����������������������������������#$������������+��<��������/�'(����:�����,9����9����������������������9�C�=�����������=�������D�

��������������������������������������������������� �.����*+����������������������������03�$��*+�

������������������������4���������������

�'��%������������������ ���������� � �

3��������������� ������������������������������������������+��������������9�������9������������,��������� ����������)��������������������������������'(9�������������� �������������������������������������������������+�������������� ��������������U���������������� ��4�'���,��0������������������������� ���������������������������������������������������������������������������������������������������'(�

������������������������������5�% ��4�'��������6�%���������!����4�'������������������������7������������

������������������������������������������&���8������9��

0������������������� ���������������9������������<− ����������������9�� ��9�V����W− ������� � ���������������� ���+������������� ���� �����������������������������������������������������

���������������,− ��������������������������������9�������� ��9����������������������������� ������� ������������������

���������������+��<�����+�������������555,9�5����+�������������",����,

1������������������������������������������ �����������������������������������������+��<�����,9�����������������������������������������<

SELECT * FROM `tabela produse`

�����������������������������������03�$:�*+�%������ ����������������������*+�������������������������

����������%)��

�������������������������������������������������������������������9����������������������<− ����������������������������������5�����

��������� ����������������������������������� ���������� ������������������������ ����������������� ������ ��������������������������������������������� �������������������������������� ��

Page 16: Notiuni+de+baza

���������������������

��������������������� ���������

�� ���������� �

������

− ���������������������������������������������������+�,9���=�+8,�������>��=�+O,��0����������� ���������������������������������+�������&�,9����8��O����� ������������������������������������������������������ ���

�'����� ��$�������������� ��������������,

����������/�'(����=��������=�����>����������� �������� ����������������#������9� �������������������������������������������9�������������������������������� �������������������9��������������� �������������������������������������������������� ����������������������������������������������#������9��������������������F���B����������� ������������������9������(���8.�����������������

1����������������������������� ����� ������������������������������������������������������������������������������������������������������/�'(�+����9����������������9�������)�����,��������)�������

7������<����������������������������0�����9�������������������������F���B���������������� ��������� �������������0-:#.�7����������9�����������(��������������� �����������������������������������

�'�������*���� ������� ���

0������������� ������� �����������)��������������9���������������� ������������������������������������������ ��� ������=����������������<�������������9�������9������������������������������������������������������������������1���� ������ ������������������������ ����������������������������������������������9���������������������� �������������������������� ����������������������

���������������������������� ���������������������������������������� ���<����������������������������������������)��������������� �9����������� �������������������������+�����������9��<OF���BO�/������������������������������������F���B9������������������������������������������������������������O,��������������� �����������������������������������������E��������������������������������9��������������������������������� ���9����������������������������������������������

��������� ��9����)������������������������������������� ������������������������ ������������������������������<− ����������������������� �����%������������%����+���������� ���������������,����

%������������%�����!�!��������������������� �����������������− �����������������������������������������������������������7����� ���������������������������������

���������������������������+������������������������������������������������������.�7�?�������������������������������������������,

7������<���������������������������������)��������<

# specificand numele complet al tabelei (baza de date academie, tabela clase)SELECT * FROM academie.clase

# folosind un nume relativ la baza de date curentaUSE academieSELECT * FROM clase

��������� ����������������������������������� ���������� ������������������������ ����������������� ������ ��������������������������������������������� �������������������������������� ��

�"

Page 17: Notiuni+de+baza

���������������������

��������������������� ���������

�� ���������� �

������

�-�.� ./012".)

• �/�'(����� ����������/�;���

• �/�'(�-� �������������<�=���<88�����/4�����8���8�� ���8 ��8��8

��������� ����������������������������������� ���������� ������������������������ ����������������� ������ ��������������������������������������������� �������������������������������� ��

�%