{"id":3406,"date":"2016-07-25T15:04:48","date_gmt":"2016-07-25T15:04:48","guid":{"rendered":"https:\/\/kiencang.net\/?p=3406"},"modified":"2016-07-25T15:04:48","modified_gmt":"2016-07-25T15:04:48","slug":"cau-lenh-tao-bang-trong-sql","status":"publish","type":"post","link":"https:\/\/kiencang.net\/cau-lenh-tao-bang-trong-sql\/","title":{"rendered":"C\u00e2u l\u1ec7nh t\u1ea1o b\u1ea3ng (create table) trong SQL"},"content":{"rendered":"\n

C\u00e2u l\u1ec7nh CREATE TABLE<\/code> \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 t\u1ea1o m\u1ed9t b\u1ea3ng trong m\u1ed9t c\u01a1 s\u1edf d\u1eef li\u1ec7u.<\/p>\n\n\n\n

C\u00e1c b\u1ea3ng \u0111\u01b0\u1ee3c s\u1eafp x\u1ebfp theo h\u00e0ng v\u00e0 c\u1ed9t; v\u00e0 m\u1ed7i b\u1ea3ng ph\u1ea3i c\u00f3 m\u1ed9t c\u00e1i t\u00ean.<\/p>\n\n\n\n

C\u00fa ph\u00e1p c\u1ee7a SQL<\/a> CREATE TABLE<\/code><\/h3>\n\n\n\n
CREATE TABLE ten_bang\n(\nten_cot_1 kieu_du_lieu(kich_co),\nten_cot_2 kieu_du_lieu(kich_co),\nten_cot_3 kieu_du_lieu(kich_co),\n....\n);<\/code><\/pre>\n\n\n\n

ten_cot <\/em>trong d\u1ea5u ngo\u1eb7c \u0111\u01a1n ch\u1ec9 t\u00ean c\u1ee7a c\u00e1c c\u1ed9t trong b\u1ea3ng.<\/p>\n\n\n\n

C\u00e1c ki\u1ec3u d\u1eef li\u1ec7u trong d\u1ea5u ngo\u1eb7c ch\u1ec9 \u0111\u1ecbnh ki\u1ec3u d\u1eef li\u1ec7u c\u1ee7a c\u1ed9t c\u00f3 th\u1ec3 n\u1eafm gi\u1eef (v\u00ed d\u1ee5 varchar, integer, decimal, date,<\/code> etc.)<\/p>\n\n\n\n

K\u00edch c\u1ee1 trong d\u1ea5u ngo\u1eb7c ch\u1ec9 \u0111\u1ed9 d\u00e0i l\u1edbn nh\u1ea5t c\u1ee7a c\u1ed9t c\u00f3 th\u1ec3 c\u00f3 trong b\u1ea3ng.<\/p>\n\n\n\n

M\u1eb9o<\/strong>: Cho c\u00e1i nh\u00ecn t\u1ed5ng quan v\u1ec1 ki\u1ec3u d\u1eef li\u1ec7u c\u00f3 th\u1ec3 c\u00f3 trong MS Access, MySQL v\u00e0 SQL Server, h\u00e3y truy c\u1eadp th\u01b0 m\u1ee5c \u0111\u1ea7y \u0111\u1ee7 c\u00e1c ki\u1ec3u d\u1eef li\u1ec7u c\u1ee7a ch\u00fang t\u00f4i.<\/p>\n\n\n\n

V\u00ed d\u1ee5 v\u1ec1 SQL CREATE TABLE<\/h2>\n\n\n\n

B\u00e2y gi\u1edd ch\u00fang ta mu\u1ed1n t\u1ea1o m\u1ed9t b\u1ea3ng c\u00f3 t\u00ean l\u00e0 “Persons” bao g\u1ed3m n\u0103m c\u1ed9t: PersonID, LastName, FirstName, Address, v\u00e0 City<\/code>.<\/p>\n\n\n\n

Ch\u00fang ta s\u1eed d\u1ee5ng c\u00e2u l\u1ec7nh CREATE TABLE<\/code> nh\u01b0 sau:<\/p>\n\n\n\n

V\u00ed d\u1ee5<\/h3>\n\n\n\n
CREATE TABLE Persons\n(\nPersonID int,\nLastName varchar(255),\nFirstName varchar(255),\nAddress varchar(255),\nCity varchar(255)\n);<\/code><\/pre>\n\n\n\n

C\u1ed9t PersonID<\/code> c\u00f3 ki\u1ec3u d\u1eef li\u1ec7u l\u00e0 int<\/code> v\u00e0 s\u1ebd l\u01b0u tr\u1eef c\u00e1c s\u1ed1 nguy\u00ean.<\/p>\n\n\n\n

C\u1ed9t LastName, FirstName, Address v\u00e0 City<\/code> c\u00f3 ki\u1ec3u d\u1eef li\u1ec7u l\u00e0 varchar<\/code> v\u00e0 l\u01b0u tr\u1eef c\u00e1c k\u00fd t\u1ef1, chi\u1ec1u d\u00e0i l\u1edbn nh\u1ea5t c\u1ee7a c\u00e1c tr\u01b0\u1eddng \u0111\u00f3 l\u00e0 255 k\u00fd t\u1ef1.<\/p>\n\n\n\n

M\u1ed9t b\u1ea3ng “Persons” r\u1ed7ng s\u1ebd tr\u00f4ng gi\u1ed1ng nh\u01b0 th\u1ebf n\u00e0y:<\/p>\n\n\n\n

PersonID<\/th>LastName<\/th>FirstName<\/th>Address<\/th>City<\/th><\/tr>
 <\/td> <\/td> <\/td> <\/td> <\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n

Tip: <\/strong>B\u1ea3ng r\u1ed7ng c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c l\u1ea5p \u0111\u1ea7y v\u1edbi d\u1eef li\u1ec7u b\u1eb1ng c\u00e2u l\u1ec7nh INSERT INTO<\/a><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"

C\u00e2u l\u1ec7nh CREATE TABLE \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 t\u1ea1o m\u1ed9t b\u1ea3ng trong m\u1ed9t c\u01a1 s\u1edf d\u1eef li\u1ec7u. C\u00e1c b\u1ea3ng \u0111\u01b0\u1ee3c s\u1eafp x\u1ebfp theo h\u00e0ng v\u00e0 c\u1ed9t; v\u00e0 m\u1ed7i b\u1ea3ng ph\u1ea3i c\u00f3 m\u1ed9t c\u00e1i t\u00ean. C\u00fa ph\u00e1p c\u1ee7a SQL CREATE TABLE ten_cot trong d\u1ea5u ngo\u1eb7c \u0111\u01a1n ch\u1ec9 t\u00ean c\u1ee7a c\u00e1c c\u1ed9t trong b\u1ea3ng. C\u00e1c ki\u1ec3u d\u1eef …<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[239],"tags":[],"yoast_head":"\nC\u00e2u l\u1ec7nh t\u1ea1o b\u1ea3ng (create table) trong SQL • Ki\u1ebfn c\u00e0ng<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/kiencang.net\/cau-lenh-tao-bang-trong-sql\/\" \/>\n<meta property=\"og:locale\" content=\"vi_VN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C\u00e2u l\u1ec7nh t\u1ea1o b\u1ea3ng (create table) trong SQL • Ki\u1ebfn c\u00e0ng\" \/>\n<meta property=\"og:description\" content=\"C\u00e2u l\u1ec7nh CREATE TABLE \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 t\u1ea1o m\u1ed9t b\u1ea3ng trong m\u1ed9t c\u01a1 s\u1edf d\u1eef li\u1ec7u. C\u00e1c b\u1ea3ng \u0111\u01b0\u1ee3c s\u1eafp x\u1ebfp theo h\u00e0ng v\u00e0 c\u1ed9t; v\u00e0 m\u1ed7i b\u1ea3ng ph\u1ea3i c\u00f3 m\u1ed9t c\u00e1i t\u00ean. C\u00fa ph\u00e1p c\u1ee7a SQL CREATE TABLE ten_cot trong d\u1ea5u ngo\u1eb7c \u0111\u01a1n ch\u1ec9 t\u00ean c\u1ee7a c\u00e1c c\u1ed9t trong b\u1ea3ng. C\u00e1c ki\u1ec3u d\u1eef …\" \/>\n<meta property=\"og:url\" content=\"https:\/\/kiencang.net\/cau-lenh-tao-bang-trong-sql\/\" \/>\n<meta property=\"og:site_name\" content=\"Ki\u1ebfn c\u00e0ng\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/anhducnguyen87\/\" \/>\n<meta property=\"article:published_time\" content=\"2016-07-25T15:04:48+00:00\" \/>\n<meta name=\"author\" content=\"Nguy\u1ec5n \u0110\u1ee9c Anh\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nguy\u1ec5n \u0110\u1ee9c Anh\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 ph\u00fat\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C\u00e2u l\u1ec7nh t\u1ea1o b\u1ea3ng (create table) trong SQL • Ki\u1ebfn c\u00e0ng","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/kiencang.net\/cau-lenh-tao-bang-trong-sql\/","og_locale":"vi_VN","og_type":"article","og_title":"C\u00e2u l\u1ec7nh t\u1ea1o b\u1ea3ng (create table) trong SQL • Ki\u1ebfn c\u00e0ng","og_description":"C\u00e2u l\u1ec7nh CREATE TABLE \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 t\u1ea1o m\u1ed9t b\u1ea3ng trong m\u1ed9t c\u01a1 s\u1edf d\u1eef li\u1ec7u. C\u00e1c b\u1ea3ng \u0111\u01b0\u1ee3c s\u1eafp x\u1ebfp theo h\u00e0ng v\u00e0 c\u1ed9t; v\u00e0 m\u1ed7i b\u1ea3ng ph\u1ea3i c\u00f3 m\u1ed9t c\u00e1i t\u00ean. C\u00fa ph\u00e1p c\u1ee7a SQL CREATE TABLE ten_cot trong d\u1ea5u ngo\u1eb7c \u0111\u01a1n ch\u1ec9 t\u00ean c\u1ee7a c\u00e1c c\u1ed9t trong b\u1ea3ng. C\u00e1c ki\u1ec3u d\u1eef …","og_url":"https:\/\/kiencang.net\/cau-lenh-tao-bang-trong-sql\/","og_site_name":"Ki\u1ebfn c\u00e0ng","article_author":"https:\/\/www.facebook.com\/anhducnguyen87\/","article_published_time":"2016-07-25T15:04:48+00:00","author":"Nguy\u1ec5n \u0110\u1ee9c Anh","twitter_card":"summary_large_image","twitter_misc":{"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi":"Nguy\u1ec5n \u0110\u1ee9c Anh","\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc":"2 ph\u00fat"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/kiencang.net\/cau-lenh-tao-bang-trong-sql\/","url":"https:\/\/kiencang.net\/cau-lenh-tao-bang-trong-sql\/","name":"C\u00e2u l\u1ec7nh t\u1ea1o b\u1ea3ng (create table) trong SQL • Ki\u1ebfn c\u00e0ng","isPartOf":{"@id":"https:\/\/kiencang.net\/#website"},"datePublished":"2016-07-25T15:04:48+00:00","dateModified":"2016-07-25T15:04:48+00:00","author":{"@id":"https:\/\/kiencang.net\/#\/schema\/person\/5e7e1a04d8d1218ad8c421ba43d25c16"},"breadcrumb":{"@id":"https:\/\/kiencang.net\/cau-lenh-tao-bang-trong-sql\/#breadcrumb"},"inLanguage":"vi","potentialAction":[{"@type":"ReadAction","target":["https:\/\/kiencang.net\/cau-lenh-tao-bang-trong-sql\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/kiencang.net\/cau-lenh-tao-bang-trong-sql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/kiencang.net\/"},{"@type":"ListItem","position":2,"name":"C\u00e2u l\u1ec7nh t\u1ea1o b\u1ea3ng (create table) trong SQL"}]},{"@type":"WebSite","@id":"https:\/\/kiencang.net\/#website","url":"https:\/\/kiencang.net\/","name":"Ki\u1ebfn c\u00e0ng","description":"\u00d4m l\u00fd thuy\u1ebft, h\u00f4n th\u1ef1c h\u00e0nh","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/kiencang.net\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"vi"},{"@type":"Person","@id":"https:\/\/kiencang.net\/#\/schema\/person\/5e7e1a04d8d1218ad8c421ba43d25c16","name":"Nguy\u1ec5n \u0110\u1ee9c Anh","image":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/kiencang.net\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6d71f9b89393952a8382e30dad26c1ec?s=96&d=monsterid&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6d71f9b89393952a8382e30dad26c1ec?s=96&d=monsterid&r=g","caption":"Nguy\u1ec5n \u0110\u1ee9c Anh"},"description":"Sinh n\u0103m 1987, t\u1ed1t nghi\u1ec7p Cao \u0111\u1eb3ng th\u1ef1c h\u00e0nh FPT qu\u00e3ng 2014, chuy\u00ean ng\u00e0nh Thi\u1ebft k\u1ebf website. T\u00f4i th\u00edch Content, SEO, Ads, T\u0103ng t\u1ed1c website v\u00e0 Th\u01b0\u01a1ng m\u1ea1i \u0111i\u1ec7n t\u1eed. B\u00ean c\u1ea1nh b\u00e0i t\u1ef1 vi\u1ebft, t\u00f4i c\u0169ng d\u1ecbch nhi\u1ec1u n\u1ed9i dung th\u00fa v\u1ecb c\u1ee7a c\u00e1c t\u00e1c gi\u1ea3 kh\u00e1c nhau. FB c\u00e1 nh\u00e2n: facebook.com\/anhducnguyen87. Email li\u00ean h\u1ec7: guiemailchotoi@gmail.com","sameAs":["https:\/\/www.facebook.com\/anhducnguyen87\/"],"url":"https:\/\/kiencang.net\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/kiencang.net\/wp-json\/wp\/v2\/posts\/3406"}],"collection":[{"href":"https:\/\/kiencang.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kiencang.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kiencang.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kiencang.net\/wp-json\/wp\/v2\/comments?post=3406"}],"version-history":[{"count":0,"href":"https:\/\/kiencang.net\/wp-json\/wp\/v2\/posts\/3406\/revisions"}],"wp:attachment":[{"href":"https:\/\/kiencang.net\/wp-json\/wp\/v2\/media?parent=3406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kiencang.net\/wp-json\/wp\/v2\/categories?post=3406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kiencang.net\/wp-json\/wp\/v2\/tags?post=3406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}