Momwe mungagwiritsire ntchito SQL Pangani Statement Yopanga Database ndi Matebulo

M'nkhaniyi tiwona momwe tingagwiritsire ntchito SQL kupanga mawu kuti tipeze nkhokwe ndi matebulo mu SQL. Tisanathe kupanga tebulo ndikuwonjezera deta, choyamba tiyenera kupanga nkhokwe.



SQL PANGANI ZOSAVUTA NTCHITO

Kuti tipeze database mu SQL, tiyenera kugwiritsa ntchito CREATE DATABASE lamulirani.

CREATE DATABASE dbname;

Mwachitsanzo:


Mawu otsatirawa a SQL amapanga nkhokwe yotchedwa 'ProductionDB'

CREATE DATABASE ProductionDB;

MUONETSETSE MISONKHANO

Kuti muwone nkhokwe yomwe mwangopanga ndikuwonanso mndandanda wazomwe zili m'dongosolo, timagwiritsa ntchito SHOW DATABASES lamulo:


SHOW DATABASES;

SQL LENGANI MITU YA NTCHITO

Ma tebulo ndizomanga zadongosolo lachibale. Tebulo lachidziwitso ndi pomwe zonse zosungidwa mu database zimasungidwa.

Kuti tithe tebulo mu SQL, tiyenera kugwiritsa ntchito CREATE TABLE lamulirani.

CREATE TABLE table_name (
column_name1 datatype,
column_name2 datatype,
column_name3 datatype, .... );

column_names amatchulira dzina lazipilala za patebulo.

Datatype imafotokoza mtundu wazomwe zikhozo zitha kusungidwa (mwachitsanzo manambala, mawu, tsiku, ndi zina zambiri).


Zindikirani:Tikamapanga tebulo mu SQL, tiyenera kufotokoza za tebulo mayina ndi mtundu wa deta adzagwira.

Mitundu yomwe imagwiritsidwa ntchito kwambiri ndi iyi:

  • CHAR
  • VARCHAR
  • TEXT
  • DATE
  • TIME
  • TIMESTAMP

SQL PANGANI CHITSANZO Chitsanzo

CREATE TABLE employees (
EmployeeID int,
FirstName varchar(255),
LastName varchar(255),
Department varchar(255),
JoiningDate DATE );

Ndondomeko ili pamwambapa imapanga tebulo lopanda kanthu lotchedwa 'antchito' lokhala ndi mizati isanu.

M'mizere yomwe yatchulidwa, EmployeeID imangokhala ndi mfundo zazikuluzikulu - FirstName, LastName ndi Damu mizati imatha kukhala ndi zilembo 255.

Chipinda cha JoiningDate chimakhala ndi mtundu wa Tsiku.