29
MySQL Database Өгөгдлийн сан

Day 1 database

  • Upload
    -

  • View
    1.547

  • Download
    5

Embed Size (px)

Citation preview

  • 1. MySQL Database

2. Database ? Database . 3. Database ? . database- . 1994-03-111992-02-05 1988-09-29 1988-08-09 4. 5. 6. 7. DBMS ? DBMS Database Management System . DBMS- Database A003 Allen A007Shane A004 Brian A008RickyRetrieve Data Update Data Insert DataDelete Data DBMS 8. Database . Database-. 9. MySQL- shell>mysql h -u -p Host . Username Password 10. MySQL Database show databases; database- . MySQL- (;) . use ; database- . 11. database CREATE DATABASE; database . DROP DATABASE ; database-.CREATE DATABASE UbErdemOyu; 12. /Table/ Keys Default value Indexes Null values 13. CREATE TABLE (); DROP TABLE ; . show tables; CREATE TABLE student ( Student_id int primary key, Student_name varchar(255) not null ); 14. tbl_name.frm tbl_name.MYD tbl_name.MYI Index 15. /Data type/ Char Varchar Text Int Smallint Float Bit Time Timestamp 16. Data Integrity Data Integrity 17. Entity Integrity Entity Integrity primary key unique key Entity Integrity- Row Integrity 18. Referential Integrity Referential Integrity . foreign key . 19. Referential Integrity 20. /PRIMARYKEY/CREATE TABLE Table_name( PRIMARY KEY);CREATE TABLE Table_name(,PRIMARY KEY(Column_name[,Column_name])); :CREATE TABLE Student( Student_id int PRIMARY KEY ) 21. primarykey ALTER TABLE ADDCONSTRAINT PRIMARY KEY([,]); . :ALTER TABLE Student ADD CONSTRAINT PRIMARY KEY (student_id) 22. AUTO_INCREMENT AUTO_INCREMENT :CREATE TABLE Student ( Student_id INT NOT NULL AUTO_INCREMENT, Studentname CHAR(30) NOT NULL, PRIMARY KEY (id)); 23. /FOREIGNKEY/ Primary Key Foreign Key 24. /FOREIGNKEY/CREATE TABLE Table_name( REFERANCES (referance_column_name)); :CREATE TABLE Student ( Student_id INT UNSIGNED NOT NULL AUTO_INCREMENT, Student_name CHAR(60) NOT NULL, Lesson_id INT NOT NULL REFERANCES Lesson(Lesson_id)); 25. INSERT [INTO] VALUES([,[,]]); . :INSERT INTO studentVALUES(1,),(2,) 26. UPDATE SET[WHERE ] :UPDATE Student SET student_name = WHERE student_id = 1 27. . :UPDATE student SET student_id = 1, student_name = WHERE student_id = 3 28. DELETE FROM [WHERE ]; . :DELETE FROM student WHERE student_id = student_id = 1 29. TRUNCATE TABLE TRUNCATE TABLE ; . :TRUNCATE TABLE student