Crearea unui tabel

postat acum 4 ani de Stefanescu Mihai in categorie SQL

Crearea unei tabele implica denumirea acesteia, definirea coloanelor si tipurilor de date stocate in aceste coloane.

Pentru a crea o noua tabela SQL folosim comanda CREATE TABLE astfel:

CREATE TABLE nume_tabel(
   Coloana1 tip_de_date,
   Coloana2 tip_de_date,
   Coloana3 tip_de_date,
   .....
   ColoanaN tip_de_date,
   PRIMARY KEY( una sau mai multe coloane)
);

CREATE TABLE este cuvantul cheie ce ii spune bazei de date ce doresti sa faci. In acest caz vrei sa creezi un nou tabel. Imediat dupa cuvantul cheie CREATE TABLE este pus un nume unic pe care doresti sa-l dai tabelei.

Apoi, in paranteze punem lista cu coloanele si tipul lor de date.

Exemplu

Mai jos vom scrie codul pentru tabelul angajati cu coloana ID ca fiind cheie primara.

SQL> CREATE TABLE angajati(
   ID   INT              NOT NULL,
   Nume VARCHAR (20)     NOT NULL,
   Varsta  INT              NOT NULL,
   Adresa  CHAR (25) ,
   Salariu   DECIMAL (18, 2),       
   PRIMARY KEY (ID)
);

Dupa ce ati creat tabela puteti observa structura acesteia folosind comanda DESC:

DESC angajati;
+---------+---------------+------+-----+---------+-------+
| Field   | Type          | Null | Key | Default | Extra |
+---------+---------------+------+-----+---------+-------+
| ID      | int(11)       | NO   | PRI |         |       |
| Nume    | varchar(20)   | NO   |     |         |       |
| Varsta  | int(11)       | NO   |     |         |       |
| Adresa  | varchar(255)  | YES  |     | NULL    |       |
| Salariu | decimal(18,2) | YES  |     | NULL    |       |
+---------+---------------+------+-----+---------+-------+

 

Sunt un tanar programator din Bucuresti ce lucreaza in PHP/Mysql (MySqli/PDO), Laravel, CodeIgniter, MySQL, PostgreSQL, Wordpress, HTML5/CSS3, Sass, Photoshop si multe altele.
Google+ Community Facebook Group
Acest articol a fost mutat de pe vechea platforma.
Pentru orice eroare aparuta la mutare va rog sa ma contactati!

Comentariu postate de minecraft download free pc la data de 14.05.2019
Howdy! I could have sworn I've visited your blog before but after looking at a few of the posts I realized it's new to me. Anyways, I'm definitely delighted I came across it and I'll be bookmarking it and checking back frequently!
Comentariu postate de minecraft free download la data de 15.05.2019
Hello there I am so grateful I found your webpage, I really found you by mistake, while I was researching on Askjeeve for something else, Regardless I am here now and would just like to say thanks a lot for a tremendous post and a all round enjoyable blog (I also love the theme/design), I don’t have time to read it all at the moment but I have book-marked it and also added your RSS feeds, so when I have time I will be back to read more, Please do keep up the great work.
Comentariu postate de how to download minecraft free la data de 16.05.2019
Do you mind if I quote a couple of your posts as long as I provide credit and sources back to your blog? My blog site is in the exact same area of interest as yours and my visitors would certainly benefit from some of the information you provide here. Please let me know if this okay with you. Thank you!
Comentariu postate de mojang minecraft download la data de 17.05.2019
This is a topic that's close to my heart... Cheers! Where are your contact details though?
Comentariu postate de minecraft free download pc la data de 17.05.2019
What i do not understood is in fact how you are no longer actually much more well-liked than you might be now. You are very intelligent. You realize thus considerably on the subject of this subject, made me in my opinion imagine it from numerous numerous angles. Its like men and women are not interested unless it is something to accomplish with Girl gaga! Your personal stuffs nice. At all times care for it up!