Back to Browse

Create Table Statement in SQL

238 views
Nov 24, 2024
2:46

In today’s video, I’m going to show you how to create a table in SQL using the create table statement. Before we get started, I want to cover what the create table statement is. The create table statement is used to define a new table in a database. This statement is fundamental in database creation and management as it sets the schema for storing structured data. *To get started:* 1. Open up SQL Server Management studio, and from the object explorer, expand the “Databases” folder, and right click on the database you’re working on, and select the “New query” option from the context menu. 2. For today’s example, I’m going to be creating a new table called “Employees”, which will be used to track employees at a company. 3. So from the query screen, you’re going to want to type in “CREATE TABLE” and now, type in the name in which you’d like to call your new table, I’m going to enter “employees”, and then an open bracket “(“ 4. Now hit the enter key on your keyboard to start a new line, and then hit the “Tab” key on your keyboard. 5. Now for this section of the query, we need to define our column names, and their data types. 6. For the first field, I’m going to create a column called “employeeId”, and then I’m going to set the data type to an integer, so I’m going to type in “int”. 7. Now hit the enter key on your keyboard to start a new line. 8. Now for the next column, I’m going to create one for the employees first name, so I’ll enter “FirstName”, and then type in “varchar(250)”. 9. Now hit the enter key on your keyboard. 10. Now in the next column, I’m going to create one for tracking the employees last name, so I’m going to type in “LastName”, with a data type of “varchar(250)”. 11. Now hit the enter key on your keyboard. 12. Now for the next column, I’d like to track the employees email address, so I’m going to type in “EmailAddress”, with a datatype of “varchar(250)”. 13. Now hit the enter key on your keyboard, and finish off the statement with a closed bracket “)“, and then a semicolon “;”. 14. Ensure everything you have entered looks good, and when you’re ready, click on the “Execute” button located at the top of the query window. 15. You should now see a command completed successfully message below. 16. Now, if we expand the “Tables” folder from the object explorer, you should now see our new table. And it’s as easy as that, utilizing the create table statement in SQL is an easy task to perform. #createtable #sql #statement

Download

0 formats

No download links available.

Create Table Statement in SQL | NatokHD